Skip to content

Class Layer ​

A layer surface: a panel, wallpaper, launcher or notification, from wm.layers.

Hazel places the layer from what the app asks for: an output, a depth, anchors, margins, a size and an exclusive zone. position, size and output:usable_area() are the result.

  • An app that names no output gets the first one. With no outputs at all the layer is closed straight away.
  • Two Layer values for the same layer are equal with ==.
lua
wm.layers:on("new_layer", function(layer)
	layer:on("first_content", function(layer)
		if layer.keyboard_interactivity == "exclusive" then
			wm.input.seats:get(1):focus(layer)
		end
	end)
end)

Properties ​

layer.kind: "layer"kind read only ​

Always "layer". A window reads "window", which tells the two apart where either can come back, such as seat:focused().

layer.namespace: stringnamespace read only ​

The name the app gave, such as "waybar" or "wallpaper". Apps pick it themselves, so it isn't unique.

layer.depth: "background" | "bottom" | "top" | "overlay"depth read only ​

Which of the four depths it is drawn at. From the front: overlay layers, fullscreen windows, top layers, other windows, bottom layers, background layers.

layer.position: Pointposition read only ​

The top-left corner, relative to the top-left of its output.

  • 0,0 once it has closed.

layer.size: Sizesize read only ​

The size the app last drew the layer at.

  • 0x0 once it has closed.

layer.output: Output?output read only ​

The output the layer was made on. It still answers after the layer has closed.

  • nil once that output is gone.

layer.keyboard_interactivity: "none" | "exclusive" | "on_demand"keyboard_interactivity read only ​

Whether the app wants keyboard input.

  • "none": never.
  • "exclusive": all of it while shown, like a launcher.
  • "on_demand": when the user picks the layer, by clicking it for example.

Hazel doesn't act on it. Give the layer focus with seat:focus(layer) when it fits.

layer.anchor: { top: boolean, bottom: boolean, left: boolean, right: boolean }anchor read only ​

The output edges the layer is attached to, in a new table each read.

  • Anchored to two opposite edges with a requested size of 0 on that axis, it stretches between them.
lua
local function is_top_bar(layer)
	local anchor = layer.anchor
	return anchor.top and anchor.left and anchor.right and not anchor.bottom
end

layer.margin: { top: integer, right: integer, bottom: integer, left: integer }margin read only ​

The distance the app wants from each anchored edge, in a new table each read.

layer.exclusive_zone: integerexclusive_zone read only ​

How much of an edge the layer reserves.

  • Above 0: that many pixels, which output:usable_area() leaves out.
  • 0: the layer moves clear of space other layers reserve.
  • -1: the layer ignores reserved space and reaches the edges it is anchored to.

layer.exclusive_edge: "top" | "bottom" | "left" | "right" | nilexclusive_edge read only ​

The edge the app picked for its exclusive zone.

  • nil when it picked none. The zone then goes on the edge the anchors imply: the one anchored edge, or the one opposite the free edge when three are anchored.

layer.requested_size: Sizerequested_size read only ​

The size the app asked for. size is the size it got.

  • 0 on an axis means stretch between the anchors.

layer.has_content: booleanhas_content read only ​

Whether the layer has drawn anything yet. It turns true just before first_content fires and stays true.

Methods ​

layer:close() -> nilclose ​

Asks the app to close the layer. closed fires when it does.

lua
wm.input:on("key", function(event)
	if event.state == "Pressed" and event.raw_key == Key.Escape then
		for _, launcher in ipairs(wm.layers:namespace("launcher")) do launcher:close() end
	end
end)

layer:on(event: "first_content" | "changed" | "closed", fn: function) -> functionon ​

Listens for one of this layer's events.

  • Listeners are dropped after closed.

Errors for any other event name. The message lists the valid ones.

Events ​

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

"first_content" (layer: Layer)first_content ​

The layer drew for the first time. position and size are known from here on.

  • After a reload it fires again for every layer that has drawn, right after new_layer.

"changed" (layer: Layer)changed ​

Something about the layer differs from what the config last saw: anchor, margin, exclusive zone or edge, requested size, keyboard interactivity, depth, position or size. Compare the fields yourself to see which.

  • position, size and output:usable_area() already have their new values.
  • It also fires for a layer that moved because another layer or the output changed.
  • A resize usually fires it twice: once when Hazel places the layer, once when the app draws at the new size.
lua
wm.layers:on("new_layer", function(layer)
	local last_zone = layer.exclusive_zone
	layer:on("changed", function(layer)
		if layer.exclusive_zone ~= last_zone then
			last_zone = layer.exclusive_zone
			print(layer.namespace, "now reserves", last_zone)
		end
	end)
end)

"closed" (layer: Layer)closed ​

The layer is gone from wm.layers.

  • Its reserved space is back in output:usable_area().

  • layer.output still answers. position and size read 0.

  • Its listeners are dropped after this.