Skip to content

Class Input ​

Keyboard and pointer input from every seat, reached as wm.input.

A key binding is a key handler that checks the key and modifiers and calls prevent_default():

lua
wm.input:on("key", function(event)
	if wm.is_session_locked or event.shortcuts_inhibited then return end
	if event.raw_key == Key.Return and event.modifiers.super and not event.modifiers.shift then
		event:prevent_default()
		if event.state == "Pressed" then Process.spawn("foot") end
	end
end)

Properties ​

wm.input.seats: SeatListseats read only ​

Every seat, sorted by name. Hazel puts every input device on one seat, seat0.

  • Empty while the config first runs. Devices arrive afterwards through new_keyboard and new_pointer.
  • After a reload the seat is already there.
lua
local first_seat = wm.input.seats:get(1)
local keyboard_of_first_seat = first_seat and first_seat:keyboard()

Methods ​

wm.input:target_under(point: Point) -> Window | Layer | niltarget_under ​

What would get pointer input at point, in global coordinates. Check kind to tell a window from a layer.

  • Order: overlay and top layers, then windows, then bottom and background layers.
  • Windows count where they are drawn. Windows with box.input false and hidden windows are skipped.
  • nil while the session is locked.
lua
local under_pointer = wm.input:target_under(pointer:position())
if under_pointer and under_pointer.kind == "window" then
	under_pointer.box:raise()
end

Events ​

Listen with wm.input:on(name, fn), which returns a function that stops listening. Handlers run in the order they were added. One that raises an error is logged and the rest still run.

Errors for a name that isn't one of the events below.

"key" (event: KeyEvent)key ​

A key was pressed or released on any keyboard, before the focused app gets it. event:prevent_default() keeps it from the app.

  • It also fires while the session is locked, when the key would go to the lock screen. Check wm.is_session_locked so bindings don't run behind it.
  • Keys sent with keyboard:key fire it before keyboard:key returns.
  • Keys that produce XF86Switch_VT_1 to XF86Switch_VT_12 (Ctrl+Alt+F1 to F12 on most layouts) switch virtual terminal whatever the handlers do.
lua
wm.input:on("key", function(event)
	if event.state == "Pressed" and event.raw_key == Key.F12 and event.modifiers.ctrl and event.modifiers.alt then
		event:prevent_default()
		wm:screenshot("/tmp/hazel-screenshot.png")
	end
end)

"pointer_move" (event: PointerMoveEvent)pointer_move ​

The pointer moved, from a device or from pointer:move, before any app sees it. event:prevent_default() keeps the pointer where it was.

"pointer_button" (event: PointerButtonEvent)pointer_button ​

A pointer button was pressed or released, before the app gets it. event:prevent_default() keeps it from the app.

  • Pointer bindings such as Super-drag go here.

"pointer_button_forwarded" (event: PointerButtonEvent)pointer_button_forwarded ​

A button after the app got it. Use it to react to clicks without taking them.

  • Doesn't fire for a button a pointer_button handler prevented.
lua
wm.input:on("pointer_button_forwarded", function(event)
	if event.state ~= "Pressed" then return end
	local clicked = event.pointer:window_under()
	local seat = event.pointer:seat()
	if clicked and seat then seat:focus(clicked) end
end)

"pointer_scroll" (event: PointerScrollEvent)pointer_scroll ​

Scrolling from a device or from pointer:scroll, before the app gets it. event:prevent_default() keeps it from the app.

"pointer_gesture" (event: PointerGestureEvent)pointer_gesture ​

A touchpad swipe, pinch or hold, once for each step.

  • event:prevent_default() on "begin" keeps the whole gesture from the app. On later steps it does nothing.

"new_keyboard" (keyboard: Keyboard)new_keyboard ​

A keyboard device was added.

  • The layout goes back to the default each time. Set it again here (see Keyboard). The repeat rate and delay are kept.
  • Fires for the keyboards found at startup, just after the config has run.
  • Doesn't fire again for them after a reload, so set those up directly too.

"new_pointer" (pointer: Pointer)new_pointer ​

A pointer device was added.

  • Fires for the pointers found at startup, just after the config has run.
  • Doesn't fire again for them after a reload.

Requests ​

Asks from an app. Listen for them with wm.input:on(name, fn) too.

"shortcuts_inhibit_request" (inhibitor: ShortcutsInhibitor)shortcuts_inhibit_request ​

An app such as a remote desktop viewer or a virtual machine wants the keys that would otherwise be the compositor's shortcuts.

  • Nothing is granted until a handler calls inhibitor:activate().
  • Granting it sets event.shortcuts_inhibited on key events. Key handlers still run and decide what to leave alone.

"pointer_constraint" (constraint: PointerConstraint)pointer_constraint ​

An app, usually a game, wants to lock the pointer in place or keep it inside an area.