Skip to content

Panels and lock screens ​

Bars, launchers, notifications and lock screens are separate programs that talk to Hazel over Wayland. Hazel places bars and launchers where they ask to be. The config starts them and decides who gets the keyboard.

All of these build on your first config.

A bar and notifications ​

waybar and mako, started once per session.

lua
if not wm.is_reload then
	spawn("waybar")
	spawn("mako")
end
  • wm.is_reload is false only for the first load, so saving the config doesn't start a second bar.
  • A bar reserves space at its edge. Windows placed in output:usable_area() stay clear of it, as Tiling does.

waybar's hyprland/workspaces and niri/workspaces modules don't work with Hazel. A custom module can ask Hazel instead. With Workspaces, this shows the current one:

json
"custom/workspace": {
	"exec": "hazel eval 'wm.store.workspaces and wm.store.workspaces.current or 1'",
	"interval": 1,
	"format": "{}",
	"on-scroll-up": "hazel eval 'wm:emit(\"show_workspace\", wm.store.workspaces.current % 9 + 1)'"
}

hazel eval runs Lua inside the running Hazel and prints what it returns. See Debugging.

Launchers ​

mod + D opens fuzzel. Launchers, and other panels that ask for the keyboard, get focus while they are open. Clicking a panel that takes the keyboard when picked, such as a search field, focuses it.

lua
bind(mod, "d", function() spawn("fuzzel") end)

wm.layers:on("new_layer", function(layer)
	layer:on("first_content", function(layer)
		if layer.keyboard_interactivity == "exclusive" and seat() then seat():focus(layer) end
	end)
	layer:on("closed", function()
		if not focused_window() then focus_topmost() end
	end)
end)

wm.input:on("pointer_button_forwarded", function(event)
	if event.state ~= "Pressed" then return end
	local target = wm.input:target_under(event.pointer:position())
	if target and target.kind == "layer" and target.keyboard_interactivity == "on_demand" and seat() then
		seat():focus(target)
	end
end)

rofi 2.0 and later, wofi and tofi work the same way.

A lock screen ​

mod + Escape locks with swaylock. hyprlock works too.

lua
wm.session_lock:set_backdrop_color("#1d2021")

bind(mod, "Escape", function() spawn("swaylock") end)

wm:on("session_unlocked", function() focus_topmost() end)
  • While the session is locked, only the lock screen is drawn, and it gets every key. The bindings from your first config don't run.
  • The backdrop shows before the lock screen has drawn, and if the locker crashes. The session stays locked then. To get back in, switch to another tty, log in, and start the locker again with WAYLAND_DISPLAY set to Hazel's socket, such as WAYLAND_DISPLAY=wayland-1 swaylock.
  • After unlocking nothing has focus, so session_unlocked gives it back.

Locking when idle ​

swayidle locks after 5 minutes without input, and before the machine sleeps.

lua
if not wm.is_reload then
	spawn("swayidle", { "-w", "timeout", "300", "swaylock -f", "before-sleep", "swaylock -f" })
end

hypridle works too, with its own config file.

All of them ​

lua
if not wm.is_reload then
	spawn("waybar")
	spawn("mako")
end

bind(mod, "d", function() spawn("fuzzel") end)

wm.layers:on("new_layer", function(layer)
	layer:on("first_content", function(layer)
		if layer.keyboard_interactivity == "exclusive" and seat() then seat():focus(layer) end
	end)
	layer:on("closed", function()
		if not focused_window() then focus_topmost() end
	end)
end)

wm.input:on("pointer_button_forwarded", function(event)
	if event.state ~= "Pressed" then return end
	local target = wm.input:target_under(event.pointer:position())
	if target and target.kind == "layer" and target.keyboard_interactivity == "on_demand" and seat() then
		seat():focus(target)
	end
end)

wm.session_lock:set_backdrop_color("#1d2021")

bind(mod, "Escape", function() spawn("swaylock") end)

wm:on("session_unlocked", function() focus_topmost() end)

if not wm.is_reload then
	spawn("swayidle", { "-w", "timeout", "300", "swaylock -f", "before-sleep", "swaylock -f" })
end