1 ---------------------------------------------------------------------------
2 -- @author Julien Danjou <julien@danjou.info>
3 -- @copyright 2008-2009 Julien Danjou
4 -- @release @AWESOME_VERSION@
5 ---------------------------------------------------------------------------
7 -- Grab environment we need
8 local capi
= { screen
= screen
,
12 local setmetatable
= setmetatable
16 local common
= require("awful.widget.common")
17 local util
= require("awful.util")
18 local tag = require("awful.tag")
19 local beautiful
= require("beautiful")
20 local fixed
= require("wibox.layout.fixed")
21 local surface
= require("gears.surface")
23 --- Taglist widget module for awful
24 -- awful.widget.taglist
25 local taglist
= { mt
= {} }
28 function taglist
.taglist_label(t
, args
)
29 if not args
then args
= {} end
30 local theme
= beautiful
.get()
31 local fg_focus
= args
.fg_focus
or theme
.taglist_fg_focus
or theme
.fg_focus
32 local bg_focus
= args
.bg_focus
or theme
.taglist_bg_focus
or theme
.bg_focus
33 local fg_urgent
= args
.fg_urgent
or theme
.taglist_fg_urgent
or theme
.fg_urgent
34 local bg_urgent
= args
.bg_urgent
or theme
.taglist_bg_urgent
or theme
.bg_urgent
35 local bg_occupied
= args
.bg_occupied
or theme
.taglist_bg_occupied
36 local fg_occupied
= args
.fg_occupied
or theme
.taglist_fg_occupied
37 local taglist_squares_sel
= args
.squares_sel
or theme
.taglist_squares_sel
38 local taglist_squares_unsel
= args
.squares_unsel
or theme
.taglist_squares_unsel
39 local taglist_squares_resize
= theme
.taglist_squares_resize
or args
.squares_resize
or "true"
40 local font
= args
.font
or theme
.taglist_font
or theme
.font
or ""
41 local text
= "<span font_desc='"..font
.."'>"
42 local sel
= capi
.client
.focus
47 local bg_resize
= false
48 local is_selected
= false
54 if taglist_squares_sel
then
55 -- Check that the selected clients is tagged with 't'.
56 local seltags
= sel
:tags()
57 for _
, v
in ipairs(seltags
) do
59 bg_image
= surface
.load(taglist_squares_sel
)
60 bg_resize
= taglist_squares_resize
== "true"
67 if not is_selected
then
68 local cls
= t
:clients()
70 if taglist_squares_unsel
then
71 bg_image
= surface
.load(taglist_squares_unsel
)
72 bg_resize
= taglist_squares_resize
== "true"
74 if bg_occupied
then bg_color
= bg_occupied
end
75 if fg_occupied
then fg_color
= fg_occupied
end
77 for k
, c
in pairs(cls
) do
79 if bg_urgent
then bg_color
= bg_urgent
end
80 if fg_urgent
then fg_color
= fg_urgent
end
85 if not tag.getproperty(t
, "icon_only") then
87 text
= text
.. "<span color='"..util
.color_strip_alpha(fg_color
).."'>" ..
88 (util
.escape(t
.name
) or "") .. "</span>"
90 text
= text
.. (util
.escape(t
.name
) or "")
93 text
= text
.. "</span>"
94 if tag.geticon(t
) and type(tag.geticon(t
)) == "image" then
96 elseif tag.geticon(t
) then
97 icon
= surface
.load(tag.geticon(t
))
100 return text
, bg_color
, bg_image
, icon
103 local function taglist_update(s
, w
, buttons
, filter
, data
, style
)
105 for k
, t
in ipairs(tag.gettags(s
)) do
106 if not tag.getproperty(t
, "hide") and filter(t
) then
107 table.insert(tags
, t
)
111 local function label(c
) return taglist
.taglist_label(c
, style
) end
113 common
.list_update(w
, buttons
, label
, data
, tags
)
116 --- Get the tag object the given widget appears on.
117 -- @param widget The widget the look for.
118 -- @return The tag object.
119 function taglist
.gettag(widget
)
120 return common
.tagwidgets
[widget
]
123 --- Create a new taglist widget.
124 -- @param screen The screen to draw taglist for.
125 -- @param filter Filter function to define what clients will be listed.
126 -- @param buttons A table with buttons binding to set.
127 -- @param style The style overrides default theme.
128 -- bg_focus The background color for focused client.
129 -- fg_focus The foreground color for focused client.
130 -- bg_urgent The background color for urgent clients.
131 -- fg_urgent The foreground color for urgent clients.
132 -- squares_sel Optional: a user provided image for selected squares.
133 -- squares_unsel Optional: a user provided image for unselected squares.
134 -- squares_resize Optional: true or false to resize squares.
136 function taglist
.new(screen
, filter
, buttons
, style
)
137 local w
= fixed
.horizontal()
139 local data
= setmetatable({}, { __mode
= 'k' })
140 local u
= function (s
)
142 taglist_update(s
, w
, buttons
, filter
, data
, style
)
145 local uc
= function (c
) return u(c
.screen
) end
146 local ut
= function (t
) return u(tag.getscreen(t
)) end
147 capi
.client
.connect_signal("focus", uc
)
148 capi
.client
.connect_signal("unfocus", uc
)
149 tag.attached_connect_signal(screen
, "property::selected", ut
)
150 tag.attached_connect_signal(screen
, "property::icon", ut
)
151 tag.attached_connect_signal(screen
, "property::hide", ut
)
152 tag.attached_connect_signal(screen
, "property::name", ut
)
153 tag.attached_connect_signal(screen
, "property::activated", ut
)
154 tag.attached_connect_signal(screen
, "property::screen", ut
)
155 capi
.client
.connect_signal("property::urgent", uc
)
156 capi
.client
.connect_signal("property::screen", function(c
)
157 -- If client change screen, refresh it anyway since we don't from
158 -- which screen it was coming :-)
161 capi
.client
.connect_signal("tagged", uc
)
162 capi
.client
.connect_signal("untagged", uc
)
163 capi
.client
.connect_signal("unmanage", uc
)
168 --- Filtering function to include all nonempty tags on the screen.
170 -- @param args unused list of extra arguments.
171 -- @return true if t is not empty, else false
172 function taglist
.filter
.noempty(t
, args
)
173 return #t
:clients() > 0 or t
.selected
176 --- Filtering function to include all tags on the screen.
178 -- @param args unused list of extra arguments.
180 function taglist
.filter
.all(t
, args
)
184 function taglist
.mt
:__call(...)
185 return taglist
.new(...)
188 return setmetatable(taglist
, taglist
.mt
)
190 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80