From 2ba9c8667fa71a7cac3ccd9e456d3df17934c400 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 10 Jul 2015 18:09:45 -0400 Subject: [PATCH 1/2] 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. From d22a65a103e8f53ac7166dad11f280206dd7704f Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 10 Jul 2015 18:11:45 -0400 Subject: [PATCH 2/2] Replace uses of color_strip_alpha with ensure_pango_color, refactor This simplifies the logic a bit since all of the fg/bg colors are always set when it gets to checking the client state. --- lib/awful/prompt.lua | 7 ++++++- lib/awful/widget/taglist.lua | 4 ++-- lib/awful/widget/tasklist.lua | 30 +++++++++++++----------------- lib/menubar/init.lua | 5 ++--- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/awful/prompt.lua b/lib/awful/prompt.lua index cf133193..a542be43 100644 --- a/lib/awful/prompt.lua +++ b/lib/awful/prompt.lua @@ -189,7 +189,12 @@ local function prompt_text_with_cursor(args) text_end = util.escape(text:sub(args.cursor_pos + 1)) end - ret = _prompt .. text_start .. "" .. char .. "" .. text_end .. spacer + local cursor_color = util.ensure_pango_color(args.cursor_color) + local text_color = util.ensure_pango_color(args.text_color) + + ret = _prompt .. text_start .. "" .. char .. "" .. text_end .. spacer return ret end diff --git a/lib/awful/widget/taglist.lua b/lib/awful/widget/taglist.lua index 4aed1caa..d2133e64 100644 --- a/lib/awful/widget/taglist.lua +++ b/lib/awful/widget/taglist.lua @@ -99,8 +99,8 @@ function taglist.taglist_label(t, args) if not tag.getproperty(t, "icon_only") then text = "" if fg_color then - text = text .. "" .. - (util.escape(t.name) or "") .. "" + text = text .. "" .. (util.escape(t.name) or "") .. "" else text = text .. (util.escape(t.name) or "") end diff --git a/lib/awful/widget/tasklist.lua b/lib/awful/widget/tasklist.lua index 9f9d19a0..c42f39d3 100644 --- a/lib/awful/widget/tasklist.lua +++ b/lib/awful/widget/tasklist.lua @@ -29,14 +29,14 @@ tasklist.filter = {} local function tasklist_label(c, args) if not args then args = {} end local theme = beautiful.get() - local fg_normal = args.fg_normal or theme.tasklist_fg_normal or theme.fg_normal or "#ffffff" + local fg_normal = util.ensure_pango_color(args.fg_normal or theme.tasklist_fg_normal or theme.fg_normal, "white") local bg_normal = args.bg_normal or theme.tasklist_bg_normal or theme.bg_normal or "#000000" - local fg_focus = args.fg_focus or theme.tasklist_fg_focus or theme.fg_focus - local bg_focus = args.bg_focus or theme.tasklist_bg_focus or theme.bg_focus - local fg_urgent = args.fg_urgent or theme.tasklist_fg_urgent or theme.fg_urgent - local bg_urgent = args.bg_urgent or theme.tasklist_bg_urgent or theme.bg_urgent - local fg_minimize = args.fg_minimize or theme.tasklist_fg_minimize or theme.fg_minimize - local bg_minimize = args.bg_minimize or theme.tasklist_bg_minimize or theme.bg_minimize + local fg_focus = util.ensure_pango_color(args.fg_focus or theme.tasklist_fg_focus or theme.fg_focus, fg_normal) + local bg_focus = args.bg_focus or theme.tasklist_bg_focus or theme.bg_focus or bg_normal + local fg_urgent = util.ensure_pango_color(args.fg_urgent or theme.tasklist_fg_urgent or theme.fg_urgent, fg_normal) + local bg_urgent = args.bg_urgent or theme.tasklist_bg_urgent or theme.bg_urgent or bg_normal + local fg_minimize = util.ensure_pango_color(args.fg_minimize or theme.tasklist_fg_minimize or theme.fg_minimize, fg_normal) + local bg_minimize = args.bg_minimize or theme.tasklist_bg_minimize or theme.bg_minimize or bg_normal local bg_image_normal = args.bg_image_normal or theme.bg_image_normal local bg_image_focus = args.bg_image_focus or theme.bg_image_focus local bg_image_urgent = args.bg_image_urgent or theme.bg_image_urgent @@ -75,23 +75,19 @@ local function tasklist_label(c, args) end if capi.client.focus == c then bg = bg_focus + text = text .. ""..name.."" bg_image = bg_image_focus - if fg_focus then - text = text .. ""..name.."" - else - text = text .. ""..name.."" - end - elseif c.urgent and fg_urgent then + elseif c.urgent then bg = bg_urgent - text = text .. ""..name.."" + text = text .. ""..name.."" bg_image = bg_image_urgent - elseif c.minimized and fg_minimize and bg_minimize then + elseif c.minimized then bg = bg_minimize - text = text .. ""..name.."" + text = text .. ""..name.."" bg_image = bg_image_minimize else bg = bg_normal - text = text .. ""..name.."" + text = text .. ""..name.."" bg_image = bg_image_normal end text = text .. "" diff --git a/lib/menubar/init.lua b/lib/menubar/init.lua index 08458cf6..1cd2c745 100644 --- a/lib/menubar/init.lua +++ b/lib/menubar/init.lua @@ -86,7 +86,7 @@ local common_args = { w = wibox.layout.fixed.horizontal(), -- @param c The desired text color. -- @return the text wrapped in a span tag. local function colortext(s, c) - return "" .. s .. "" + return "" .. s .. "" end --- Get how the menu item should be displayed. @@ -94,8 +94,7 @@ end -- @return item name, item background color, background image, item icon. local function label(o) if o.focused then - local color = awful.util.color_strip_alpha(theme.fg_focus) - return colortext(o.name, color), theme.bg_focus, nil, o.icon + return colortext(o.name, theme.fg_focus), theme.bg_focus, nil, o.icon else return o.name, theme.bg_normal, nil, o.icon end