Class OutputList
The outputs Hazel draws to, as wm.outputs.
Implements: List<Output>
pairs(wm.outputs) goes over them by name.
for name, output in pairs(wm.outputs) do
local area = output:area()
print(name, area.width .. "x" .. area.height)
endMethods
wm.outputs:name(name: string) -> Output?name
The output called name, such as "eDP-1" or "winit". Use it to find an output again from a saved name.
- nil when there is none.
local saved_name = output.name
local same_output = wm.outputs:name(saved_name)
assert(same_output == output)wm.outputs:under(point: Point) -> Output[]under
Every output whose area contains point, in global coordinates.
- Empty when the point is outside every output.
- More than one where outputs overlap.
local output_under_pointer = wm.outputs:under(pointer:position())[1] or wm.outputs:get(1)wm.outputs:add_virtual(name: string, size: Size) -> Outputadd_virtual
Adds an output with no monitor behind it. It is drawn like any other and fires added.
- It goes right of the rightmost output, at y 0.
- Its one mode is
sizeat 60 Hz. - Its
propertieshave make"Hazel"and model"Virtual". - Take a picture of it with
wm:screenshotand remove it withoutput:remove().
Errors on a tty, for a size outside 1x1 to 16384x16384, and when an output called name already exists.
wm.input:on("key", function(event)
if event.state == "Pressed" and event.raw_key == Key.F9 and not wm.outputs:name("preview") then
wm.outputs:add_virtual("preview", { width = 640, height = 480 })
end
end)Events
Listen with wm.outputs:on(name, fn), which returns a function that stops listening.
Errors for a name that isn't one of the events below.
"added" (output: Output)added
An output is ready to use.
- After each load of the config, it fires once for every output that already exists. Setting outputs up here covers the ones there at startup.
- Also fires for a new virtual output.
wm.outputs:on("added", function(added)
local area = added:area()
print(added.name .. " is " .. area.width .. "x" .. area.height .. " at " .. area.x .. ", " .. area.y)
end)"changed" (output: Output)changed
The output's scale, position, transform or mode changed. Its area() and usable_area() may have too.
- Setting
scale,positionortransformfires it straight away. - Setting
modefires it once the new mode is in use: at once on a tty, and once the window has resized when nested. - Resizing nested Hazel's window fires it too.
local last_area = {}
wm.outputs:on("changed", function(changed)
local area = changed:area()
local before = last_area[changed.name]
if before and (before.x ~= area.x or before.y ~= area.y) then
print(changed.name .. " moved by " .. (area.x - before.x) .. ", " .. (area.y - before.y))
end
last_area[changed.name] = area
end)"removed" (output: Output)removed
The output is about to go. Its name, area() and the windows on it can still be read, so move windows to another output here.
- After the handler, its layers are closed and its drawables dropped.
- Fires when a monitor is unplugged, and when a virtual output is removed.
wm.outputs:on("removed", function(removed)
local fallback
for _, candidate in ipairs(wm.outputs:all()) do
if candidate ~= removed then fallback = candidate break end
end
if not fallback then return end
local from, to = removed:area(), fallback:area()
for _, moved in ipairs(wm.windows:all()) do
if from:contains(moved.box.position:target()) then
moved.box.position = moved.box.position:target() - Point(from.x, from.y) + Point(to.x, to.y)
end
end
end)