Add new window switcher on super+tab and smaller fixes

This commit is contained in:
Crylia
2022-06-16 00:30:56 +02:00
parent 454c80336c
commit fb22b50a97
13 changed files with 358 additions and 68 deletions

View File

@@ -4,46 +4,85 @@
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
local naughty = require("naughty")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/window_switcher/"
return function(s)
-- Variable to check if client is selected
local list_update = function(widget, buttons, label, _, objects)
widget:reset()
for _, object in ipairs(objects) do
local function sort_objects()
local objects_sorted = {}
objects_sorted[1] = objects[1]
local index = 2
for _, object in ipairs(objects) do
if object ~= nil or object ~= 0 then
if object == client.focus then
objects_sorted[1] = object
else
objects_sorted[index] = object
index = index + 1
end
end
end
index = 2
if objects_sorted[1].pid == objects_sorted[2].pid then
table.remove(objects_sorted, 2)
end
return objects_sorted
end
local objects_sorted = sort_objects()
local selected = objects_sorted[1].pid
for _, object in ipairs(objects_sorted) do
local window_element = wibox.widget {
{
{
{ -- Icon
{
{ -- Icon
{
id = "icon",
image = object.icon,
valign = "center",
halign = "center",
widget = wibox.widget.imagebox
},
width = dpi(100),
height = dpi(100),
id = "icon_const",
strategy = "exact",
widget = wibox.container.constraint
},
{
id = "icon",
image = object.icon,
{
text = "Application",
id = "label",
widget = wibox.widget.textbox
},
id = "place",
valign = "center",
halign = "center",
widget = wibox.widget.imagebox
widget = wibox.container.place
},
width = dpi(100),
height = dpi(100),
id = "icon_const",
strategy = "exact",
widget = wibox.container.constraint
id = "layout1",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
},
{
text = "Application",
id = "label",
valign = "center",
align = "center",
widget = wibox.widget.textbox
},
id = "layout1",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
id = "box",
width = dpi(150),
height = dpi(150),
strategy = "exact",
widget = wibox.container.constraint
},
id = "margin",
margins = dpi(20),
@@ -52,7 +91,8 @@ return function(s)
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, dpi(12))
end,
bg = Theme_config.window_switcher.element_bg,
border_color = Theme_config.window_switcher.border_color,
border_width = Theme_config.window_switcher.border_width,
fg = Theme_config.window_switcher.element_fg,
widget = wibox.container.background
}
@@ -78,38 +118,122 @@ return function(s)
end
window_element:buttons(create_buttons(buttons, object))
local text, _ = label(object, window_element:get_children_by_id("label")[1])
local text, _ = label(object, window_element.margin.layout1.label)
local i = 1
local sel = nil
if object == client.focus then
if text == nil or text == "" then
window_element:get_children_by_id("label")[1].text = "Application"
else
local text_full = text:match(">(.-)<")
if text_full then
if object.class == nil then
text = object.name
local select_next = function()
if #objects_sorted >= i then
selected = objects_sorted[i].pid
sel = selected
if object.valid then
if selected == object.pid then
window_element.border_color = Theme_config.window_switcher.selected_border_color
window_element.fg = Theme_config.window_switcher.selected_fg
window_element.bg = Theme_config.window_switcher.selected_bg
else
text = object.class:sub(1, 20)
window_element.border_color = Theme_config.window_switcher.border_color
window_element.fg = Theme_config.window_switcher.element_fg
window_element.bg = Theme_config.window_switcher.bg
end
end
window_element:get_children_by_id("label")[1].text = text
end
else
if #objects_sorted > i then
i = i + 1
else
i = 1
end
end
awesome.connect_signal(
"window_switcher::select_next",
select_next
)
object:connect_signal(
"unmanage",
function(c)
i = 1
objects_sorted[1] = objects_sorted[#objects_sorted]
objects_sorted[#objects_sorted] = nil
if objects_sorted[1] then
selected = objects_sorted[1].pid
end
-- remove object from table
for _, object in ipairs(objects) do
if object.pid == c.pid then
table.remove(objects, _)
break
end
end
for _, object in ipairs(objects_sorted) do
if object.pid == c.pid then
table.remove(objects_sorted, _)
break
end
end
end
)
awesome.connect_signal(
"window_switcher::raise",
function()
if objects_sorted[i] then
if object.valid then
if sel == object.pid then
object:jump_to()
end
-- Reset window switcher
i = 1
selected = objects_sorted[i].pid
sel = selected
if selected == object.pid then
window_element.border_color = Theme_config.window_switcher.selected_border_color
window_element.fg = Theme_config.window_switcher.selected_fg
window_element.bg = Theme_config.window_switcher.bg
else
window_element.border_color = Theme_config.window_switcher.border_color
window_element.fg = Theme_config.window_switcher.element_fg
window_element.bg = Theme_config.window_switcher.selected_bg
end
end
end
end
)
if text == nil or text == "" then
window_element:get_children_by_id("label")[1].text = "Application"
else
local text_full = text:match(">(.-)<")
if text_full then
if object.class == nil then
text = object.name
else
text = object.class:sub(1, 20)
end
end
window_element:get_children_by_id("label")[1].text = object.name
end
if selected == object.pid then
window_element.border_color = Theme_config.window_switcher.selected_border_color
window_element.fg = Theme_config.window_switcher.selected_fg
window_element.bg = Theme_config.window_switcher.selected_bg
end
window_element:get_children_by_id("icon")[1]:set_image(xdg_icon_lookup:find_icon(object.class, 64))
widget:add(window_element)
widget:set_spacing(dpi(6))
widget:set_spacing(dpi(20))
end
return widget
end
local window_switcher = awful.widget.tasklist(
s,
awful.widget.tasklist.filter.allscreen,
awful.widget.tasklist.source.all_clients,
awful.util.table.join(
awful.button(
{},
@@ -133,21 +257,36 @@ return function(s)
wibox.layout.fixed.horizontal()
)
local window_switcher_margin = wibox.widget {
window_switcher,
margins = dpi(20),
widget = wibox.container.margin
}
local window_switcher_container = awful.popup {
widget = wibox.container.background,
ontop = true,
visible = false,
stretch = false,
screen = s,
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, dpi(12))
end,
widget = { window_switcher },
placement = awful.placement.centered,
bg = Theme_config.window_switcher.bg,
border_color = Theme_config.window_switcher.border_color,
border_width = Theme_config.window_switcher.border_width
}
awesome.connect_signal(
"toggle_window_switcher",
function()
window_switcher_container.visible = not window_switcher_container.visible
end
)
window_switcher_container:setup {
window_switcher_margin,
layout = wibox.layout.fixed.vertical
}
end