{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:
parent
8560de597c
commit
4463f89b15
|
@ -36,6 +36,24 @@ local function replace_in_template(t, ib, tb)
|
|||
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)
|
||||
-- update the widgets, creating them if needed
|
||||
w:reset()
|
||||
|
@ -61,20 +79,7 @@ function common.list_update(w, buttons, label, data, objects)
|
|||
-- And all of this gets a background
|
||||
bgb:set_widget(l)
|
||||
|
||||
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", o) end)
|
||||
btn:connect_signal("release", function () b:emit_signal("release", o) end)
|
||||
btns[#btns + 1] = btn
|
||||
end
|
||||
bgb:buttons(btns)
|
||||
end
|
||||
bgb:buttons(common.create_buttons(buttons, o))
|
||||
|
||||
data[o] = {
|
||||
ib = ib,
|
||||
|
|
|
@ -100,7 +100,7 @@ function taglist.taglist_label(t, args)
|
|||
return text, bg_color, bg_image, icon
|
||||
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 = {}
|
||||
for k, t in ipairs(tag.gettags(s)) do
|
||||
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
|
||||
|
||||
common.list_update(w, buttons, label, data, tags)
|
||||
update_function(w, buttons, label, data, tags)
|
||||
end
|
||||
|
||||
--- Get the tag object the given widget appears on.
|
||||
|
@ -120,11 +120,20 @@ function taglist.gettag(widget)
|
|||
return common.tagwidgets[widget]
|
||||
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 filter Filter function to define what clients will be listed.
|
||||
-- @param buttons A table with buttons binding to set.
|
||||
-- @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.
|
||||
-- fg_focus The foreground color for focused client.
|
||||
-- bg_urgent The background color for urgent clients.
|
||||
|
@ -133,13 +142,14 @@ end
|
|||
-- squares_unsel Optional: a user provided image for unselected squares.
|
||||
-- squares_resize Optional: true or false to resize squares.
|
||||
-- font The font.
|
||||
function taglist.new(screen, filter, buttons, style)
|
||||
local w = fixed.horizontal()
|
||||
function taglist.new(screen, filter, buttons, style, update_function, base_widget)
|
||||
local uf = update_function or common.list_update
|
||||
local w = base_widget or fixed.horizontal()
|
||||
|
||||
local data = setmetatable({}, { __mode = 'k' })
|
||||
local u = function (s)
|
||||
if s == screen then
|
||||
taglist_update(s, w, buttons, filter, data, style)
|
||||
taglist_update(s, w, buttons, filter, data, style, uf)
|
||||
end
|
||||
end
|
||||
local uc = function (c) return u(c.screen) end
|
||||
|
|
|
@ -78,7 +78,7 @@ local function tasklist_label(c, args)
|
|||
return text, bg, nil, c.icon
|
||||
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 = {}
|
||||
for k, c in ipairs(capi.client.get()) do
|
||||
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
|
||||
|
||||
common.list_update(w, buttons, label, data, clients)
|
||||
update_function(w, buttons, label, data, clients)
|
||||
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 filter Filter function to define what clients will be listed.
|
||||
-- @param buttons A table with buttons binding to set.
|
||||
-- @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.
|
||||
-- fg_normal The foreground color for unfocused 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_vertical Symbol to use for clients that have been vertically maximized.
|
||||
-- font The font.
|
||||
function tasklist.new(screen, filter, buttons, style)
|
||||
local w = flex.horizontal()
|
||||
function tasklist.new(screen, filter, buttons, style, update_function, base_widget)
|
||||
local uf = update_function or common.list_update
|
||||
local w = base_widget or flex.horizontal()
|
||||
|
||||
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::activated", u)
|
||||
capi.client.connect_signal("property::urgent", u)
|
||||
|
|
Loading…
Reference in New Issue