Skip to content

Animation ​

Any position, size, opacity or colour can be given an animated value instead of a plain one. Hazel has two kinds:

  • Anim.spring(to, { stiffness, damping_ratio }) moves like a weight on a spring. It keeps its speed when you change the target halfway, so a window that is re-tiled mid-animation curves smoothly to its new place. Use it for movement.
  • Anim.tween(to, ms, easing) takes exactly ms milliseconds along an easing curve. Use it for fades and colours.

Higher stiffness is faster. damping_ratio 1 arrives without overshoot, lower bounces. A rough match for Hyprland's defaults is { stiffness = 300, damping_ratio = 0.85 }, the one Tiling uses. See Animated values for the rest.

All of these build on your first config.

Windows fade in ​

New windows fade in.

lua
wm.windows:on("new_window", function(window)
	window.box.opacity = 0
	window:on("first_content", function(window)
		window.box.opacity = Anim.tween(1, 180)
	end)
end)

A window starts at opacity 0 and stays invisible until it has drawn, then fades in from 0.

Windows fade out ​

A closed window shrinks a little and fades. Hazel keeps its last frame on screen until the animation is done.

lua
wm.windows:on("new_window", function(window)
	window:on("closed", function(window)
		local drawn = window.box.size and window.box.size:now() or window.size
		window.box.opacity = Anim.tween(0, 160)
		if drawn then
			local smaller = { width = drawn.width * 0.92, height = drawn.height * 0.92 }
			local shift = Point((drawn.width - smaller.width) / 2, (drawn.height - smaller.height) / 2)
			window.box.size = Anim.tween(smaller, 160)
			window.box.position = Anim.tween(window.box.position:now() + shift, 160)
		end
	end)
end)

Without an animation in closed, a window disappears at once.

A shake on the bell ​

When an app rings the bell, its window shakes sideways. Timer.after springs it back with a low damping ratio, so it wobbles before it settles.

lua
wm.windows:on("new_window", function(window)
	window:on("bell", function(window)
		local home = window.box.position:target()
		window.box.position = Anim.spring(home + Point(14, 0), { stiffness = 2000 })
		Timer.after(60, function()
			window.box.position = Anim.spring(home, { stiffness = 700, damping_ratio = 0.25 })
		end)
	end)
end)

Try it with printf '\a' in foot, which rings this bell by default.

Focus fades ​

The focused window is fully opaque and the others fade to 90 %. It sets the same property as opacity in window rules and the scrolling layout, so use one of them.

lua
local unfocused_opacity = 0.9

wm.windows:on("new_window", function(window)
	window:on("focus", function(_, _, window)
		local focused = #window.focused_seats > 0
		window.box.opacity = Anim.tween(focused and 1 or unfocused_opacity, 200)
	end)
end)

All of them ​

lua
wm.windows:on("new_window", function(window)
	window.box.opacity = 0
	window:on("first_content", function(window)
		window.box.opacity = Anim.tween(1, 180)
	end)
end)

wm.windows:on("new_window", function(window)
	window:on("closed", function(window)
		local drawn = window.box.size and window.box.size:now() or window.size
		window.box.opacity = Anim.tween(0, 160)
		if drawn then
			local smaller = { width = drawn.width * 0.92, height = drawn.height * 0.92 }
			local shift = Point((drawn.width - smaller.width) / 2, (drawn.height - smaller.height) / 2)
			window.box.size = Anim.tween(smaller, 160)
			window.box.position = Anim.tween(window.box.position:now() + shift, 160)
		end
	end)
end)

wm.windows:on("new_window", function(window)
	window:on("bell", function(window)
		local home = window.box.position:target()
		window.box.position = Anim.spring(home + Point(14, 0), { stiffness = 2000 })
		Timer.after(60, function()
			window.box.position = Anim.spring(home, { stiffness = 700, damping_ratio = 0.25 })
		end)
	end)
end)

local unfocused_opacity = 0.9

wm.windows:on("new_window", function(window)
	window:on("focus", function(_, _, window)
		local focused = #window.focused_seats > 0
		window.box.opacity = Anim.tween(focused and 1 or unfocused_opacity, 200)
	end)
end)