widget.common: Add custom sources for the taglist and tasklist.

The current taglist/tasklist allow filter function to remove elements
from the list. However they don't allow sorting or additional entries
to be listed.

This commit introduced such a concept. It will later be used by the
layoutlist where it becomes more relevant since layouts are used created
"objects".
This commit is contained in:
Emmanuel Lepage Vallee 2018-08-18 16:30:15 -04:00
parent 3fe5798a97
commit 96bbbc82f3
2 changed files with 35 additions and 4 deletions

View File

@ -61,7 +61,7 @@ local function get_screen(s)
end
local taglist = { mt = {} }
taglist.filter = {}
taglist.filter, taglist.source = {}, {}
--- The tag list main foreground (text) color.
-- @beautiful beautiful.taglist_fg_focus
@ -386,7 +386,11 @@ end
local function taglist_update(s, w, buttons, filter, data, style, update_function, args)
local tags = {}
for _, t in ipairs(s.tags) do
local source = args and args.source or taglist.source.for_screen or nil
local list = source and source(s, args) or s.tags
for _, t in ipairs(list) do
if not tag.getproperty(t, "hide") and filter(t) then
table.insert(tags, t)
end
@ -411,6 +415,8 @@ end
-- update. See `awful.widget.common`.
-- @tparam[opt] widget args.layout Optional layout widget for tag widgets. Default
-- is wibox.layout.fixed.horizontal().
-- @tparam[opt=awful.taglist.source.for_screen] function args.source The
-- function used to generate the list of tag.
-- @tparam[opt] table args.widget_template A custom widget to be used for each tag
-- @tparam[opt={}] table args.style The style overrides default theme.
-- @tparam[opt=nil] string|pattern args.style.fg_focus
@ -570,6 +576,16 @@ function taglist.filter.all()
return true
end
--- All tags for the defined screen ordered by indices.
--
-- This is the default source.
--
-- @sourcefunction awful.taglist.source.for_screen
-- @see screen
function taglist.source.for_screen(s)
return s.tags
end
function taglist.mt:__call(...)
return taglist.new(...)
end

View File

@ -245,7 +245,7 @@ local instances
-- @see gears.color
-- Public structures
tasklist.filter = {}
tasklist.filter, tasklist.source = {}, {}
local function tasklist_label(c, args, tb)
if not args then args = {} end
@ -401,7 +401,11 @@ end
local function tasklist_update(s, w, buttons, filter, data, style, update_function, args)
local clients = {}
for _, c in ipairs(capi.client.get()) do
local source = args and args.source or tasklist.source.all_clients or nil
local list = source and source(s, args) or capi.client.get()
for _, c in ipairs(list) do
if not (c.skip_taskbar or c.hidden
or c.type == "splash" or c.type == "dock" or c.type == "desktop")
and filter(c, s) then
@ -430,6 +434,8 @@ end
-- update. See `awful.widget.common.list_update`.
-- @tparam[opt] table args.layout Container widget for tag widgets. Default
-- is `wibox.layout.flex.horizontal`.
-- @tparam[opt=awful.tasklist.source.all_clients] function args.source The
-- function used to generate the list of client.
-- @tparam[opt] table args.widget_template A custom widget to be used for each client
-- @tparam[opt={}] table args.style The style overrides default theme.
-- @tparam[opt=nil] string|pattern args.style.fg_normal
@ -677,6 +683,15 @@ function tasklist.filter.focused(c, screen)
return get_screen(c.screen) == get_screen(screen) and capi.client.focus == c
end
--- Get all the clients in an undefined order.
--
-- This is the default source.
--
-- @sourcefunction awful.tasklist.source.all_clients
function tasklist.source.all_clients()
return capi.client.get()
end
function tasklist.mt:__call(...)
return tasklist.new(...)
end