Outputs
Monitors are outputs. Each has a connector name such as DP-1 or eDP-1, and a position in one shared coordinate space that windows are placed in.
To see the names of yours, run this in a terminal inside Hazel:
hazel eval 'local names = {} for name in pairs(wm.outputs) do names[#names + 1] = name end return names'Nested, there is one output called winit.
All of these build on your first config.
Monitor layout
Position, scale and mode per monitor, like Hyprland's monitor= lines.
local monitors = {
["DP-1"] = { position = Point(0, 0), mode = { size = { width = 2560, height = 1440 }, refresh = 144000 } },
["eDP-1"] = { position = Point(2560, 0), scale = 1.5 },
}
local function set_up_output(output)
local wanted = monitors[output.name]
if not wanted then return end
if wanted.mode then output.mode = wanted.mode end
if wanted.scale then output.scale = wanted.scale end
if wanted.position then output.position = wanted.position end
if wanted.transform then output.transform = wanted.transform end
end
wm.outputs:on("added", set_up_output)refreshis in millihertz: 144000 is 144 Hz. Leave it out to get the highest rate at that size.- Positions are in logical pixels, after scaling. A 2560x1440 monitor at scale 1.5 is 1707 wide, so the next one to its right starts at x 1707.
- Monitors aren't moved apart for you. Two that overlap show the same part of the desktop.
transformturns a monitor:"90","180","270", and"flipped"versions of each.addedfires for monitors that are already there each time the config loads, and for each one plugged in later.
Moving between outputs
mod + comma and period focus the window under the centre of the previous or next output. Add Shift to send the focused window there.
Works with Tiling: a tiled window joins the layout on the other output.
local function output_after(output, step)
local outputs = wm.outputs:all()
for index, each in ipairs(outputs) do
if each == output then return outputs[(index - 1 + step) % #outputs + 1] end
end
return outputs[1]
end
local function current_output()
local window = focused_window()
return window and output_of(window) or output_under_pointer()
end
for key, step in pairs({ comma = -1, period = 1 }) do
bind(mod, key, function()
local target = output_after(current_output(), step)
local center = target:area():center()
local pointer = seat() and seat():pointer()
if pointer then pointer:move(center) end
local window = wm.windows:under(center)
if window then focus(window) end
end)
bind(mod .. " shift", key, function()
local window = focused_window()
if not window then return end
local source = output_of(window)
local target = output_after(source, step)
local from, to = source:area(), target:area()
window.box.position = window.box.position:target() - Point(from.x, from.y) + Point(to.x, to.y)
if wm.store.tiling then wm.store.tiling.outputs[tostring(window.id)] = target.name end
wm:emit("arrange")
end)
endWhen a monitor is unplugged
Windows on an unplugged monitor would stay where it was, out of reach. This moves them to the first output left.
wm.outputs:on("removed", function(removed)
local fallback
for _, output in ipairs(wm.outputs:all()) do
if output ~= removed then fallback = output break end
end
if not fallback then return end
local from, to = removed:area(), fallback:area()
for _, window in ipairs(wm.windows:all()) do
if from:contains(window.box.position:target()) then
window.box.position = window.box.position:target() - Point(from.x, from.y) + Point(to.x, to.y)
end
end
end)Tiling already moves tiled windows to an output that still exists. This recipe is for the floating ones.
All of them
local monitors = {
["DP-1"] = { position = Point(0, 0), mode = { size = { width = 2560, height = 1440 }, refresh = 144000 } },
["eDP-1"] = { position = Point(2560, 0), scale = 1.5 },
}
local function set_up_output(output)
local wanted = monitors[output.name]
if not wanted then return end
if wanted.mode then output.mode = wanted.mode end
if wanted.scale then output.scale = wanted.scale end
if wanted.position then output.position = wanted.position end
if wanted.transform then output.transform = wanted.transform end
end
wm.outputs:on("added", set_up_output)
local function output_after(output, step)
local outputs = wm.outputs:all()
for index, each in ipairs(outputs) do
if each == output then return outputs[(index - 1 + step) % #outputs + 1] end
end
return outputs[1]
end
local function current_output()
local window = focused_window()
return window and output_of(window) or output_under_pointer()
end
for key, step in pairs({ comma = -1, period = 1 }) do
bind(mod, key, function()
local target = output_after(current_output(), step)
local center = target:area():center()
local pointer = seat() and seat():pointer()
if pointer then pointer:move(center) end
local window = wm.windows:under(center)
if window then focus(window) end
end)
bind(mod .. " shift", key, function()
local window = focused_window()
if not window then return end
local source = output_of(window)
local target = output_after(source, step)
local from, to = source:area(), target:area()
window.box.position = window.box.position:target() - Point(from.x, from.y) + Point(to.x, to.y)
if wm.store.tiling then wm.store.tiling.outputs[tostring(window.id)] = target.name end
wm:emit("arrange")
end)
end
wm.outputs:on("removed", function(removed)
local fallback
for _, output in ipairs(wm.outputs:all()) do
if output ~= removed then fallback = output break end
end
if not fallback then return end
local from, to = removed:area(), fallback:area()
for _, window in ipairs(wm.windows:all()) do
if from:contains(window.box.position:target()) then
window.box.position = window.box.position:target() - Point(from.x, from.y) + Point(to.x, to.y)
end
end
end)