-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathawesome-3.5.5-qubes.patch
256 lines (247 loc) · 7.48 KB
/
awesome-3.5.5-qubes.patch
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
commit e9b73c2d92569e244e26b1ab6186e382a3ece816 (HEAD, 3.5-qubes)
Author: Wojciech Zygmunt Porczyk <[email protected]>
Date: Sat Oct 25 16:02:49 2014 +0200
Qubes OS integration
Qubes OS library and changes to default config file.
Signed-off-by: Wojciech Zygmunt Porczyk <[email protected]>
diff --git a/awesomerc.lua.in b/awesomerc.lua.in
index 2cd914a..a72088f 100644
--- a/awesomerc.lua.in
+++ b/awesomerc.lua.in
@@ -11,6 +11,8 @@ local beautiful = require("beautiful")
local naughty = require("naughty")
local menubar = require("menubar")
+local qubes = require("qubes")
+
-- {{{ Error handling
-- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config)
@@ -89,20 +91,11 @@ end
-- {{{ Menu
-- Create a laucher widget and a main menu
-myawesomemenu = {
- { "manual", terminal .. " -e man awesome" },
- { "edit config", editor_cmd .. " " .. awesome.conffile },
- { "restart", awesome.restart },
- { "quit", awesome.quit }
-}
-
-mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
- { "open terminal", terminal }
- }
- })
+mymainmenu = awful.menu({ items = qubes.make_menu(), theme = { width = 300, height = 24 } })
-mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
- menu = mymainmenu })
+mylauncher = awful.widget.launcher({
+ image = '/usr/share/icons/hicolor/16x16/apps/qubes-logo-icon.png',
+ menu = mymainmenu })
-- Menubar configuration
menubar.utils.terminal = terminal -- Set the terminal for applications that require it
@@ -440,6 +433,7 @@ client.connect_signal("manage", function (c, startup)
end
end)
-client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
-client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
+client.connect_signal("focus", function(c) c.border_color = qubes.get_colour_focus(c) end)
+client.connect_signal("unfocus", function(c) c.border_color = qubes.get_colour(c) end)
+client.connect_signal("manage", qubes.manage)
-- }}}
diff --git a/lib/qubes.lua.in b/lib/qubes.lua.in
new file mode 100644
index 0000000..06bb1fe
--- /dev/null
+++ b/lib/qubes.lua.in
@@ -0,0 +1,192 @@
+----------------------------------------------------------------------------
+-- Qubes OS bridge
+-- @copyright 2014 Invisible Things Lab
+-- @copyright 2014 Wojciech Porczyk <[email protected]>
+-- license: GPL-2+
+----------------------------------------------------------------------------
+
+local io = io
+local math = math
+local string = string
+local tonumber = tonumber
+local table = table
+
+local client = require('awful.client')
+local util = require('awful.util')
+local color = require('gears.color')
+local beautiful = require('beautiful')
+
+local qubes = {}
+
+-- the following three functions are lifted from
+-- /usr/lib64/python2.7/colorsys.py
+
+-- XXX this belongs to /usr/share/awesome/lib/gears/colors.lua
+
+local function rgb_to_hls(r, g, b)
+ maxc = math.max(r, g, b)
+ minc = math.min(r, g, b)
+ -- XXX Can optimize (maxc+minc) and (maxc-minc)
+ l = (minc+maxc)/2.0
+ if minc == maxc then
+ return 0.0, l, 0.0
+ end
+ if l <= 0.5 then
+ s = (maxc-minc) / (maxc+minc)
+ else
+ s = (maxc-minc) / (2.0-maxc-minc)
+ end
+ rc = (maxc-r) / (maxc-minc)
+ gc = (maxc-g) / (maxc-minc)
+ bc = (maxc-b) / (maxc-minc)
+ if r == maxc then
+ h = bc-gc
+ elseif g == maxc then
+ h = 2.0+rc-bc
+ else
+ h = 4.0+gc-rc
+ end
+ h = (h/6.0) % 1.0
+ return h, l, s
+end
+
+local function v(m1, m2, hue)
+ hue = hue % 1.0
+ if hue < 1/6 then
+ return m1 + (m2-m1)*hue*6.0
+ end
+ if hue < 0.5 then
+ return m2
+ end
+ if hue < 2/3 then
+ return m1 + (m2-m1)*(2/3-hue)*6.0
+ end
+ return m1
+end
+
+local function hls_to_rgb(h, l, s)
+ if s == 0.0 then
+ return l, l, l
+ end
+ if l <= 0.5 then
+ m2 = l * (1.0+s)
+ else
+ m2 = l+s-(l*s)
+ end
+ m1 = 2.0*l - m2
+ return v(m1, m2, h+1/3), v(m1, m2, h), v(m1, m2, h-1/3)
+end
+
+-- end of codelifting
+
+local function parse_desktop_file(desktop)
+ local entry = {}
+ for line in io.lines(desktop) do
+ key, value = line:match('^(%w+)%s*=%s*(.*)$')
+ if key ~= nil then
+ entry[key] = value
+ end
+ end
+ return entry
+end
+
+local function shift_luminance(colour, factor)
+ local r, g, b = color.parse_color(colour)
+
+ h, l, s = rgb_to_hls(r, g, b)
+ l = math.max(math.min(l * factor, 1), 0)
+ r, g, b = hls_to_rgb(h, l, s)
+
+ return string.format('#%02x%02x%02x', r * 0xff, g * 0xff, b * 0xff)
+end
+
+function qubes.init()
+ -- read labels
+ qubes.labels = { ['*'] = {
+ colour = beautiful.border_normal,
+ colour_focus = beautiful.border_focus
+ } }
+
+ local data = util.pread([[python -c "
+import qubes.qubes
+print(''.join('{}:{}\n'.format(l.index, l.color)
+ for l in qubes.qubes.QubesVmLabels.values()))
+"]])
+ for index, colour in string.gmatch(data, '(%d):0x([0-9a-f]+)') do
+ colour = '#' .. colour
+
+ qubes.labels[index] = { colour = shift_luminance(colour, 0.5),
+ colour_focus = shift_luminance(colour, 1.5) }
+ end
+end
+
+function qubes.manage(c)
+ if client.property.get(c, 'qubes_vmname') ~= nil then return end
+
+ local data = util.pread('xprop -id ' .. c.window
+ .. ' -notype _QUBES_VMNAME _QUBES_LABEL')
+
+ client.property.set(c, 'qubes_vmname',
+ string.match(data, '_QUBES_VMNAME = "(.+)"') or 'dom0')
+ client.property.set(c, 'qubes_label',
+ string.match(data, '_QUBES_LABEL = (%d+)') or '*')
+
+ client.property.set(c, 'prefix',
+ '[' .. client.property.get(c, 'qubes_vmname') .. '] ')
+end
+
+function qubes.get_label(c)
+ if qubes.labels == nil then
+ qubes.init()
+ end
+ local label = client.property.get(c, 'qubes_label')
+ return qubes.labels[label] or qubes.labels['*']
+end
+
+function qubes.get_colour(c)
+ return qubes.get_label(c).colour
+end
+
+function qubes.get_colour_focus(c)
+ return qubes.get_label(c).colour_focus
+end
+
+function qubes.make_vm_menu(vmname, vmpath)
+ local menu = {}
+
+ for desktop in io.popen('ls -1 ' .. vmpath .. '/apps/*.desktop'):lines() do
+ local entry = parse_desktop_file(desktop)
+-- if entry['Icon'] == nil then
+-- entry['Icon'] = vmpath .. '/icon.png'
+-- end
+ table.insert(menu, {entry['Name'], entry['Exec'], entry['Icon']})
+ end
+
+ return {vmname, menu, vmpath .. '/icon.png'}
+end
+
+function qubes.make_menu()
+ local menu = {}
+ for line in io.popen([[python -c "
+import os.path
+import qubes.qubes
+qvmc = qubes.qubes.QubesVmCollection()
+qvmc.lock_db_for_reading()
+qvmc.load()
+qvmc.unlock_db()
+print('\n'.join('{} {}'.format(vm.name, vm.dir_path)
+ for vm in sorted(qvmc.values(), key=lambda vm: vm.name)
+ if os.path.isdir(vm.dir_path)))
+"]]):lines() do
+ local vmname, vmpath = line:match('^(.+) (.+)$')
+ io.stderr:write('line=' .. line .. '\n')
+ table.insert(menu, qubes.make_vm_menu(vmname, vmpath))
+ end
+ table.insert(menu, {'Qubes Manager', 'qubes-manager',
+ '/usr/share/icons/hicolor/16x16/apps/qubes-logo-icon.png'})
+ return menu
+end
+
+return qubes
+
+-- vim: ts=4 sw=4 et