Hello people, the attached patch adds a few new functions to awful.widget and awful.tag which allow having icons for tags. The additions to awful.tag are:
awful.tag.seticon(icon, tag)
awful.tag.geticon(tag)
These get and set the tags icon, which can either be an image object or a file
path.
I also added a new function to awful.widget, which is:
awful.widget.taglist.label.icons(t, args)
which creates tag labels that use the icon property if available. If no icon is
available, the tags name is used instead. Note that currently, this doesn't
support taglist_squares.
--
Gregor Best
From baaf2d114169cf11f1478f30ad723ab824c977d3 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 | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 0 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..d7b028c 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") @@ -116,6 +117,58 @@ function taglist.new(screen, label, buttons) return w end +--- Return labels for a taglist widget with all tags from the screen, with icons +-- This functions works like taglist.label.all, but it doesn't use taglist_squares_* +-- if a tag icon is set, it is used instead of the tag name +-- @param t The tag +-- @param args The arguments table +-- bg_focus The background color for selected tag. +-- fg_focus The foreground color for selected tag. +-- bg_urgent The background color for urgent tags. +-- fg_urgent The foreground color for urgent tags. +-- @return A string to print, a background color, a background image and a +-- background resize value. +function taglist.label.icons(t, args) + if not args then args = {} end + local theme = beautiful.get() + local fg_focus = args.fg_focus or theme.taglist_fg_focus or theme.fg_focus + local bg_focus = args.bg_focus or theme.taglist_bg_focus or theme.bg_focus + local fg_urgent = args.fg_urgent or theme.taglist_fg_urgent or theme.fg_urgent + local bg_urgent = args.bg_urgent or theme.taglist_bg_urgent or theme.bg_urgent + local font = args.font or theme.taglist_font or theme.font or "" + local text = "<span font_desc='"..font.."'> " + local bg_color = nil + local fg_color = nil + local bg_image + local bg_resize = false + bg_resize = true + if t.selected then + bg_color = bg_focus + fg_color = fg_focus + end + local cls = t:clients() + for k, c in pairs(cls) do + if c.urgent then + if bg_urgent then bg_color = bg_urgent end + if fg_urgent then fg_color = fg_urgent end + break + end + end + if tag.geticon(t) and type(tag.geticon(t)) == "image" then + bg_image = tag.geticon(t) + elseif tag.geticon(t) then + bg_image = capi.image(tag.geticon(t)) + else + 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) + end + end + text = text .. " </span>" + return text, bg_color, bg_image, bg_resize +end + --- Return labels for a taglist widget with all tag from screen. -- It returns the tag name and set a special -- foreground and background color for selected tags. -- 1.6.1
signature.asc
Description: PGP signature
