2023-05-08 13:35:23 +02:00
|
|
|
-- ████████╗ █████╗ ███████╗██╗ ██╗ ██╗ ██╗███████╗████████╗
|
|
|
|
-- ╚══██╔══╝██╔══██╗██╔════╝██║ ██╔╝ ██║ ██║██╔════╝╚══██╔══╝
|
|
|
|
-- ██║ ███████║███████╗█████╔╝ ██║ ██║███████╗ ██║
|
|
|
|
-- ██║ ██╔══██║╚════██║██╔═██╗ ██║ ██║╚════██║ ██║
|
|
|
|
-- ██║ ██║ ██║███████║██║ ██╗ ███████╗██║███████║ ██║
|
|
|
|
-- ╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚══════╝╚═╝╚══════╝ ╚═╝
|
2022-07-19 19:45:11 +02:00
|
|
|
|
|
|
|
-- ===================================================================
|
|
|
|
-- Initialization
|
|
|
|
-- ===================================================================
|
|
|
|
|
|
|
|
|
|
|
|
local awful = require('awful')
|
|
|
|
local wibox = require('wibox')
|
|
|
|
local gears = require('gears')
|
2023-06-05 16:22:53 +02:00
|
|
|
local pl = require("utils.powerline")
|
2022-07-22 14:47:26 +02:00
|
|
|
local theme = require("theme")
|
2022-07-19 19:45:11 +02:00
|
|
|
|
|
|
|
local dpi = require('beautiful').xresources.apply_dpi
|
|
|
|
local capi = {button = button}
|
2023-06-05 16:40:17 +02:00
|
|
|
local ICON_DIR = gears.filesystem.get_configuration_dir() .. "/images/"
|
2022-07-19 19:45:11 +02:00
|
|
|
|
|
|
|
-- define module table
|
|
|
|
local task_list = {}
|
|
|
|
|
|
|
|
|
|
|
|
-- ===================================================================
|
|
|
|
-- Functionality
|
|
|
|
-- ===================================================================
|
|
|
|
|
|
|
|
|
|
|
|
local function create_buttons(buttons, object)
|
2022-07-23 19:31:38 +02:00
|
|
|
if buttons then
|
|
|
|
local btns = {}
|
|
|
|
for _, b in ipairs(buttons) do
|
|
|
|
-- Create a proxy button object: it will receive the real
|
|
|
|
-- press and release events, and will propagate them to 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()
|
2023-09-03 12:24:47 +02:00
|
|
|
object.minimized = false
|
|
|
|
object:raise()
|
2022-07-23 19:31:38 +02:00
|
|
|
end
|
|
|
|
)
|
|
|
|
btns[#btns + 1] = btn
|
|
|
|
end
|
|
|
|
return btns
|
|
|
|
end
|
2022-07-19 19:45:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2023-05-20 23:04:33 +02:00
|
|
|
local function list_update(w, buttons, label, _, objects)
|
2022-07-23 19:31:38 +02:00
|
|
|
-- update the widgets, creating them if needed
|
|
|
|
w:reset()
|
|
|
|
local index = 0
|
|
|
|
local count = 0
|
|
|
|
for _ in pairs(objects) do
|
|
|
|
count = count + 1
|
|
|
|
end
|
2023-05-08 13:35:23 +02:00
|
|
|
local static_length = 16 * count
|
|
|
|
local total_text_length = 0
|
|
|
|
for _, o in ipairs(objects) do
|
2023-05-21 00:35:23 +02:00
|
|
|
if o.name then
|
|
|
|
total_text_length = total_text_length + o.name:len()
|
|
|
|
end
|
2023-05-08 13:35:23 +02:00
|
|
|
end
|
|
|
|
local truncate = (total_text_length + static_length) > 170
|
|
|
|
|
2022-07-23 19:31:38 +02:00
|
|
|
for i, o in ipairs(objects) do
|
|
|
|
index = index + 1
|
|
|
|
local ib, cb, tb, cbm, bgb, tbm, ibm, tt, l, ll
|
|
|
|
ib = wibox.widget.imagebox()
|
|
|
|
tb = wibox.widget.textbox()
|
2023-05-08 13:35:23 +02:00
|
|
|
cb = wibox.container.margin(wibox.widget.imagebox(ICON_DIR .. "close.svg"), dpi(9), dpi(0), dpi(9), dpi(9))
|
2022-07-23 19:31:38 +02:00
|
|
|
cb.shape = gears.shape.circle
|
|
|
|
cbm = wibox.container.margin(cb, dpi(0), dpi(0), dpi(0), dpi(0)) -- 4, 8 ,12 ,12 -- close button
|
|
|
|
cbm:buttons(gears.table.join(awful.button({}, 1, nil,
|
|
|
|
function()
|
|
|
|
o.kill(o)
|
|
|
|
end
|
|
|
|
)))
|
|
|
|
bgb = wibox.container.background()
|
|
|
|
tbm = wibox.container.margin(tb, dpi(4), dpi(4))
|
|
|
|
ibm = wibox.container.margin(ib, dpi(5), dpi(5), dpi(5), dpi(5)) -- 12 is default top and bottom margin --app icon
|
|
|
|
l = wibox.layout.fixed.horizontal()
|
|
|
|
ll = wibox.layout.fixed.horizontal()
|
|
|
|
|
|
|
|
-- All of this is added in a fixed widget
|
|
|
|
l:fill_space(true)
|
|
|
|
l:add(ibm)
|
|
|
|
l:add(tbm)
|
|
|
|
ll:add(l)
|
|
|
|
ll:add(cbm)
|
|
|
|
|
|
|
|
if (index % 2 == 0) then
|
2022-07-25 18:48:49 +02:00
|
|
|
local end_color = (count == index or objects[index+1].minimized) and "" or theme.top_panel_powerline
|
2022-07-25 18:57:14 +02:00
|
|
|
local main_color = o.minimized and "" or theme.bg_normal
|
2022-07-23 19:31:38 +02:00
|
|
|
bgb:set_widget(pl(ll, main_color, end_color, true))
|
|
|
|
else
|
2022-07-25 18:48:49 +02:00
|
|
|
local end_color = (count == index or objects[index+1].minimized) and "" or theme.bg_normal
|
2022-07-25 18:57:14 +02:00
|
|
|
local main_color = o.minimized and "" or theme.top_panel_powerline
|
2022-07-23 19:31:38 +02:00
|
|
|
bgb:set_widget(pl(ll, main_color, end_color, true))
|
|
|
|
end
|
|
|
|
|
|
|
|
l:buttons(create_buttons(buttons, o))
|
|
|
|
|
|
|
|
-- Tooltip to display whole title, if it was truncated
|
|
|
|
tt = awful.tooltip({
|
|
|
|
objects = {tb},
|
|
|
|
mode = 'outside',
|
|
|
|
align = 'bottom',
|
|
|
|
delay_show = 1,
|
|
|
|
})
|
|
|
|
|
2023-05-20 23:04:33 +02:00
|
|
|
local text, _, bg_image, icon, args = label(o, tb)
|
2022-07-23 19:31:38 +02:00
|
|
|
args = args or {}
|
|
|
|
|
|
|
|
-- The text might be invalid, so use pcall.
|
|
|
|
if text == nil or text == '' then
|
|
|
|
tbm:set_margins(0)
|
|
|
|
else
|
|
|
|
-- truncate when title is too long
|
|
|
|
local text_only = text:match('>(.*)<')
|
2023-05-08 13:35:23 +02:00
|
|
|
local max_length = math.floor((155 - static_length) / count)
|
|
|
|
if (truncate and text_only:len() > max_length) then
|
2023-05-21 01:27:24 +02:00
|
|
|
text = text:gsub('>(.*)<', '>' .. string.sub(text_only, 1, max_length) .. '...<')
|
2023-05-08 13:35:23 +02:00
|
|
|
tt:set_text(text)
|
2022-07-23 19:31:38 +02:00
|
|
|
tt:add_to_object(tb)
|
|
|
|
else
|
|
|
|
tt:remove_from_object(tb)
|
|
|
|
end
|
|
|
|
if not tb:set_markup_silently(text) then
|
|
|
|
tb:set_markup('<i><Invalid text></i>')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- bgb:set_bg(bg)
|
|
|
|
if type(bg_image) == 'function' then
|
|
|
|
-- TODO: Why does this pass nil as an argument?
|
|
|
|
bg_image = bg_image(tb, o, nil, objects, i)
|
|
|
|
end
|
|
|
|
-- bgb:set_bgimage(bg_image)
|
|
|
|
if icon then
|
|
|
|
ib.image = icon
|
|
|
|
else
|
|
|
|
ibm:set_margins(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
w:add(bgb)
|
|
|
|
end
|
2022-07-19 19:45:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- ===================================================================
|
|
|
|
-- Widget Creation
|
|
|
|
-- ===================================================================
|
|
|
|
|
|
|
|
|
|
|
|
local tasklist_buttons = awful.util.table.join(
|
2022-07-23 19:31:38 +02:00
|
|
|
awful.button({}, 1,
|
|
|
|
function(c)
|
|
|
|
if c == client.focus then
|
|
|
|
c.minimized = true
|
|
|
|
else
|
|
|
|
-- Without this, the following
|
|
|
|
-- :isvisible() makes no sense
|
|
|
|
c.minimized = false
|
|
|
|
if not c:isvisible() and c.first_tag then
|
|
|
|
c.first_tag:view_only()
|
|
|
|
end
|
|
|
|
-- This will also un-minimize
|
|
|
|
-- the client, if needed
|
|
|
|
client.focus = c
|
|
|
|
c:raise()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
),
|
|
|
|
awful.button({}, 2,
|
|
|
|
function(c)
|
|
|
|
c.kill(c)
|
|
|
|
end
|
|
|
|
),
|
|
|
|
awful.button({}, 4,
|
|
|
|
function()
|
|
|
|
awful.client.focus.byidx(1)
|
|
|
|
end
|
|
|
|
),
|
|
|
|
awful.button({}, 5,
|
|
|
|
function()
|
|
|
|
awful.client.focus.byidx(-1)
|
|
|
|
end
|
|
|
|
)
|
2022-07-19 19:45:11 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-23 19:13:05 +02:00
|
|
|
local filter = function(c, _)
|
2022-07-23 19:31:38 +02:00
|
|
|
local tags = c.screen.tags
|
|
|
|
for _, t in ipairs(tags) do
|
|
|
|
if t.selected then
|
|
|
|
local ctags = c:tags()
|
|
|
|
for _, v in ipairs(ctags) do
|
2023-05-21 00:35:23 +02:00
|
|
|
if v == t and client.focus and c.screen == client.focus.screen then
|
2022-07-23 19:31:38 +02:00
|
|
|
return true
|
|
|
|
end
|
2022-07-23 19:13:05 +02:00
|
|
|
end
|
2022-07-23 19:31:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
2022-07-23 19:13:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2022-07-19 19:45:11 +02:00
|
|
|
task_list.create = function(s)
|
2022-07-23 19:31:38 +02:00
|
|
|
return awful.widget.tasklist(
|
|
|
|
s,
|
|
|
|
filter,
|
|
|
|
tasklist_buttons,
|
|
|
|
{},
|
|
|
|
list_update,
|
|
|
|
wibox.layout.fixed.horizontal()
|
|
|
|
)
|
2022-07-19 19:45:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return task_list
|