Skip to content

Class Cursor ​

What a pointer shows on screen, from pointer.cursor. Each pointer has its own.

  • By default the cursor is whatever the app under the pointer asked for. Setting shape overrides that.
  • A reload sets every field back to its default and empties drawables. If the new config fails to load, the old settings come back.

A larger cursor with a ring around the hotspot, on every pointer:

lua
local function style_cursor(cursor)
	cursor.size = 32
	cursor.drawables = {
		Drawable.rect({ left = -14, top = -14, width = 28, height = 28, radius = 14, border_width = 2, border_color = "#ffffff99" }),
	}
end

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

Properties ​

cursor.shape: CursorShapeName?shape ​

The shape Hazel shows instead of the app's, also over an app that draws its own cursor image.

  • nil (the default): what the app under the pointer asked for.
  • "none" hides the cursor.
  • The other names, mostly the CSS cursor names: "default", "context-menu", "help", "pointer", "progress", "wait", "cell", "crosshair", "text", "vertical-text", "alias", "copy", "move", "no-drop", "not-allowed", "grab", "grabbing", "e-resize", "n-resize", "ne-resize", "nw-resize", "s-resize", "se-resize", "sw-resize", "w-resize", "ew-resize", "ns-resize", "nesw-resize", "nwse-resize", "col-resize", "row-resize", "all-scroll", "zoom-in", "zoom-out", "dnd-ask", "all-resize".

Errors for any other name.

A resize shape for the edge under the pointer, and nil over a window's content to give the app its own cursor back:

lua
local EDGE_CURSORS = {
	top = "n-resize", bottom = "s-resize", left = "w-resize", right = "e-resize",
	top_left = "nw-resize", top_right = "ne-resize", bottom_left = "sw-resize", bottom_right = "se-resize",
}

local function show_edge(edge_name)
	pointer.cursor.shape = EDGE_CURSORS[edge_name]
end

show_edge("top_left")
show_edge(nil)

cursor.app_shape: CursorShapeName | "surface"app_shape read only ​

What the app under the pointer last asked for, whether or not shape overrides it.

  • A shape name, "surface" when the app draws its own cursor image, or "none" when it hid the cursor.

cursor.size: number | Animated | nilsize ​

The cursor's size in logical pixels. Reads back as an Animated.

  • nil (the default): XCURSOR_SIZE from Hazel's environment, or 24 when that is unset or not a positive number.

Errors for a size of 0 or less.

lua
pointer.cursor.size = Anim.spring(48)
pointer.cursor.size = nil

cursor.theme: string?theme ​

The XCursor theme to load shapes from.

  • nil (the default): XCURSOR_THEME, or "default" when that is unset.
  • A shape the theme lacks is looked up under its older X cursor names, then falls back to the theme's "default", then to a small built-in cursor.
  • Animated cursor images play.

Errors for an empty or blank name.

cursor.drawables: DrawableListdrawables ​

Drawables drawn with the cursor, in front of everything, the cursor image included.

  • left and top are offsets from the hotspot, the tip of the pointer.
  • They show on every output they reach.
  • Assigning a table replaces the list.

shape = "none" with drawables gives a cursor made only of drawables:

lua
pointer.cursor.shape = "none"
pointer.cursor.drawables = { Drawable.rect({ left = -4, top = -4, width = 8, height = 8, radius = 4, fill = "#ff8800" }) }
pointer.cursor.drawables = {}
pointer.cursor.shape = nil

Events ​

Listen with cursor:on(name, fn), which returns a function that stops listening.

Errors for an unknown event name.

"app_shape_changed" (cursor: Cursor)app_shape_changed ​

The app under the pointer asked for a different cursor. app_shape has the new one.

  • Fires when the pointer moves onto an app that wants another shape, and when the app changes its cursor while the pointer stands still.
  • A request for the shape it already has doesn't fire it.
lua
local stop = pointer.cursor:on("app_shape_changed", function(cursor)
	print("app wants " .. cursor.app_shape)
end)
stop()