Add application launcher and rewritten window switcher, remove rofi as its no longer needed and replaced by widgets. Fixed a lot of bugs and weird behaviour
This commit is contained in:
@@ -8,264 +8,12 @@ local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gears = require("gears")
|
||||
local wibox = require("wibox")
|
||||
|
||||
local window_elements = require("src.modules.window_switcher.window_elements")()
|
||||
|
||||
return function(s)
|
||||
|
||||
-- Variable to check if client is selected
|
||||
|
||||
local list_update = function(widget, buttons, label, _, objects)
|
||||
widget:reset()
|
||||
|
||||
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
|
||||
{
|
||||
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
|
||||
},
|
||||
{
|
||||
{
|
||||
text = "Application",
|
||||
id = "label",
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
id = "place",
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
widget = wibox.container.place
|
||||
},
|
||||
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),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(12))
|
||||
end,
|
||||
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
|
||||
}
|
||||
|
||||
local function create_buttons(buttons_t, object_t)
|
||||
if buttons_t then
|
||||
local btns = {}
|
||||
for _, b in ipairs(buttons_t) do
|
||||
local btn = awful.button {
|
||||
modifiers = b.modifiers,
|
||||
button = b.button,
|
||||
on_press = function()
|
||||
b:emit_signal('press', object_t)
|
||||
end,
|
||||
on_release = function()
|
||||
b:emit_signal('release', object_t)
|
||||
end
|
||||
}
|
||||
btns[#btns + 1] = btn
|
||||
end
|
||||
return btns
|
||||
end
|
||||
end
|
||||
|
||||
window_element:buttons(create_buttons(buttons, object))
|
||||
local text, _ = label(object, window_element:get_children_by_id("label")[1])
|
||||
|
||||
local i = 1
|
||||
local sel = nil
|
||||
|
||||
local function select_next()
|
||||
if not object.valid then
|
||||
return
|
||||
end
|
||||
if #objects_sorted >= i then
|
||||
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.selected_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.bg
|
||||
end
|
||||
end
|
||||
if #objects_sorted > i then
|
||||
i = i + 1
|
||||
else
|
||||
i = 1
|
||||
end
|
||||
end
|
||||
|
||||
local function raise()
|
||||
if not object.valid then
|
||||
return
|
||||
end
|
||||
if objects_sorted[i] then
|
||||
if sel == object.pid then
|
||||
if not object:isvisible() and object.first_tag then
|
||||
object.first_tag:view_only()
|
||||
end
|
||||
object:emit_signal('request::activate')
|
||||
object:raise()
|
||||
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
|
||||
awesome.disconnect_signal(
|
||||
"window_switcher::select_next",
|
||||
select_next
|
||||
)
|
||||
awesome.disconnect_signal(
|
||||
"window_switcher::raise",
|
||||
raise
|
||||
)
|
||||
end
|
||||
|
||||
awesome.connect_signal(
|
||||
"window_switcher::select_next",
|
||||
select_next
|
||||
)
|
||||
|
||||
awesome.connect_signal(
|
||||
"window_switcher::raise",
|
||||
raise
|
||||
)
|
||||
|
||||
|
||||
object:connect_signal(
|
||||
"unmanage",
|
||||
function(c)
|
||||
if object.valid then
|
||||
i = 1
|
||||
objects_sorted[1] = objects_sorted[#objects_sorted]
|
||||
objects_sorted[#objects_sorted] = nil
|
||||
for _, obj in ipairs(objects_sorted) do
|
||||
if obj.valid then
|
||||
if obj.pid == c.pid then
|
||||
table.remove(objects_sorted, _)
|
||||
break
|
||||
end
|
||||
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(20))
|
||||
end
|
||||
return widget
|
||||
end
|
||||
|
||||
local window_switcher = awful.widget.tasklist(
|
||||
s,
|
||||
awful.widget.tasklist.source.all_clients,
|
||||
awful.util.table.join(
|
||||
awful.button(
|
||||
{},
|
||||
1,
|
||||
function(c)
|
||||
if c == client.focus then
|
||||
c.minimized = true
|
||||
else
|
||||
c.minimized = false
|
||||
if not c:isvisible() and c.first_tag then
|
||||
c.first_tag:view_only()
|
||||
end
|
||||
c:emit_signal('request::activate')
|
||||
c:raise()
|
||||
end
|
||||
end
|
||||
)
|
||||
),
|
||||
{},
|
||||
list_update,
|
||||
wibox.layout.fixed.horizontal()
|
||||
)
|
||||
|
||||
local window_switcher_margin = wibox.widget {
|
||||
window_switcher,
|
||||
local window_switcher_list = wibox.widget {
|
||||
window_elements,
|
||||
margins = dpi(20),
|
||||
widget = wibox.container.margin
|
||||
}
|
||||
@@ -285,6 +33,11 @@ return function(s)
|
||||
border_width = Theme_config.window_switcher.border_width
|
||||
}
|
||||
|
||||
window_switcher_container:setup {
|
||||
window_switcher_list,
|
||||
layout = wibox.layout.fixed.vertical
|
||||
}
|
||||
|
||||
awesome.connect_signal(
|
||||
"toggle_window_switcher",
|
||||
function()
|
||||
@@ -293,9 +46,4 @@ return function(s)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
window_switcher_container:setup {
|
||||
window_switcher_margin,
|
||||
layout = wibox.layout.fixed.vertical
|
||||
}
|
||||
end
|
||||
|
||||
179
awesome/src/modules/window_switcher/window_elements.lua
Normal file
179
awesome/src/modules/window_switcher/window_elements.lua
Normal file
@@ -0,0 +1,179 @@
|
||||
---------------------------------
|
||||
-- This is the window_switcher --
|
||||
---------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gears = require("gears")
|
||||
local wibox = require("wibox")
|
||||
|
||||
return function()
|
||||
|
||||
local elements = wibox.widget {
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
spacing = dpi(20),
|
||||
id = "switcher"
|
||||
}
|
||||
|
||||
local selected = 0
|
||||
|
||||
local function create_elements(fn)
|
||||
fn = fn or ""
|
||||
|
||||
elements:reset()
|
||||
|
||||
local clients = client.get()
|
||||
local clients_sorted = {}
|
||||
|
||||
if client.focus then
|
||||
clients_sorted[1] = client.focus
|
||||
end
|
||||
|
||||
for _, client in ipairs(clients) do
|
||||
if client ~= clients_sorted[1] then
|
||||
table.insert(clients_sorted, client)
|
||||
end
|
||||
end
|
||||
|
||||
selected = selected
|
||||
|
||||
for i, client in ipairs(clients_sorted) do
|
||||
local window_element = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{ -- Icon
|
||||
{
|
||||
id = "icon",
|
||||
--!ADD FALLBACK ICON!--
|
||||
image = xdg_icon_lookup:find_icon(client.class, 64) or client.icon,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
widget = wibox.widget.imagebox
|
||||
},
|
||||
width = dpi(100),
|
||||
height = dpi(100),
|
||||
id = "icon_const",
|
||||
strategy = "exact",
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
{
|
||||
{
|
||||
text = client.name,
|
||||
id = "label",
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
id = "place",
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
widget = wibox.container.place
|
||||
},
|
||||
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),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(12))
|
||||
end,
|
||||
border_color = Theme_config.window_switcher.border_color,
|
||||
border_width = Theme_config.window_switcher.border_width,
|
||||
bg = Theme_config.window_switcher.element_bg,
|
||||
fg = Theme_config.window_switcher.element_fg,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
if i == selected 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
|
||||
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
|
||||
|
||||
elements:add(window_element)
|
||||
end
|
||||
|
||||
if fn == "next" then
|
||||
if selected >= #clients_sorted then
|
||||
selected = 1
|
||||
else
|
||||
selected = selected + 1
|
||||
end
|
||||
|
||||
for i, element in ipairs(elements.children) do
|
||||
if i == selected then
|
||||
element.border_color = Theme_config.window_switcher.selected_border_color
|
||||
element.fg = Theme_config.window_switcher.selected_fg
|
||||
element.bg = Theme_config.window_switcher.selected_bg
|
||||
else
|
||||
element.border_color = Theme_config.window_switcher.border_color
|
||||
element.fg = Theme_config.window_switcher.element_fg
|
||||
element.bg = Theme_config.window_switcher.bg
|
||||
end
|
||||
end
|
||||
elseif fn == "raise" then
|
||||
local c = clients_sorted[selected]
|
||||
if not c:isvisible() and c.first_tag then
|
||||
c.first_tag:view_only()
|
||||
end
|
||||
c:emit_signal('request::activate')
|
||||
c:raise()
|
||||
|
||||
--reset selected
|
||||
selected = 0
|
||||
end
|
||||
return elements
|
||||
end
|
||||
|
||||
elements = create_elements()
|
||||
|
||||
awesome.connect_signal(
|
||||
"window_switcher::select_next",
|
||||
function()
|
||||
elements = create_elements("next")
|
||||
end
|
||||
)
|
||||
|
||||
awesome.connect_signal(
|
||||
"window_switcher::raise",
|
||||
function()
|
||||
elements = create_elements("raise")
|
||||
end
|
||||
)
|
||||
|
||||
client.connect_signal(
|
||||
"manage",
|
||||
function()
|
||||
elements = create_elements()
|
||||
end
|
||||
)
|
||||
|
||||
client.connect_signal(
|
||||
"unmanage",
|
||||
function()
|
||||
elements = create_elements()
|
||||
end
|
||||
)
|
||||
|
||||
awesome.connect_signal(
|
||||
"window_switcher::update",
|
||||
function()
|
||||
elements = create_elements()
|
||||
end
|
||||
)
|
||||
|
||||
return elements
|
||||
end
|
||||
Reference in New Issue
Block a user