Cleaned up shortcut code
This commit is contained in:
		| @ -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 | ||||
|  | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
		Reference in New Issue
	
	Block a user