Persist complete monitor layouts
This commit is contained in:
@@ -20,7 +20,10 @@
|
||||
local prefs = require("prefs")
|
||||
|
||||
-- Per-output overrides written by Panama Settings, keyed by output name:
|
||||
-- { ["DP-2"] = { mode = "3840x2160@60", scale = 2, transform = 0 } }
|
||||
-- { ["DP-2"] = {
|
||||
-- mode = "3840x2160@60", scale = 2, transform = 0,
|
||||
-- x = 0, y = 0, primary = true,
|
||||
-- } }
|
||||
--
|
||||
-- Only mode, scale, and transform are read. Colour management and bit depth
|
||||
-- stay here, because those are the settings with a documented reason attached
|
||||
@@ -71,6 +74,26 @@ local function valid_transform(transform)
|
||||
and transform <= 3
|
||||
end
|
||||
|
||||
local function valid_coordinate(value)
|
||||
return type(value) == "number"
|
||||
and value == value
|
||||
and value == math.floor(value)
|
||||
and value >= -100000
|
||||
and value <= 100000
|
||||
end
|
||||
|
||||
local function valid_position(entry)
|
||||
return valid_coordinate(entry.x) and valid_coordinate(entry.y)
|
||||
end
|
||||
|
||||
local function valid_primary(entry)
|
||||
return type(entry.primary) == "boolean"
|
||||
end
|
||||
|
||||
local function has_layout_fields(entry)
|
||||
return entry.x ~= nil or entry.y ~= nil or entry.primary ~= nil
|
||||
end
|
||||
|
||||
local function display_entry(output)
|
||||
if type(output) ~= "string" or output == ""
|
||||
or output:match("^[%w_.-]+$") == nil then
|
||||
@@ -85,9 +108,23 @@ local function display_entry(output)
|
||||
or not valid_transform(entry.transform) then
|
||||
return nil
|
||||
end
|
||||
-- Legacy records have none of the layout fields and keep automatic
|
||||
-- placement. A partially written extended record is unsafe: accepting its
|
||||
-- mode but guessing its position could overlap or strand another output.
|
||||
if has_layout_fields(entry)
|
||||
and (not valid_position(entry) or not valid_primary(entry)) then
|
||||
return nil
|
||||
end
|
||||
return entry
|
||||
end
|
||||
|
||||
local function display_position(entry, fallback)
|
||||
if entry ~= nil and has_layout_fields(entry) then
|
||||
return string.format("%dx%d", entry.x, entry.y)
|
||||
end
|
||||
return fallback
|
||||
end
|
||||
|
||||
local shipped_mode = "4500x3000@60"
|
||||
local shipped_scale = 1.5
|
||||
local shipped_transform = 0
|
||||
@@ -96,7 +133,7 @@ local dp2 = display_entry("DP-2")
|
||||
hl.monitor({
|
||||
output = "DP-2",
|
||||
mode = dp2 and dp2.mode or shipped_mode,
|
||||
position = "0x0",
|
||||
position = display_position(dp2, "0x0"),
|
||||
scale = dp2 and dp2.scale or shipped_scale,
|
||||
transform = dp2 and dp2.transform or shipped_transform,
|
||||
|
||||
@@ -119,7 +156,7 @@ for output, _ in pairs(displays) do
|
||||
hl.monitor({
|
||||
output = output,
|
||||
mode = entry.mode,
|
||||
position = "auto",
|
||||
position = display_position(entry, "auto"),
|
||||
scale = entry.scale,
|
||||
transform = entry.transform,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user