update taglist and tasklist to new widget layouts
Signed-off-by: Lukas Hrazky <lukkash@email.cz> Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
a079ab654d
commit
9a51955279
|
@ -8,48 +8,70 @@
|
||||||
local math = math
|
local math = math
|
||||||
local type = type
|
local type = type
|
||||||
local ipairs = ipairs
|
local ipairs = ipairs
|
||||||
|
local pairs = pairs
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local capi = { widget = widget, button = button }
|
local capi = { widget = widget, button = button }
|
||||||
|
local layout = require("awful.widget.layout")
|
||||||
|
local util = require("awful.util")
|
||||||
|
|
||||||
--- Common widget code
|
local common = {}
|
||||||
module("awful.widget.common")
|
|
||||||
|
|
||||||
-- Private structures
|
-- Private structures
|
||||||
tagwidgets = setmetatable({}, { __mode = 'k' })
|
tagwidgets = setmetatable({}, { __mode = 'k' })
|
||||||
|
|
||||||
function list_update(w, buttons, label, data, widgets, objects)
|
-- Recursively processes a template, replacing the tables representing the icon and
|
||||||
|
-- the title with the widgets ib and tb
|
||||||
|
local function replace_in_template(t, ib, tb)
|
||||||
|
for i, v in ipairs(t) do
|
||||||
|
if type(t[i]) == "table" then
|
||||||
|
if v.item == "icon" then
|
||||||
|
t[i] = ib
|
||||||
|
elseif v.item == "title" then
|
||||||
|
tb.align = v.align or "left"
|
||||||
|
tb:margin(v.margin or {})
|
||||||
|
tb.bg_resize = v.bg_resize or false
|
||||||
|
tb.bg_align = v.bg_align or ""
|
||||||
|
t[i] = tb
|
||||||
|
else
|
||||||
|
replace_in_template(v, ib, tb)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function common.list_update(w, buttons, label, data, template, objects)
|
||||||
-- Hack: if it has been registered as a widget in a wibox,
|
-- Hack: if it has been registered as a widget in a wibox,
|
||||||
-- it's w.len since __len meta does not work on table until Lua 5.2.
|
-- it's w.len since __len meta does not work on table until Lua 5.2.
|
||||||
-- Otherwise it's standard #w.
|
-- Otherwise it's standard #w.
|
||||||
local len = (w.len or #w) / 2
|
local len = (w.len or #w)
|
||||||
-- Add more widgets
|
|
||||||
if len < #objects then
|
|
||||||
for i = len * 2 + 1, #objects * 2, 2 do
|
|
||||||
local ib = capi.widget({ type = "imagebox", align = widgets.imagebox.align })
|
|
||||||
local tb = capi.widget({ type = "textbox", align = widgets.textbox.align })
|
|
||||||
|
|
||||||
w[i] = ib
|
-- Remove excessive widgets
|
||||||
w[i + 1] = tb
|
if len > #objects then
|
||||||
w[i + 1]:margin({ left = widgets.textbox.margin.left, right = widgets.textbox.margin.right })
|
for i = #objects, len do
|
||||||
w[i + 1].bg_resize = widgets.textbox.bg_resize or false
|
|
||||||
w[i + 1].bg_align = widgets.textbox.bg_align or ""
|
|
||||||
|
|
||||||
if type(objects[math.floor(i / 2) + 1]) == "tag" then
|
|
||||||
tagwidgets[ib] = objects[math.floor(i / 2) + 1]
|
|
||||||
tagwidgets[tb] = objects[math.floor(i / 2) + 1]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- Remove widgets
|
|
||||||
elseif len > #objects then
|
|
||||||
for i = #objects * 2 + 1, len * 2, 2 do
|
|
||||||
w[i] = nil
|
w[i] = nil
|
||||||
w[i + 1] = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- update widgets text
|
-- update the widgets, creating them if needed
|
||||||
for k = 1, #objects * 2, 2 do
|
for i, o in ipairs(objects) do
|
||||||
local o = objects[(k + 1) / 2]
|
local ib, tb
|
||||||
|
if w[i] then
|
||||||
|
ib = w[i].icon
|
||||||
|
tb = w[i].title
|
||||||
|
else
|
||||||
|
ib = capi.widget({ type = "imagebox" })
|
||||||
|
tb = capi.widget({ type = "textbox" })
|
||||||
|
w[i] = util.table.clone(template)
|
||||||
|
replace_in_template(w[i], ib, tb)
|
||||||
|
w[i].icon = ib
|
||||||
|
w[i].title = tb
|
||||||
|
|
||||||
|
if type(o) == "tag" then
|
||||||
|
tagwidgets[ib] = o
|
||||||
|
tagwidgets[tb] = o
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if buttons then
|
if buttons then
|
||||||
if not data[o] then
|
if not data[o] then
|
||||||
data[o] = { }
|
data[o] = { }
|
||||||
|
@ -64,24 +86,26 @@ function list_update(w, buttons, label, data, widgets, objects)
|
||||||
data[o][#data[o] + 1] = btn
|
data[o][#data[o] + 1] = btn
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
w[k]:buttons(data[o])
|
ib:buttons(data[o])
|
||||||
w[k + 1]:buttons(data[o])
|
tb:buttons(data[o])
|
||||||
end
|
end
|
||||||
|
|
||||||
local text, bg, bg_image, icon = label(o)
|
local text, bg, bg_image, icon = label(o)
|
||||||
w[k + 1].text, w[k + 1].bg, w[k + 1].bg_image = text, bg, bg_image
|
tb.text, tb.bg, tb.bg_image = text, bg, bg_image
|
||||||
w[k].bg, w[k].image = bg, icon
|
ib.bg, ib.image = bg, icon
|
||||||
if not w[k + 1].text then
|
if not tb.text then
|
||||||
w[k+1].visible = false
|
tb.visible = false
|
||||||
else
|
else
|
||||||
w[k+1].visible = true
|
tb.visible = true
|
||||||
end
|
end
|
||||||
if not w[k].image then
|
if not ib.image then
|
||||||
w[k].visible = false
|
ib.visible = false
|
||||||
else
|
else
|
||||||
w[k].visible = true
|
ib.visible = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return common
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
|
@ -23,89 +23,9 @@ local layout = require("awful.widget.layout")
|
||||||
--- Taglist widget module for awful
|
--- Taglist widget module for awful
|
||||||
module("awful.widget.taglist")
|
module("awful.widget.taglist")
|
||||||
|
|
||||||
label = {}
|
filter = {}
|
||||||
|
|
||||||
local function taglist_update (screen, w, label, buttons, data, widgets)
|
function taglist_label(t, args)
|
||||||
local tags = capi.screen[screen]:tags()
|
|
||||||
local showntags = {}
|
|
||||||
for k, t in ipairs(tags) do
|
|
||||||
if not tag.getproperty(t, "hide") then
|
|
||||||
table.insert(showntags, t)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
common.list_update(w, buttons, label, data, widgets, showntags)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Get the tag object the given widget appears on.
|
|
||||||
-- @param widget The widget the look for.
|
|
||||||
-- @return The tag object.
|
|
||||||
function gettag(widget)
|
|
||||||
return common.tagwidgets[widget]
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Create a new taglist widget.
|
|
||||||
-- @param screen The screen to draw tag list for.
|
|
||||||
-- @param label Label function to use.
|
|
||||||
-- @param buttons A table with buttons binding to set.
|
|
||||||
function new(screen, label, buttons)
|
|
||||||
local w = {
|
|
||||||
layout = layout.horizontal.leftright
|
|
||||||
}
|
|
||||||
local widgets = { }
|
|
||||||
widgets.imagebox = { }
|
|
||||||
widgets.textbox = { ["margin"] = { ["left"] = 0,
|
|
||||||
["right"] = 0},
|
|
||||||
["bg_resize"] = true
|
|
||||||
}
|
|
||||||
local data = setmetatable({}, { __mode = 'k' })
|
|
||||||
local u = function (s)
|
|
||||||
if s == screen then
|
|
||||||
taglist_update(s, w, label, buttons, data, widgets)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local uc = function (c) return u(c.screen) end
|
|
||||||
capi.client.add_signal("focus", uc)
|
|
||||||
capi.client.add_signal("unfocus", uc)
|
|
||||||
tag.attached_add_signal(screen, "property::selected", uc)
|
|
||||||
tag.attached_add_signal(screen, "property::icon", uc)
|
|
||||||
tag.attached_add_signal(screen, "property::hide", uc)
|
|
||||||
tag.attached_add_signal(screen, "property::name", uc)
|
|
||||||
capi.screen[screen]:add_signal("tag::attach", function(screen, tag)
|
|
||||||
u(screen.index)
|
|
||||||
end)
|
|
||||||
capi.screen[screen]:add_signal("tag::detach", function(screen, tag)
|
|
||||||
u(screen.index)
|
|
||||||
end)
|
|
||||||
capi.client.add_signal("new", function(c)
|
|
||||||
c:add_signal("property::urgent", uc)
|
|
||||||
c:add_signal("property::screen", function(c)
|
|
||||||
-- If client change screen, refresh it anyway since we don't from
|
|
||||||
-- which screen it was coming :-)
|
|
||||||
u(screen)
|
|
||||||
end)
|
|
||||||
c:add_signal("tagged", uc)
|
|
||||||
c:add_signal("untagged", uc)
|
|
||||||
end)
|
|
||||||
capi.client.add_signal("unmanage", uc)
|
|
||||||
u(screen)
|
|
||||||
return w
|
|
||||||
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.
|
|
||||||
-- @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.
|
|
||||||
-- squares_sel Optional: a user provided image for selected squares.
|
|
||||||
-- squares_unsel Optional: a user provided image for unselected squares.
|
|
||||||
-- squares_resize Optional: true or false to resize squares.
|
|
||||||
-- @return A string to print, a background color, a background image and a
|
|
||||||
-- background resize value.
|
|
||||||
function label.all(t, args)
|
|
||||||
if not args then args = {} end
|
if not args then args = {} end
|
||||||
local theme = beautiful.get()
|
local theme = beautiful.get()
|
||||||
local fg_focus = args.fg_focus or theme.taglist_fg_focus or theme.fg_focus
|
local fg_focus = args.fg_focus or theme.taglist_fg_focus or theme.fg_focus
|
||||||
|
@ -174,23 +94,124 @@ function label.all(t, args)
|
||||||
return text, bg_color, bg_image, icon
|
return text, bg_color, bg_image, icon
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Return labels for a taglist widget with all *non empty* tags from screen.
|
local function taglist_update(s, w, buttons, filter, data, style, template)
|
||||||
-- It returns the tag name and set a special
|
local tags = {}
|
||||||
-- foreground and background color for selected tags.
|
for k, t in ipairs(capi.screen[s]:tags()) do
|
||||||
-- @param t The tag.
|
if not tag.getproperty(t, "hide") and filter(t) then
|
||||||
-- @param args The arguments table.
|
table.insert(tags, t)
|
||||||
-- 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 label.noempty(t, args)
|
|
||||||
if #t:clients() > 0 or t.selected then
|
|
||||||
return label.all(t, args)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function label(c) return taglist_label(c, style) end
|
||||||
|
|
||||||
|
common.list_update(w, buttons, label, data, template, tags)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Get the tag object the given widget appears on.
|
||||||
|
-- @param widget The widget the look for.
|
||||||
|
-- @return The tag object.
|
||||||
|
function gettag(widget)
|
||||||
|
return common.tagwidgets[widget]
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Create a new taglist widget.
|
||||||
|
-- @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.
|
||||||
|
-- bg_focus The background color for focused client.
|
||||||
|
-- fg_focus The foreground color for focused client.
|
||||||
|
-- bg_urgent The background color for urgent clients.
|
||||||
|
-- fg_urgent The foreground color for urgent clients.
|
||||||
|
-- squares_sel Optional: a user provided image for selected squares.
|
||||||
|
-- squares_unsel Optional: a user provided image for unselected squares.
|
||||||
|
-- squares_resize Optional: true or false to resize squares.
|
||||||
|
-- font The font.
|
||||||
|
-- @param template The template to use for each item.
|
||||||
|
-- The default template:<br/>
|
||||||
|
-- <code>
|
||||||
|
--{<br/>
|
||||||
|
-- {<br/>
|
||||||
|
-- item = "icon"<br/>
|
||||||
|
-- },<br/>
|
||||||
|
-- {<br/>
|
||||||
|
-- item = "title",<br/>
|
||||||
|
-- bg_resize = true,<br/>
|
||||||
|
-- },<br/>
|
||||||
|
-- layout = layout.horizontal.leftright<br/>
|
||||||
|
--}<br/>
|
||||||
|
-- </code>
|
||||||
|
function new(screen, filter, buttons, style, template)
|
||||||
|
local w = {
|
||||||
|
layout = layout.horizontal.leftright
|
||||||
|
}
|
||||||
|
|
||||||
|
template = template or {
|
||||||
|
{
|
||||||
|
item = "icon"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
item = "title",
|
||||||
|
--margin = { left = 2, right = 2 },
|
||||||
|
bg_resize = true,
|
||||||
|
},
|
||||||
|
layout = layout.horizontal.leftright
|
||||||
|
}
|
||||||
|
|
||||||
|
local data = setmetatable({}, { __mode = 'k' })
|
||||||
|
local u = function (s)
|
||||||
|
if s == screen then
|
||||||
|
taglist_update(s, w, buttons, filter, data, style, template)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local uc = function (c) return u(c.screen) end
|
||||||
|
capi.client.add_signal("focus", uc)
|
||||||
|
capi.client.add_signal("unfocus", uc)
|
||||||
|
tag.attached_add_signal(screen, "property::selected", uc)
|
||||||
|
tag.attached_add_signal(screen, "property::icon", uc)
|
||||||
|
tag.attached_add_signal(screen, "property::hide", uc)
|
||||||
|
tag.attached_add_signal(screen, "property::name", uc)
|
||||||
|
capi.screen[screen]:add_signal("tag::attach", function(screen, tag)
|
||||||
|
u(screen.index)
|
||||||
|
end)
|
||||||
|
capi.screen[screen]:add_signal("tag::detach", function(screen, tag)
|
||||||
|
u(screen.index)
|
||||||
|
end)
|
||||||
|
capi.client.add_signal("new", function(c)
|
||||||
|
c:add_signal("property::urgent", uc)
|
||||||
|
c:add_signal("property::screen", function(c)
|
||||||
|
-- If client change screen, refresh it anyway since we don't from
|
||||||
|
-- which screen it was coming :-)
|
||||||
|
u(screen)
|
||||||
|
end)
|
||||||
|
c:add_signal("tagged", uc)
|
||||||
|
c:add_signal("untagged", uc)
|
||||||
|
end)
|
||||||
|
capi.client.add_signal("unmanage", uc)
|
||||||
|
u(screen)
|
||||||
|
return w
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Filtering function to include all nonempty tags on the screen.
|
||||||
|
-- @param t The tag.
|
||||||
|
-- @param screen The screen we are drawing on.
|
||||||
|
-- @return true if t is not empty, else false
|
||||||
|
function filter.noempty(t, args)
|
||||||
|
if #t:clients() > 0 or t.selected then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Filtering function to include all tags on the screen.
|
||||||
|
-- @param t The tag.
|
||||||
|
-- @param screen The screen we are drawing on.
|
||||||
|
-- @return true
|
||||||
|
function filter.all(t, args)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
|
@ -23,64 +23,9 @@ local layout = require("awful.widget.layout")
|
||||||
module("awful.widget.tasklist")
|
module("awful.widget.tasklist")
|
||||||
|
|
||||||
-- Public structures
|
-- Public structures
|
||||||
label = {}
|
filter = {}
|
||||||
|
|
||||||
local function tasklist_update(w, buttons, label, data, widgets)
|
local function tasklist_label(c, args)
|
||||||
local clients = capi.client.get()
|
|
||||||
local shownclients = {}
|
|
||||||
for k, c in ipairs(clients) do
|
|
||||||
if not (c.skip_taskbar or c.hidden
|
|
||||||
or c.type == "splash" or c.type == "dock" or c.type == "desktop") then
|
|
||||||
table.insert(shownclients, c)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
clients = shownclients
|
|
||||||
|
|
||||||
common.list_update(w, buttons, label, data, widgets, clients)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Create a new tasklist widget.
|
|
||||||
-- @param label Label function to use.
|
|
||||||
-- @param buttons A table with buttons binding to set.
|
|
||||||
function new(label, buttons)
|
|
||||||
local w = {
|
|
||||||
layout = layout.horizontal.flex
|
|
||||||
}
|
|
||||||
local widgets = { }
|
|
||||||
widgets.imagebox = { }
|
|
||||||
widgets.textbox = { margin = { left = 2,
|
|
||||||
right = 2 },
|
|
||||||
bg_resize = true,
|
|
||||||
bg_align = "right"
|
|
||||||
}
|
|
||||||
local data = setmetatable({}, { __mode = 'k' })
|
|
||||||
local u = function () tasklist_update(w, buttons, label, data, widgets) end
|
|
||||||
for s = 1, capi.screen.count() do
|
|
||||||
tag.attached_add_signal(s, "property::selected", u)
|
|
||||||
capi.screen[s]:add_signal("tag::attach", u)
|
|
||||||
capi.screen[s]:add_signal("tag::detach", u)
|
|
||||||
end
|
|
||||||
capi.client.add_signal("new", function (c)
|
|
||||||
c:add_signal("property::urgent", u)
|
|
||||||
c:add_signal("property::floating", u)
|
|
||||||
c:add_signal("property::maximized_horizontal", u)
|
|
||||||
c:add_signal("property::maximized_vertical", u)
|
|
||||||
c:add_signal("property::name", u)
|
|
||||||
c:add_signal("property::icon_name", u)
|
|
||||||
c:add_signal("property::skip_taskbar", u)
|
|
||||||
c:add_signal("property::hidden", u)
|
|
||||||
c:add_signal("tagged", u)
|
|
||||||
c:add_signal("untagged", u)
|
|
||||||
end)
|
|
||||||
capi.client.add_signal("unmanage", u)
|
|
||||||
capi.client.add_signal("list", u)
|
|
||||||
capi.client.add_signal("focus", u)
|
|
||||||
capi.client.add_signal("unfocus", u)
|
|
||||||
u()
|
|
||||||
return w
|
|
||||||
end
|
|
||||||
|
|
||||||
local function widget_tasklist_label_common(c, args)
|
|
||||||
if not args then args = {} end
|
if not args then args = {} end
|
||||||
local theme = beautiful.get()
|
local theme = beautiful.get()
|
||||||
local fg_focus = args.fg_focus or theme.tasklist_fg_focus or theme.fg_focus
|
local fg_focus = args.fg_focus or theme.tasklist_fg_focus or theme.fg_focus
|
||||||
|
@ -123,86 +68,152 @@ local function widget_tasklist_label_common(c, args)
|
||||||
return text, bg, status_image, c.icon
|
return text, bg, status_image, c.icon
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Return labels for a tasklist widget with clients from all tags and screen.
|
local function tasklist_update(s, w, buttons, filter, data, style, template)
|
||||||
-- It returns the client name and set a special
|
local clients = {}
|
||||||
-- foreground and background color for focused client.
|
for k, c in ipairs(capi.client.get()) do
|
||||||
-- It also puts a special icon for floating windows.
|
if not (c.skip_taskbar or c.hidden
|
||||||
-- @param c The client.
|
or c.type == "splash" or c.type == "dock" or c.type == "desktop")
|
||||||
-- @param screen The screen we are drawing on.
|
and filter(c, s) then
|
||||||
-- @param args The arguments table.
|
table.insert(clients, c)
|
||||||
-- bg_focus The background color for focused client.
|
end
|
||||||
-- fg_focus The foreground color for focused client.
|
|
||||||
-- bg_urgent The background color for urgent clients.
|
|
||||||
-- fg_urgent The foreground color for urgent clients.
|
|
||||||
-- @return A string to print, a background color and a status image.
|
|
||||||
function label.allscreen(c, screen, args)
|
|
||||||
return widget_tasklist_label_common(c, args)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Return labels for a tasklist widget with clients from all tags.
|
local function label(c) return tasklist_label(c, style) end
|
||||||
-- It returns the client name and set a special
|
|
||||||
-- foreground and background color for focused client.
|
common.list_update(w, buttons, label, data, template, clients)
|
||||||
-- It also puts a special icon for floating windows.
|
|
||||||
-- @param c The client.
|
|
||||||
-- @param screen The screen we are drawing on.
|
|
||||||
-- @param args The arguments table.
|
|
||||||
-- bg_focus The background color for focused client.
|
|
||||||
-- fg_focus The foreground color for focused client.
|
|
||||||
-- bg_urgent The background color for urgent clients.
|
|
||||||
-- fg_urgent The foreground color for urgent clients.
|
|
||||||
-- @return A string to print, a background color and a status image.
|
|
||||||
function label.alltags(c, screen, args)
|
|
||||||
-- Only print client on the same screen as this widget
|
|
||||||
if c.screen ~= screen then return end
|
|
||||||
return widget_tasklist_label_common(c, args)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Return labels for a tasklist widget with clients from currently selected tags.
|
--- Create a new tasklist widget.
|
||||||
-- It returns the client name and set a special
|
-- @param screen The screen to draw tasklist for.
|
||||||
-- foreground and background color for focused client.
|
-- @param filter Filter function to define what clients will be listed.
|
||||||
-- It also puts a special icon for floating windows.
|
-- @param buttons A table with buttons binding to set.
|
||||||
-- @param c The client.
|
-- @param style The style overrides default theme.
|
||||||
-- @param screen The screen we are drawing on.
|
|
||||||
-- @param args The arguments table.
|
|
||||||
-- 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.
|
||||||
-- fg_urgent The foreground color for urgent clients.
|
-- fg_urgent The foreground color for urgent clients.
|
||||||
-- @return A string to print, a background color and a status image.
|
-- bg_minimize The background color for minimized clients.
|
||||||
function label.currenttags(c, screen, args)
|
-- fg_minimize The foreground color for minimized clients.
|
||||||
|
-- floating_icon The icon for flating clients.
|
||||||
|
-- font The font.
|
||||||
|
-- @param template The template to use for each item.
|
||||||
|
-- The default template:<br/>
|
||||||
|
-- <code>
|
||||||
|
-- {<br/>
|
||||||
|
-- {<br/>
|
||||||
|
-- item = "icon"<br/>
|
||||||
|
-- },<br/>
|
||||||
|
-- {<br/>
|
||||||
|
-- {<br/>
|
||||||
|
-- item = "title",<br/>
|
||||||
|
-- margin = { left = 2, right = 2 },<br/>
|
||||||
|
-- bg_resize = true,<br/>
|
||||||
|
-- bg_align = "right"<br/>
|
||||||
|
-- },<br/>
|
||||||
|
-- layout = layout.horizontal.flex<br/>
|
||||||
|
-- },<br/>
|
||||||
|
-- layout = layout.horizontal.leftright<br/>
|
||||||
|
-- }<br/>
|
||||||
|
-- </code>
|
||||||
|
function new(screen, filter, buttons, style, template)
|
||||||
|
local w = {
|
||||||
|
layout = layout.horizontal.flex
|
||||||
|
}
|
||||||
|
template = template or {
|
||||||
|
{
|
||||||
|
item = "icon"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{
|
||||||
|
item = "title",
|
||||||
|
margin = { left = 2, right = 2 },
|
||||||
|
bg_resize = true,
|
||||||
|
bg_align = "right"
|
||||||
|
},
|
||||||
|
layout = layout.horizontal.flex
|
||||||
|
},
|
||||||
|
layout = layout.horizontal.leftright
|
||||||
|
}
|
||||||
|
|
||||||
|
local data = setmetatable({}, { __mode = 'k' })
|
||||||
|
local u = function () tasklist_update(screen, w, buttons, filter, data, style, template) end
|
||||||
|
for s = 1, capi.screen.count() do
|
||||||
|
tag.attached_add_signal(s, "property::filtered", u)
|
||||||
|
capi.screen[s]:add_signal("tag::attach", u)
|
||||||
|
capi.screen[s]:add_signal("tag::detach", u)
|
||||||
|
capi.screen[s]:add_signal("tag::history::update", u)
|
||||||
|
end
|
||||||
|
capi.client.add_signal("new", function (c)
|
||||||
|
c:add_signal("property::urgent", u)
|
||||||
|
c:add_signal("property::floating", u)
|
||||||
|
c:add_signal("property::maximized_horizontal", u)
|
||||||
|
c:add_signal("property::maximized_vertical", u)
|
||||||
|
c:add_signal("property::name", u)
|
||||||
|
c:add_signal("property::icon_name", u)
|
||||||
|
c:add_signal("property::skip_taskbar", u)
|
||||||
|
c:add_signal("property::hidden", u)
|
||||||
|
c:add_signal("tagged", u)
|
||||||
|
c:add_signal("untagged", u)
|
||||||
|
end)
|
||||||
|
capi.client.add_signal("unmanage", u)
|
||||||
|
capi.client.add_signal("list", u)
|
||||||
|
capi.client.add_signal("focus", u)
|
||||||
|
capi.client.add_signal("unfocus", u)
|
||||||
|
u()
|
||||||
|
return w
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Filtering function to include all clients.
|
||||||
|
-- @param c The client.
|
||||||
|
-- @param screen The screen we are drawing on.
|
||||||
|
-- @return true
|
||||||
|
function filter.allscreen(c, screen)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Filtering function to include the clients from all tags on the screen.
|
||||||
|
-- @param c The client.
|
||||||
|
-- @param screen The screen we are drawing on.
|
||||||
|
-- @return true if c is on screen, false otherwise
|
||||||
|
function filter.alltags(c, screen)
|
||||||
-- Only print client on the same screen as this widget
|
-- Only print client on the same screen as this widget
|
||||||
if c.screen ~= screen then return end
|
if c.screen ~= screen then return false end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Filtering function to include only the clients from currently selected tags.
|
||||||
|
-- @param c The client.
|
||||||
|
-- @param screen The screen we are drawing on.
|
||||||
|
-- @return true if c is in a selected tag on screen, false otherwise
|
||||||
|
function filter.currenttags(c, screen)
|
||||||
|
-- Only print client on the same screen as this widget
|
||||||
|
if c.screen ~= screen then return false end
|
||||||
-- Include sticky client too
|
-- Include sticky client too
|
||||||
if c.sticky then return widget_tasklist_label_common(c, args) end
|
if c.sticky then return true end
|
||||||
for k, t in ipairs(capi.screen[screen]:tags()) do
|
tags = capi.screen[screen]:tags()
|
||||||
|
for k, t in ipairs(tags) do
|
||||||
if t.selected then
|
if t.selected then
|
||||||
local ctags = c:tags()
|
local ctags = c:tags()
|
||||||
for _, v in ipairs(ctags) do
|
for _, v in ipairs(ctags) do
|
||||||
if v == t then
|
if v == t then
|
||||||
return widget_tasklist_label_common(c, args)
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Return label for only the currently focused client.
|
--- Filtering function to include only the currently focused client.
|
||||||
-- It returns the client name and set a special
|
|
||||||
-- foreground and background color for focused client.
|
|
||||||
-- It also puts a special icon for floating windows.
|
|
||||||
-- @param c The client.
|
-- @param c The client.
|
||||||
-- @param screen The screen we are drawing on.
|
-- @param screen The screen we are drawing on.
|
||||||
-- @param args The arguments table.
|
-- @return true if c is focused on screen, false otherwise
|
||||||
-- bg_focus The background color for focused client.
|
function filter.focused(c, screen)
|
||||||
-- fg_focus The foreground color for focused client.
|
|
||||||
-- bg_urgent The background color for urgent clients.
|
|
||||||
-- fg_urgent The foreground color for urgent clients.
|
|
||||||
-- @return A string to print, a background color and a status image.
|
|
||||||
function label.focused(c, screen, args)
|
|
||||||
-- Only print client on the same screen as this widget
|
-- Only print client on the same screen as this widget
|
||||||
if c.screen == screen and capi.client.focus == c then
|
if c.screen == screen and capi.client.focus == c then
|
||||||
return widget_tasklist_label_common(c, args)
|
return true
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
||||||
|
|
Loading…
Reference in New Issue