Okay, here it comes, a new version with imagebox + textbox, also supporting taglist squares :)
I removed the function awful.widget.taglist.label.icon, now the ordinary *.all
function sets the icon if it is set.
Hint: For a nicer, icons only look use "" as the tag name :)
--
Gregor Best
From b1508a3058ef731c4e39419392dedfdecabfc0ec Mon Sep 17 00:00:00 2001 From: Gregor Best <[email protected]> Date: Tue, 13 Jan 2009 16:04:11 +0100 Subject: [PATCH] (awful/widget awful/tag): add support for tag icons Signed-off-by: Gregor Best <[email protected]> --- lib/awful/tag.lua.in | 16 +++++++++ lib/awful/widget.lua.in | 87 ++++++++++++++++++++++++++++++----------------- 2 files changed, 72 insertions(+), 31 deletions(-) diff --git a/lib/awful/tag.lua.in b/lib/awful/tag.lua.in index 40b5481..6c69eb2 100644 --- a/lib/awful/tag.lua.in +++ b/lib/awful/tag.lua.in @@ -142,6 +142,22 @@ function incnmaster(add, t) setnmaster(getnmaster(t) + add) end + +--- Set the tag icon +-- @param icon the icon to set, either path or image object +-- @param tag the tag +function seticon(icon, tag) + local tag = tag or selected() + setproperty(tag, "icon", icon) +end + +--- Get the tag icon +-- @param t the tag +function geticon(tag) + local tag = tag or selected() + return getproperty(tag, "icon") +end + --- Set number of column windows. -- @param ncol The number of column. function setncol(ncol, t) diff --git a/lib/awful/widget.lua.in b/lib/awful/widget.lua.in index 3a38683..be06d65 100644 --- a/lib/awful/widget.lua.in +++ b/lib/awful/widget.lua.in @@ -24,6 +24,7 @@ local hooks = require("awful.hooks") local beautiful = require("beautiful") local menu = require("awful.menu") local client = require("awful.client") +local tag = require("awful.tag") --- Widget module for awful module("awful.widget") @@ -45,38 +46,40 @@ local function taglist_update (screen, w, label, buttons, data) local len = w.len or #w -- Add more widgets if len < #tags then - for i = len + 1, #tags do - local wi = capi.widget({ type = "textbox" }) - w[i] = wi - tagwidgets[wi] = tags[i] - end + for i = len * 2 + 1, #tags * 2, 2 do + w[i] = capi.widget({ type = "imagebox" }) + w[i + 1] = capi.widget({ type = "textbox" }) + end -- Remove widgets elseif len > #tags then - for i = #tags + 1, len do - tagwidgets[w[i]] = nil + for i = #tags * 2 + 1, len * 2, 2 do w[i] = nil + w[i + 1] = nil end end + -- Update widgets text - for k, tag in ipairs(tags) do - local text, bg, bg_image, bg_resize = label(tag) - w[k].text = text - if text then - w[k].bg, w[k].bg_image, w[k].bg_resize = bg, bg_image, bg_resize - if buttons then - if not data[tag] then - -- Replace press function by a new one calling with tags as - -- argument. - -- This is done here because order of tags can change - data[tag] = {} - for kb, b in ipairs(buttons) do - -- Copy object - data[tag][kb] = capi.button(b) - data[tag][kb].press = function () b.press(tag) end - end + for k = 1, #tags * 2, 2 do + local tag = tags[(k + 1) / 2] + local text, bg, bg_image, bg_resize, icon, squares = label(tag) + w[k].image = icon + w[k].bg = bg + w[k + 1].text = text + w[k + 1].bg, w[k + 1].bg_image, w[k + 1].bg_resize = bg, bg_image, bg_resize + if buttons then + if not data[tag] then + -- Replace press function by a new one calling with tags as + -- argument. + -- This is done here because order of tags can change + data[tag] = {} + for kb, b in ipairs(buttons) do + -- Copy object + data[tag][kb] = capi.button(b) + data[tag][kb].press = function () b.press(tag) end end - w[k]:buttons(data[tag]) end + w[k]:buttons(data[tag]) + w[k + 1]:buttons(data[tag]) end end end @@ -141,11 +144,12 @@ function taglist.label.all(t, args) local taglist_squares_unsel = args.squares_unsel or theme.taglist_squares_unsel local taglist_squares_resize = theme.taglist_squares_resize or args.squares_resize or "true" local font = args.font or theme.taglist_font or theme.font or "" - local text = "<span font_desc='"..font.."'> " + local text = "<span font_desc='"..font.."'>" local sel = capi.client.focus local bg_color = nil local fg_color = nil local bg_image + local icon local bg_resize = false if t.selected then bg_color = bg_focus @@ -170,13 +174,34 @@ function taglist.label.all(t, args) end end end - if fg_color then - text = text .. "<span color='"..util.color_strip_alpha(fg_color).."'>"..util.escape(t.name).."</span>" - else - text = text .. util.escape(t.name) + local taglist_squares = false + if taglist_squares_sel or taglist_squares_unsel then + taglist_squares = true end - text = text .. " </span>" - return text, bg_color, bg_image, bg_resize + if t.name then + if fg_color then + text = text .. "<span color='"..util.color_strip_alpha(fg_color).."'>" + if taglist_squares then + text = text .. " " + end + text = text..util.escape(t.name).." </span>" + else + if taglist_squares then + text = text .. " " + end + text = text .. util.escape(t.name) .. " " + end + elseif taglist_squares then + text = text .. " " + end + text = text .. "</span>" + if tag.geticon(t) and type(tag.geticon(t)) == "image" then + icon = tag.geticon(t) + elseif tag.geticon(t) then + icon = capi.image(tag.geticon(t)) + end + + return text, bg_color, bg_image, bg_resize, icon, taglist_squares end --- Return labels for a taglist widget with all *non empty* tags from screen. -- 1.6.1
signature.asc
Description: PGP signature
