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 = { local desktop = {
Tagger = require("desktop.tagger"), Tagger = require("desktop.tagger"),
LayoutManager = require("desktop.layoutmanager"), LayoutManager = require("desktop.layoutmanager"),
Shortcut = require("desktop.widgets.shortcut"),
popup = { popup = {
language = require("desktop.popups.language") language = require("desktop.popups.language")
@ -11,7 +13,6 @@ local desktop = {
textclock = require("desktop.widgets.textclock"), textclock = require("desktop.widgets.textclock"),
keymap = require("desktop.widgets.keymap"), keymap = require("desktop.widgets.keymap"),
launcher = require("desktop.widgets.launcher"), launcher = require("desktop.widgets.launcher"),
shortcut = require("desktop.widgets.shortcut"),
--mdadm = require("desktop.widgets.mdadm"), --mdadm = require("desktop.widgets.mdadm"),
--winstat = require("desktop.widgets.window_status"), --winstat = require("desktop.widgets.window_status"),
@ -127,7 +128,7 @@ awful.screen.connect_for_each_screen(
desktop.widgets.space(6) desktop.widgets.space(6)
} }
for k, v in pairs(conf.bar_shortcuts) do 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
end end

View File

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