Cleaned up shortcut code

master
Mark 2022-04-29 11:07:15 -07:00
parent 40c26c2d7e
commit 6c2443a79c
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
2 changed files with 20 additions and 12 deletions

View File

@ -1,6 +1,8 @@
local desktop = {
Tagger = require("desktop.tagger"),
LayoutManager = require("desktop.layoutmanager"),
Shortcut = require("desktop.widgets.shortcut"),
popup = {
language = require("desktop.popups.language")
@ -11,7 +13,6 @@ local desktop = {
textclock = require("desktop.widgets.textclock"),
keymap = require("desktop.widgets.keymap"),
launcher = require("desktop.widgets.launcher"),
shortcut = require("desktop.widgets.shortcut"),
--mdadm = require("desktop.widgets.mdadm"),
--winstat = require("desktop.widgets.window_status"),
@ -127,7 +128,7 @@ awful.screen.connect_for_each_screen(
desktop.widgets.space(6)
}
for k, v in pairs(conf.bar_shortcuts) do
s.shortcuts[#s.shortcuts + 1] = desktop.widgets.shortcut:new(v[1], v[2])
s.shortcuts[#s.shortcuts + 1] = desktop.Shortcut:new{command = v[1], icon = v[2]}.widget
end
end

View File

@ -1,7 +1,14 @@
local shortcuts = {}
local P = {}
P.__index = P
function shortcuts:new(command, icon)
widget = wibox.widget {
function P:new(args)
local s = {
command = args.command,
icon = args.icon
}
setmetatable(s, self)
s.widget = wibox.widget {
{
{ -- Right space
widget = wibox.widget.separator,
@ -11,7 +18,7 @@ function shortcuts:new(command, icon)
{
wibox.widget {
resize = true,
image = conf.app_icon_dir .. icon,
image = conf.app_icon_dir .. s.icon,
widget = wibox.widget.imagebox
},
top = beautiful.dpi(3),
@ -28,24 +35,24 @@ function shortcuts:new(command, icon)
layout = wibox.container.background
}
widget:connect_signal("mouse::enter", function(result)
s.widget:connect_signal("mouse::enter", function(result)
result.bg = beautiful.color.bar.hover_bg
end)
widget:connect_signal("mouse::leave", function(result)
s.widget:connect_signal("mouse::leave", function(result)
result.bg = beautiful.color.transparent
end)
widget:connect_signal("button::press",
s.widget:connect_signal("button::press",
function(_, _, _, button, mods)
if (button == 1) then
awful.spawn(command, false)
awful.spawn(s.command, false)
end
end
)
return widget
return s
end
return shortcuts
return P