This repository has been archived by the owner on Aug 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
quicklaunch.lua
144 lines (121 loc) · 3.84 KB
/
quicklaunch.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
--[[
Quicklaunchbar for awesomeWM
--]]
-- local captures
local awful = require("awful")
local wibox = require("wibox")
local spawn = awful.spawn or awful.util.spawn
------------------------------------------
-- Private utility functions
------------------------------------------
local function table_empty(tab)
for k, v in pairs(tab) do return false end
return true
end
local function table_lookup_key(tab, lookup)
local ret = {}
for k, v in pairs(tab) do ret[lookup[k] or k] = v end
return ret
end
local function make_action(action)
if type(action) == "string" or type(action) == "table" then
return function() spawn(action) end
elseif type(action) == "function" then
return function() action() end -- don't forward arguments!
end
end
------------------------------------------
-- Quicklaunch module
------------------------------------------
local quicklaunch = {}
-- some defaults:
quicklaunch.height = 24
quicklaunch.icon_path = {
os.getenv("XDG_DATA_HOME") .. "/icons",
os.getenv("HOME") .. "/.icons",
os.getenv("HOME") .. "/.local/share/icons",
"/usr/share/icons/hicolor/24x24/apps",
"/usr/share/icons/hicolor/24x24/mimetypes",
"/usr/share/icons/gnome/24x24/apps",
"/usr/share/pixmaps",
"/usr/share/icons/hicolor/32x32/apps",
"/usr/share/icons/hicolor/32x32/mimetypes",
"/usr/share/icons/hicolor/48x48/apps",
"/usr/share/icons/hicolor/48x48/mimetypes",
"/usr/share/icons/hicolor/64x64/apps",
"/usr/share/icons/hicolor/64x64/mimetypes",
"/usr/share/icons/gnome/48x48/apps",
"/usr/share/icons/hicolor/scalable/apps",
}
quicklaunch.separator = wibox.widget.textbox()
quicklaunch.separator:set_markup('<span color="red"> | </span>')
-- manage globally: at most one menu for all controls
function menu_visible(menu)
if quicklaunch.menu and quicklaunch.menu ~= menu then
quicklaunch.menu:hide()
quicklaunch.menu = nil
end
if menu.wibox.visible then
quicklaunch.menu = menu
end
end
-- module definition
function quicklaunch:bar(items)
local launchbar = wibox.layout.fixed.horizontal()
for _, args in ipairs(items) do
if table_empty(args)
then launchbar:add(self.separator)
else launchbar:add(self:wrap(self:widget(args)))
end
end
return launchbar
end
function quicklaunch:wrap(widget)
return wibox.layout {
nil, wibox.container.constraint(widget, "exact", nil, self.height), nil,
expand = "outside",
layout = wibox.layout.align.vertical,
}
end
function quicklaunch:widget(args)
local args = table_lookup_key(args, {'tooltip', 'image', 'action', 'menu'})
args.image = self:find_icon(args.image)
-- uninstalling an application shouldn't break your awesome:
if not args.image then
return
end
local widget = awful.widget.button(args)
local lclick, rclick
if args.menu then
local menu = awful.menu( args.menu )
rclick = function() menu:toggle() end
lclick = rclick
menu.wibox:connect_signal("property::visible", function()
menu_visible(menu)
end)
end
if args.action then
lclick = make_action(args.action)
end
if args.tooltip then
awful.tooltip({ objects={ widget } }):set_text(args.tooltip)
end
widget:buttons(awful.util.table.join(widget:buttons(),
lclick and awful.button({}, 1, nil, lclick),
rclick and awful.button({}, 3, nil, rclick)
))
return widget
end
function quicklaunch:find_icon(filename)
if awful.util.file_readable(filename) then
return filename
end
for _, path in ipairs(self.icon_path) do
local fullpath = path .. "/" .. filename
if awful.util.file_readable(fullpath) then
return fullpath
end
end
return nil
end
return quicklaunch