Skip to content

Class Pointer ​

A seat's pointer. Get one from seat:pointer() or the new_pointer event.

new_pointer doesn't fire again after a reload, so set up the pointers that are already there as well:

lua
local function set_up_pointer(pointer)
	pointer.cursor.size = 32
end

for _, seat in ipairs(wm.input.seats:all()) do
	local seat_pointer = seat:pointer()
	if seat_pointer then set_up_pointer(seat_pointer) end
end
wm.input:on("new_pointer", set_up_pointer)

Moving a window with Super and the left button, with the pointer grabbed for the drag:

lua
local drag

wm.input:on("pointer_button", function(event)
	if event.button ~= Button.Left then return end
	if event.state == "Pressed" then
		local target = event.pointer:window_under()
		if not (event.modifiers.super and target) then return end
		event:prevent_default()
		drag = { window = target, pointer = event.pointer, start = event.pointer:position(), from = target.box.position:target() }
		event.pointer:grab()
		event.pointer.cursor.shape = "move"
	elseif drag then
		event:prevent_default()
		drag.pointer:ungrab()
		drag.pointer.cursor.shape = nil
		drag = nil
	end
end)

wm.input:on("pointer_move", function(event)
	if not drag then return end
	drag.window.box.position = drag.from + (event.position - drag.start)
end)

Properties ​

pointer.cursor: Cursorcursor read only ​

What this pointer shows on screen. Each pointer has its own.

Methods ​

pointer:seat() -> Seat?seat ​

The seat this pointer belongs to.

  • nil once the seat no longer has it.

pointer:position() -> Pointposition ​

Where the pointer is, in global coordinates. Fractions are kept.

lua
local target = wm.input:target_under(pointer:position())

pointer:buttons() -> integer[]buttons ​

The buttons held down, as Linux input codes (272 is the left button), in the order they were pressed.

  • A press is added before the pointer_button handlers run, and counts even when a handler prevents it. A release removes it the same way.
  • Presses from pointer:button count too.
lua
local held = #pointer:buttons() > 0

pointer:window_under() -> Window?window_under ​

The frontmost window drawn under the pointer.

pointer:move(point: Point) -> nilmove ​

Moves the pointer to point as if the device had.

  • Fires pointer_move first, which can prevent it. delta is the distance from the old position.
  • An active pointer lock under the pointer keeps it in place. A confinement clamps it.
  • Calling it from a pointer_move handler fires pointer_move again. Guard against a loop.
lua
pointer:move(output:area():center())

pointer:button(button: MouseButton | integer, state: "pressed" | "released") -> nilbutton ​

Presses or releases a button as if the device had. button is a Button.* value or a Linux input code.

Errors for any other state.

lua
pointer:move(window.box.position:target() + Point(40, 40))
pointer:button(Button.Left, "pressed")
pointer:button(Button.Left, "released")

pointer:scroll(horizontal: number, vertical: number, source: "wheel" | "finger" | "continuous" | nil) -> nilscroll ​

Scrolls as if the device had. Positive vertical scrolls down, positive horizontal scrolls right. pointer_scroll fires first and can prevent it.

  • "wheel" (the default): amounts are wheel notches. A notch is 15 pixels. Fractions work.
  • "finger": amounts are pixels, as from a touchpad. A 0 on an axis tells the app scrolling stopped there, which ends kinetic scrolling.
  • "continuous": amounts are pixels, as from a trackball.

Errors for any other source.

lua
pointer:scroll(0, 3)
pointer:scroll(0, -40, "finger")

pointer:gesture(kind: "swipe" | "pinch" | "hold", phase: "begin" | "update" | "end", options: table?) -> nilgesture ​

Sends one step of a touchpad gesture as if the device had. pointer_gesture fires for it. The app gets it unless a handler prevented the gesture's "begin".

options may hold:

  • fingers: default 0. Only "begin" reads it. Later steps keep the begin's count.
  • delta: a Point, how far the fingers moved since the last step. Default 0,0.
  • scale: for a pinch, the finger spread relative to the start. Default 1.
  • rotation: for a pinch, degrees turned since the last step. Default 0.
  • cancelled: for "end", whether the gesture was called off. Default false.

Errors

Steps must come in order. It errors for a "begin" while a gesture is in progress, an "update" or "end" with none in progress, a kind other than the one in progress, an "update" for a hold, and an unknown kind or phase.

lua
pointer:gesture("swipe", "begin", { fingers = 3 })
pointer:gesture("swipe", "update", { delta = Point(40, 0) })
pointer:gesture("swipe", "end")

pointer:grab() -> nilgrab ​

Takes the pointer away from apps, for compositor drags and overlays. The pointer leaves the app under it. No app gets motion, buttons, scrolling or gestures.

pointer:ungrab() -> nilungrab ​

Ends a pointer:grab. Whatever is under the pointer gets it back straight away, without waiting for a move.

  • Does nothing when the pointer isn't grabbed.

pointer:grabbed() -> booleangrabbed ​

Whether a pointer:grab is in place. An app's own grab, such as an open popup menu or a drag and drop, doesn't count.