diff --git a/lib/gears/color.lua b/lib/gears/color.lua index 87a20ca7..87bc0a72 100644 --- a/lib/gears/color.lua +++ b/lib/gears/color.lua @@ -338,6 +338,11 @@ end -- @treturn string color if it is valid, else fallback. function color.ensure_pango_color(check_color, fallback) check_color = tostring(check_color) + -- Pango markup supports alpha, PangoColor does not. Thus, check for this. + local len = #check_color + if string.match(check_color, "^#%x+$") and (len == 5 or len == 9 or len == 17) then + return check_color + end return Pango.Color.parse(Pango.Color(), check_color) and check_color or fallback or "black" end diff --git a/spec/gears/color_spec.lua b/spec/gears/color_spec.lua index 89b0b1b5..ed550c7f 100644 --- a/spec/gears/color_spec.lua +++ b/spec/gears/color_spec.lua @@ -271,7 +271,7 @@ describe("gears.color", function() describe("ensure_pango_color", function() -- Successful cases for _, value in ipairs{ "red", "cyan", "black", "#f00", "#014578", - "#01ef01ef01ef" + "#01ef01ef01ef", "#f00f", "#014578ab", "#01ef01ef01ef01ef" } do it(value, function() assert.is.same(value, color.ensure_pango_color(value)) @@ -282,6 +282,11 @@ describe("gears.color", function() assert.is.same("black", color.ensure_pango_color("#abz")) end) + it("#fedcba98765432", function() + -- Only one, two or four characters per channel are supported + assert.is.same("black", color.ensure_pango_color("#fedcba98765432")) + end) + it("fallback", function() assert.is.same("zzz", color.ensure_pango_color("#abz", "zzz")) end)