From 2ba9c8667fa71a7cac3ccd9e456d3df17934c400 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 10 Jul 2015 18:09:45 -0400 Subject: [PATCH] Replace color_strip_alpha with ensure_pango_color color_strip_alpha was used to insert colors into Pango markup, but it did not correctly check for valid Pango colors. ensure_pango_color checks if the color is valid in Pango, and returns a placeholder if it is not. --- lib/awful/util.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/awful/util.lua b/lib/awful/util.lua index a7ff1f1f..05bb6e57 100644 --- a/lib/awful/util.lua +++ b/lib/awful/util.lua @@ -20,6 +20,8 @@ local type = type local rtable = table local pairs = pairs local string = string +local lgi = require("lgi") +local Pango = lgi.Pango local capi = { awesome = awesome, @@ -47,14 +49,13 @@ function util.deprecate(see) io.stderr:write("\n" .. tb .. "\n") end ---- Strip alpha part of color. +--- Get a valid color for Pango markup -- @param color The color. --- @return The color without alpha channel. -function util.color_strip_alpha(color) - if color:len() == 9 then - color = color:sub(1, 7) - end - return color +-- @tparam string fallback The color to return if the first is invalid. (default: black) +-- @treturn string color if it is valid, else fallback. +function util.ensure_pango_color(color, fallback) + color = tostring(color) + return Pango.Color.parse(Pango.Color(), color) and color or fallback or "black" end --- Make i cycle.