Skip to content

Class WindowStates ​

The states a window's app is told about, read from window.states.

States tell the app how it is shown. They don't move or resize the window: to maximize, set "maximized" and also move and size the window.

  • Hazel never sets a state by itself.
  • Several changes in one handler reach the app together.
lua
local function show_as_tiled(window)
	window.states:set("maximized", false)
	for _, edge in ipairs({ "tiled_left", "tiled_right", "tiled_top", "tiled_bottom" }) do
		window.states:set(edge, true)
	end
end

show_as_tiled(window)

States ​

  • maximized: the app fills the size it is given, without its shadows and rounded corners.
  • fullscreen: the app leaves out its own title bar and borders. Hazel draws the window in front of top layers such as bars, and behind overlay layers.
  • resizing: an interactive resize is going on, such as during a resize_request drag.
  • activated: the app draws itself as the active window, with a highlighted title bar for example. It is separate from keyboard focus.
  • tiled_left, tiled_right, tiled_top, tiled_bottom: that edge touches something, so the app draws it square and without a shadow.
  • suspended: the window can't be seen, so the app may stop drawing.

Taskbars see maximized, fullscreen and activated.

Methods ​

states:has(name: string) -> booleanhas ​

Whether the state is set, even if the app hasn't caught up yet.

  • false for an unknown name.
lua
local maximized = window.states:has("maximized")

states:list() -> string[]list ​

Every state that is set, as a new table of names.

lua
print(table.concat(window.states:list(), ", "))

states:set(name: string, enabled: boolean) -> nilset ​

Sets or clears one state.

  • An unknown name is ignored without an error.
lua
window:on("focus", function(seat, focused, window)
	window.states:set("activated", #window.focused_seats > 0)
end)