From 6c2443a79c857530d1fc776a3abcab56c41d73c7 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 29 Apr 2022 11:07:15 -0700 Subject: [PATCH] Cleaned up shortcut code --- desktop/init.lua | 5 +++-- desktop/widgets/shortcut.lua | 27 +++++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/desktop/init.lua b/desktop/init.lua index f017f9b..21a124f 100755 --- a/desktop/init.lua +++ b/desktop/init.lua @@ -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 diff --git a/desktop/widgets/shortcut.lua b/desktop/widgets/shortcut.lua index 762ac87..ef84f5a 100644 --- a/desktop/widgets/shortcut.lua +++ b/desktop/widgets/shortcut.lua @@ -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