{tag,task}list: add update_function and base_widget constructor arguments

The arguments are optional, making it possible to use a custom function
to create the {tag,task}list layout. The base_widget arguments can be
used to override the base layout of the {tag,task}list widget.

Signed-off-by: Lukáš Hrázký <lukkash@email.cz>
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Lukáš Hrázký 2013-01-05 16:12:51 +01:00 committed by Uli Schlachter
parent 8560de597c
commit 4463f89b15
3 changed files with 51 additions and 26 deletions

View File

@ -36,6 +36,24 @@ local function replace_in_template(t, ib, tb)
end end
end end
function common.create_buttons(buttons, object)
if buttons then
local btns = {}
for kb, b in ipairs(buttons) do
-- Create a proxy button object: it will receive the real
-- press and release events, and will propagate them the the
-- button object the user provided, but with the object as
-- argument.
local btn = capi.button { modifiers = b.modifiers, button = b.button }
btn:connect_signal("press", function () b:emit_signal("press", object) end)
btn:connect_signal("release", function () b:emit_signal("release", object) end)
btns[#btns + 1] = btn
end
return btns
end
end
function common.list_update(w, buttons, label, data, objects) function common.list_update(w, buttons, label, data, objects)
-- update the widgets, creating them if needed -- update the widgets, creating them if needed
w:reset() w:reset()
@ -61,20 +79,7 @@ function common.list_update(w, buttons, label, data, objects)
-- And all of this gets a background -- And all of this gets a background
bgb:set_widget(l) bgb:set_widget(l)
if buttons then bgb:buttons(common.create_buttons(buttons, o))
local btns = {}
for kb, b in ipairs(buttons) do
-- Create a proxy button object: it will receive the real
-- press and release events, and will propagate them the the
-- button object the user provided, but with the object as
-- argument.
local btn = capi.button { modifiers = b.modifiers, button = b.button }
btn:connect_signal("press", function () b:emit_signal("press", o) end)
btn:connect_signal("release", function () b:emit_signal("release", o) end)
btns[#btns + 1] = btn
end
bgb:buttons(btns)
end
data[o] = { data[o] = {
ib = ib, ib = ib,

View File

@ -100,7 +100,7 @@ function taglist.taglist_label(t, args)
return text, bg_color, bg_image, icon return text, bg_color, bg_image, icon
end end
local function taglist_update(s, w, buttons, filter, data, style) local function taglist_update(s, w, buttons, filter, data, style, update_function)
local tags = {} local tags = {}
for k, t in ipairs(tag.gettags(s)) do for k, t in ipairs(tag.gettags(s)) do
if not tag.getproperty(t, "hide") and filter(t) then if not tag.getproperty(t, "hide") and filter(t) then
@ -110,7 +110,7 @@ local function taglist_update(s, w, buttons, filter, data, style)
local function label(c) return taglist.taglist_label(c, style) end local function label(c) return taglist.taglist_label(c, style) end
common.list_update(w, buttons, label, data, tags) update_function(w, buttons, label, data, tags)
end end
--- Get the tag object the given widget appears on. --- Get the tag object the given widget appears on.
@ -120,11 +120,20 @@ function taglist.gettag(widget)
return common.tagwidgets[widget] return common.tagwidgets[widget]
end end
--- Create a new taglist widget. --- Create a new taglist widget. The last two arguments (update_function
-- and base_widget) serve to customize the layout of the taglist (eg. to
-- make it vertical). For that, you will need to copy the
-- awful.widget.common.list_update function, make your changes to it
-- and pass it as update_function here. Also change the base_widget if the
-- default is not what you want.
-- @param screen The screen to draw taglist for. -- @param screen The screen to draw taglist for.
-- @param filter Filter function to define what clients will be listed. -- @param filter Filter function to define what clients will be listed.
-- @param buttons A table with buttons binding to set. -- @param buttons A table with buttons binding to set.
-- @param style The style overrides default theme. -- @param style The style overrides default theme.
-- @param update_function Optional function to create a tag widget on each
-- update. @see awful.widget.common.
-- @param base_widget Optional container widget for tag widgets. Default
-- is wibox.layout.fixed.horizontal().
-- bg_focus The background color for focused client. -- bg_focus The background color for focused client.
-- fg_focus The foreground color for focused client. -- fg_focus The foreground color for focused client.
-- bg_urgent The background color for urgent clients. -- bg_urgent The background color for urgent clients.
@ -133,13 +142,14 @@ end
-- squares_unsel Optional: a user provided image for unselected squares. -- squares_unsel Optional: a user provided image for unselected squares.
-- squares_resize Optional: true or false to resize squares. -- squares_resize Optional: true or false to resize squares.
-- font The font. -- font The font.
function taglist.new(screen, filter, buttons, style) function taglist.new(screen, filter, buttons, style, update_function, base_widget)
local w = fixed.horizontal() local uf = update_function or common.list_update
local w = base_widget or fixed.horizontal()
local data = setmetatable({}, { __mode = 'k' }) local data = setmetatable({}, { __mode = 'k' })
local u = function (s) local u = function (s)
if s == screen then if s == screen then
taglist_update(s, w, buttons, filter, data, style) taglist_update(s, w, buttons, filter, data, style, uf)
end end
end end
local uc = function (c) return u(c.screen) end local uc = function (c) return u(c.screen) end

View File

@ -78,7 +78,7 @@ local function tasklist_label(c, args)
return text, bg, nil, c.icon return text, bg, nil, c.icon
end end
local function tasklist_update(s, w, buttons, filter, data, style) local function tasklist_update(s, w, buttons, filter, data, style, update_function)
local clients = {} local clients = {}
for k, c in ipairs(capi.client.get()) do for k, c in ipairs(capi.client.get()) do
if not (c.skip_taskbar or c.hidden if not (c.skip_taskbar or c.hidden
@ -90,14 +90,23 @@ local function tasklist_update(s, w, buttons, filter, data, style)
local function label(c) return tasklist_label(c, style) end local function label(c) return tasklist_label(c, style) end
common.list_update(w, buttons, label, data, clients) update_function(w, buttons, label, data, clients)
end end
--- Create a new tasklist widget. --- Create a new tasklist widget. The last two arguments (update_function
-- and base_widget) serve to customize the layout of the tasklist (eg. to
-- make it vertical). For that, you will need to copy the
-- awful.widget.common.list_update function, make your changes to it
-- and pass it as update_function here. Also change the base_widget if the
-- default is not what you want.
-- @param screen The screen to draw tasklist for. -- @param screen The screen to draw tasklist for.
-- @param filter Filter function to define what clients will be listed. -- @param filter Filter function to define what clients will be listed.
-- @param buttons A table with buttons binding to set. -- @param buttons A table with buttons binding to set.
-- @param style The style overrides default theme. -- @param style The style overrides default theme.
-- @param update_function Optional function to create a tag widget on each
-- update. @see awful.widget.common.
-- @param base_widget Optional container widget for tag widgets. Default
-- is wibox.layout.flex.horizontal().
-- bg_normal The background color for unfocused client. -- bg_normal The background color for unfocused client.
-- fg_normal The foreground color for unfocused client. -- fg_normal The foreground color for unfocused client.
-- bg_focus The background color for focused client. -- bg_focus The background color for focused client.
@ -111,11 +120,12 @@ end
-- maximized_horizontal Symbol to use for clients that have been horizontally maximized. -- maximized_horizontal Symbol to use for clients that have been horizontally maximized.
-- maximized_vertical Symbol to use for clients that have been vertically maximized. -- maximized_vertical Symbol to use for clients that have been vertically maximized.
-- font The font. -- font The font.
function tasklist.new(screen, filter, buttons, style) function tasklist.new(screen, filter, buttons, style, update_function, base_widget)
local w = flex.horizontal() local uf = update_function or common.list_update
local w = base_widget or flex.horizontal()
local data = setmetatable({}, { __mode = 'k' }) local data = setmetatable({}, { __mode = 'k' })
local u = function () tasklist_update(screen, w, buttons, filter, data, style) end local u = function () tasklist_update(screen, w, buttons, filter, data, style, uf) end
tag.attached_connect_signal(screen, "property::selected", u) tag.attached_connect_signal(screen, "property::selected", u)
tag.attached_connect_signal(screen, "property::activated", u) tag.attached_connect_signal(screen, "property::activated", u)
capi.client.connect_signal("property::urgent", u) capi.client.connect_signal("property::urgent", u)