Krolyxon
Commit 6418b5f

Branches

Refs →

aurora.confighyprsourcemonitors.lua

54 lines · 2.4 KB · Lua

1-- -----------------------------------------------------
2-- Monitors (replaced kanshi: its wlr-output-management state overrode every hl.monitor() rule)
3-- -----------------------------------------------------
4-- Defaults are below. aurora's settings app (Display) saves per-output changes and the layout to
5-- ~/.config/aurora/monitors.lua (generated, not in the repo) and changes them live through
6-- `hyprctl eval 'monitors.apply()'`.
7-- layout: "extend" every connected output on
8-- "laptop" only the laptop panel
9-- "external" laptop panel off while another output is on (it comes back when that one is unplugged)
10monitors = {
11 laptop = "eDP-1",
12 layout = "extend",
13 outputs = {
14 ["eDP-1"] = { mode = "highrr", position = "0x0", scale = 1 },
15 ["HDMI-A-1"] = { mode = "1920x1080", position = "1920x0", scale = 1 },
16 },
17 fallback = { mode = "preferred", position = "auto", scale = 1 }, -- any other output
18}
19
20local ok, saved = pcall(dofile, HOME .. "/.config/aurora/monitors.lua")
21if ok and type(saved) == "table" then
22 if saved.layout == "extend" or saved.layout == "laptop" or saved.layout == "external" then
23 monitors.layout = saved.layout
24 end
25 for name, s in pairs(saved.outputs or {}) do monitors.outputs[name] = s end
26end
27
28local function rule(name, s, off)
29 -- disabled = false explicitly: hl.monitor() merges into the output's existing rule
30 if off then return { output = name, disabled = true } end
31 return { output = name, mode = s.mode, position = s.position, scale = s.scale, disabled = false }
32end
33
34-- is an output other than the laptop panel (and `gone`, which is being unplugged) on?
35local function externalOn(gone)
36 for _, m in ipairs(hl.get_monitors()) do
37 if m.name ~= monitors.laptop and m.name ~= gone then return true end
38 end
39 return false
40end
41
42function monitors.apply(gone)
43 local l = monitors.layout
44 hl.monitor(rule("", monitors.fallback, l == "laptop"))
45 for name, s in pairs(monitors.outputs) do
46 if name ~= monitors.laptop then hl.monitor(rule(name, s, l == "laptop")) end
47 end
48 hl.monitor(rule(monitors.laptop, monitors.outputs[monitors.laptop] or monitors.fallback,
49 l == "external" and externalOn(gone)))
50end
51
52monitors.apply()
53hl.on("monitor.added", function() monitors.apply() end)
54hl.on("monitor.removed", function(m) monitors.apply(m.name) end)