Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion default/hypr/wide-gamut.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,46 @@ local paths = require("default.hypr.paths")

local chosen = {}

-- The area of the primaries triangle in an EDID's chromaticity block (sRGB is
-- about 0.11). A panel that reports no primaries has no gamut to map into:
-- "edid" then collapses the output to black. Unreadable EDIDs count as usable.
local function edid_has_gamut(name)
if not name:match("^[%w%-]+$") then
return true
end

local pipe = io.popen("cat /sys/class/drm/card*-" .. name .. "/edid 2>/dev/null", "r")
if not pipe then
return true
end
local edid = pipe:read("a")
pipe:close()
if #edid < 35 then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: requiring 128 bytes and the EDID header would keep a truncated blob from being read as primaries.

— Marcelo's agent

return true
end

local function coord(msb_offset, lsb_offset, shift)
local msb = edid:byte(msb_offset + 1)
local lsb = (edid:byte(lsb_offset + 1) // 2 ^ shift) % 4
return (msb * 4 + lsb) / 1024
end

local rx, ry = coord(27, 25, 6), coord(28, 25, 4)
local gx, gy = coord(29, 25, 2), coord(30, 25, 0)
local bx, by = coord(31, 26, 6), coord(32, 26, 4)
return math.abs(rx * (gy - by) + gx * (by - ry) + bx * (ry - gy)) / 2 > 0.01
end

-- Whether every monitor a rule covers has a gamut ("" covers all of them).
local function gamut_for_rule(output)
for _, monitor in ipairs(hl.get_monitors()) do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If hl.get_monitors() is still empty while the config first loads, the catch-all gets edid and the panel goes black at login. Worth re-checking on hyprland.start and monitor.added.

— Marcelo's agent

if (output == "" or monitor.name == output) and not edid_has_gamut(monitor.name) then
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
return false
end
end
return true
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
end

local function chosen_for(output)
if chosen[output] then
return chosen[output]
Expand Down Expand Up @@ -47,7 +87,7 @@ if o.shell_succeeds(o.shell_quote(paths.omarchy_path .. "/bin/omarchy-hw-aarch64
if rule.cm ~= nil then
chosen[output] = rule.cm
else
rule.cm = chosen_for(output) or "edid"
rule.cm = chosen_for(output) or (gamut_for_rule(output) and "edid" or nil)
end
end

Expand Down