author | Fabien Ninoles <fabien@tzone.org> |
Sun, 13 Sep 2015 14:47:26 -0400 | |
changeset 14 | 6348b9f842b2 |
parent 13 | e9e2f624cd99 |
child 15 | 73df43769340 |
permissions | -rw-r--r-- |
12 | 1 |
local os = require("os") |
2 |
local io = require("io") |
|
3 |
local debug = require("debug") |
|
13
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
4 |
local table = require("table") |
12 | 5 |
local awesome = require("awesome") |
11 | 6 |
local naughty = require("naughty") |
7 |
local awful = require("awful") |
|
8 |
local vicious = require("vicious") |
|
9 |
local wicked = require("wicked") |
|
10 |
local beautiful = require("beautiful") |
|
11 |
local timer = require("timer") |
|
12 |
local wibox = require("wibox") |
|
7 | 13 |
|
14 |
local ipairs = ipairs |
|
15 |
local pairs = pairs |
|
16 |
||
17 |
local capi = { |
|
12 | 18 |
keygrabber = require("keygrabber"), |
19 |
client = require("client"), |
|
20 |
string = require("string"), |
|
7 | 21 |
} |
22 |
||
23 |
module("my") |
|
24 |
||
12 | 25 |
--- Stolen from shifty: Shows a popup and logs to a file |
26 |
-- @param message The text message. |
|
14
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
27 |
-- @param log_level 1 = INFO, 2 = WARN, 3 = ERROR, if nothing is provided 1 is used. |
12 | 28 |
function log(message, log_level) |
29 |
if log_level == nil then |
|
30 |
log_level = 1 |
|
31 |
end |
|
32 |
||
33 |
local log_table = { |
|
34 |
{ level = "INFO", bg_colour = "#18F92C", fg_colour = "#0E0E0E" }, |
|
35 |
{ level = "WARN", bg_colour = "#9E731F", fg_colour = "#0E0E0E" }, |
|
36 |
{ level = "ERROR", bg_colour = "#FF0015", fg_colour = "#000000" } |
|
37 |
} |
|
38 |
-- %c eg: Wed Jan 30 14:25:13 2013 |
|
39 |
local time = os.date("%c") |
|
14
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
40 |
message = time .. " - " .. log_table[log_level].level .. " - " .. message .. "\n" |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
41 |
tb = debug.traceback() |
12 | 42 |
|
43 |
local home = os.getenv("HOME") |
|
44 |
local log_file = io.open(home .. "/.awesome.log", "a+") |
|
14
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
45 |
log_file:write(message .. tb .. "\n") |
12 | 46 |
log_file:close() |
47 |
||
48 |
naughty.notify({ preset = naughty.config.presets.critical, text = message, bg = log_table[log_level].bg_colour, fg = log_table[log_level].fg_colour}) |
|
11 | 49 |
end |
50 |
||
7 | 51 |
local in_error = false |
12 | 52 |
function mk_notify_error_dialog(level) |
53 |
return function(msg) |
|
54 |
-- Make sure we don't go into an endless error loop |
|
55 |
if in_error then return end |
|
56 |
in_error = true |
|
7 | 57 |
|
12 | 58 |
log(msg, level) |
59 |
||
60 |
in_error = false |
|
61 |
end |
|
62 |
end |
|
63 |
||
64 |
notify_error = mk_notify_error_dialog(3) |
|
65 |
||
13
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
66 |
local function get_gradient_colors(c1, c2) |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
67 |
return { type = "linear", from = { 0, 0 }, to = { 0, 20 }, stops = { { 0, c2 }, { 1, c1 } }} |
7 | 68 |
end |
69 |
||
70 |
function mkspawn(p) |
|
71 |
return function () awful.util.spawn(p) end |
|
72 |
end |
|
73 |
||
74 |
function setxkbmap(kb) |
|
75 |
XKBDIR="$HOME/.xkb" |
|
76 |
-- Strange bug on xkbcomp: pushing directly the output to the display |
|
77 |
-- lead to an error; We need to convert it first to .xkb and then feed |
|
78 |
-- xkbcomp again for setting the x display |
|
79 |
p = 'setxkbmap "' .. kb .. " -print | xkbcomp -xkb -a -I" .. XKBDIR .. " - - | kxbcomp - $DISPLAY" |
|
80 |
awful.util.spawn_with_shell(p) |
|
81 |
end |
|
82 |
||
83 |
function kill_all(rule) |
|
84 |
for c in awful.client.iterate(rule) do |
|
85 |
c:kill() |
|
86 |
end |
|
87 |
end |
|
88 |
||
89 |
function quit() |
|
12 | 90 |
kill_all(function (c) return true end) |
7 | 91 |
awesome.quit() |
92 |
end |
|
93 |
||
94 |
function show_clients() |
|
95 |
if instance then |
|
96 |
instance:hide() |
|
97 |
instance = nil |
|
98 |
else |
|
99 |
instance = awful.menu.clients({width=250}) |
|
100 |
end |
|
101 |
end |
|
102 |
||
103 |
local function widgets_cpu() |
|
104 |
local w = awful.widget.graph() |
|
105 |
-- Graph properties |
|
106 |
w:set_width(30) |
|
13
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
107 |
w:set_background_color(beautiful.bg_normal) |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
108 |
w:set_color(get_gradient_colors(beautiful.bg_focus, beautiful.bg_urgent)) |
7 | 109 |
-- Register widget |
110 |
vicious.register(w, vicious.widgets.cpu, "$1", 1) |
|
111 |
return w |
|
112 |
end |
|
113 |
||
114 |
local function widgets_mdp() |
|
115 |
-- Initialize widget |
|
11 | 116 |
local w = wibox.widget.textbox() |
7 | 117 |
-- Register widget |
118 |
vicious.register(w, vicious.widgets.mpd, |
|
119 |
function (widget, args) |
|
120 |
if args["{state}"] == "Stop" then |
|
121 |
return " - " |
|
122 |
else |
|
123 |
return args["{Artist}"]..' - '.. args["{Title}"] |
|
124 |
end |
|
125 |
end, 10) |
|
126 |
return w |
|
127 |
end |
|
128 |
||
129 |
local function widgets_mem(monitor) |
|
130 |
-- Initialize widget |
|
131 |
local w = awful.widget.progressbar() |
|
132 |
-- Progressbar properties |
|
133 |
w:set_width(10) |
|
134 |
w:set_vertical(true) |
|
13
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
135 |
w:set_background_color(beautiful.bg_normal) |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
136 |
w:set_color(get_gradient_colors(beautiful.bg_focus, beautiful.bg_urgent)) |
7 | 137 |
-- Register widget |
138 |
vicious.register(w, vicious.widgets.mem, "$1", 5) |
|
139 |
return w |
|
140 |
end |
|
141 |
||
142 |
local function widgets_net(device) |
|
11 | 143 |
local w = wibox.widget.textbox() |
7 | 144 |
-- w:set_vertical(true) |
145 |
w.width = 150 |
|
14
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
146 |
w:set_align('center') |
7 | 147 |
vicious.register(w, wicked.widgets.net, |
14
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
148 |
'<tt>${' .. device .. ' up} â–´ ${' .. device .. ' down} â–¾</tt>', |
7 | 149 |
1) |
150 |
return w |
|
151 |
end |
|
152 |
||
153 |
local function widgets_mode() |
|
12 | 154 |
local bg = wibox.widget.background() |
11 | 155 |
local w = wibox.widget.textbox() |
12 | 156 |
bg:set_widget(w) |
7 | 157 |
widgets.mode_widget = w |
12 | 158 |
widgets.mode_widget_bg = bg |
159 |
return bg |
|
7 | 160 |
end |
161 |
||
162 |
local function widgets_keyboard() |
|
11 | 163 |
local w = wibox.widget.textbox() |
7 | 164 |
widgets.keyboard_widget = w |
165 |
return w |
|
166 |
end |
|
167 |
||
168 |
local function widgets_decorated(w, onclick) |
|
169 |
local wg = w |
|
170 |
if w.widget then |
|
171 |
wg = w.widget |
|
172 |
end |
|
173 |
wg:buttons(awful.util.table.join( |
|
174 |
awful.button({}, 1, onclick))) |
|
175 |
return w |
|
176 |
end |
|
177 |
||
178 |
widgets = { |
|
179 |
cpu = widgets_cpu, |
|
180 |
mem = widgets_mem, |
|
181 |
net = widgets_net, |
|
182 |
mdp = widgets_mdp, |
|
183 |
mode = widgets_mode, |
|
184 |
keyboard = widgets_keyboard, |
|
185 |
decorated = widgets_decorated, |
|
14
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
186 |
|
7 | 187 |
} |
188 |
function make_key(k, n, f) |
|
189 |
return { key = k, name = n, func = f} |
|
190 |
end |
|
191 |
||
14
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
192 |
function make_single_key(k, n, f) |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
193 |
if f == nil then |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
194 |
log("name: " .. n .. " is nil", 3) |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
195 |
end |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
196 |
return make_key(k, n, function (c) f(c); return true ; end) |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
197 |
end |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
198 |
|
7 | 199 |
function show_kt(keytable, title) |
200 |
-- todo: replace with a menu ? |
|
201 |
text = "" |
|
202 |
for _, k in ipairs(keytable) do |
|
203 |
text = text .. "\'" .. k.key .. "\'\t" .. k.name .. "\n" |
|
204 |
end |
|
205 |
naughty.notify({text = text, |
|
206 |
title = title, |
|
207 |
position = "top_left", |
|
208 |
}) |
|
209 |
end |
|
210 |
||
211 |
local keynames = { |
|
212 |
[" "] = "space", |
|
213 |
["\t"] = "tab", |
|
214 |
} |
|
215 |
||
8 | 216 |
local ignored_mods = { |
217 |
["Mod2"] = true, |
|
218 |
} |
|
219 |
||
7 | 220 |
local function translate_key(mod, key) |
221 |
local skey = "" |
|
222 |
for m,v in pairs(mod) do |
|
8 | 223 |
if not ignored_mods[v] then |
7 | 224 |
skey = skey .. v .. "+" |
225 |
end |
|
226 |
end |
|
227 |
skey = skey .. (keynames[key] or key) |
|
228 |
return skey |
|
229 |
end |
|
230 |
||
231 |
local function kt_handler(keytable, mod, key, event) |
|
232 |
if event == "release" then |
|
233 |
return true |
|
234 |
end |
|
13
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
235 |
widgets.mode_widget_bg:set_bg(beautiful.bg_focus) |
7 | 236 |
if key == "Escape" then |
237 |
return false |
|
238 |
end |
|
239 |
local skey = capi.string.lower(translate_key(mod, key)) |
|
240 |
if skey == "control+h" or skey == "shift+?" then |
|
241 |
show_kt(keytable, "Current binding") |
|
242 |
return true |
|
243 |
end |
|
244 |
for _,k in ipairs(keytable) do |
|
245 |
if skey == capi.string.lower(k.key) then |
|
246 |
return k.func(c) |
|
247 |
end |
|
248 |
end |
|
249 |
-- notify_error("Nothing for " .. skey) |
|
13
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
250 |
widgets.mode_widget_bg:set_bg(beautiful.bg_urgent) |
7 | 251 |
return true |
252 |
end |
|
253 |
||
254 |
local function stop_kt() |
|
255 |
capi.keygrabber.stop() |
|
12 | 256 |
widgets.mode_widget:set_text("") |
7 | 257 |
end |
258 |
||
259 |
function mkinteractive(f) |
|
260 |
return function (c) |
|
261 |
stop_kt() |
|
262 |
return f(c) |
|
263 |
end |
|
264 |
end |
|
265 |
||
266 |
||
267 |
-- local is_in_run_kt = false |
|
268 |
function run_kt(c, keytable, title) |
|
12 | 269 |
widgets.mode_widget:set_text("Mode: " .. title) |
270 |
-- widgets.mode_widget:show() |
|
13
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
271 |
widgets.mode_widget_bg:set_bg(beautiful.bg_focus) |
7 | 272 |
widgets.mode_widget:buttons( |
273 |
awful.util.table.join( |
|
274 |
awful.button({}, 1, function () show_kt(keytable, "Binding") end), |
|
275 |
awful.button({}, 3, stop_kt))) |
|
276 |
capi.keygrabber.run(function (mod, key, event) |
|
277 |
if not kt_handler(keytable, mod, key, event) then |
|
278 |
stop_kt() |
|
279 |
return false |
|
280 |
end |
|
281 |
return true |
|
282 |
end) |
|
283 |
end |
|
284 |
||
285 |
function make_kt(keytable, title) |
|
286 |
return function (c) |
|
287 |
-- if is_in_run_kt then |
|
288 |
-- -- notify_error("Already in run_kt:\n" .. debug.traceback()) |
|
289 |
-- is_in_run_kt = false -- reset |
|
290 |
-- return false |
|
291 |
-- end |
|
292 |
return run_kt(c, keytable, title) |
|
293 |
end |
|
294 |
end |
|
295 |
||
296 |
function make_focus_bydirection(direction) |
|
297 |
return function () |
|
298 |
awful.client.focus.bydirection(direction) |
|
299 |
if capi.client.focus then capi.client.focus:raise() end |
|
300 |
return true |
|
301 |
end |
|
302 |
end |
|
303 |
||
14
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
304 |
function split_modifiers(key) |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
305 |
local modifiers = {} |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
306 |
local pattern = capi.string.format("([^+]+)", sep) |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
307 |
key:gsub(pattern, function(mod) table.insert(modifiers, mod) end) |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
308 |
key = table.remove(modifiers) |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
309 |
return modifiers, key |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
310 |
end |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
311 |
|
7 | 312 |
function make_globalkeys(modifiers, keytable) |
313 |
local t = {} |
|
314 |
for _,k in ipairs(keytable) do |
|
14
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
315 |
local mods, key = split_modifiers(k.key) |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
316 |
mods = awful.util.table.join(modifiers, mods) |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
317 |
-- log("name=" .. k.name .. "; modifiers=" .. table.concat(mods, ":") .. "; key=" .. key) |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
318 |
if key == "Space" then |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
319 |
key = capi.string.lower(key) |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
320 |
end |
6348b9f842b2
Move back to non-shifty awesomeness.
Fabien Ninoles <fabien@tzone.org>
parents:
13
diff
changeset
|
321 |
t = awful.util.table.join(t, awful.key(mods, key, k.func)) |
7 | 322 |
end |
323 |
return t |
|
324 |
end |
|
325 |
||
8 | 326 |
-- Install a sloppy-like focus with a timeout. |
327 |
||
328 |
function sloppy_toggle() |
|
329 |
sloppy = not sloppy |
|
330 |
end |
|
331 |
||
332 |
function sloppy_mouse_enter(c) |
|
333 |
if sloppy and |
|
334 |
c ~= sloppy_last_client and |
|
335 |
awful.client.focus.filter(c) and |
|
336 |
awful.layout.get(c.screen) ~= awful.layout.suit.magnifier |
|
337 |
then |
|
9
56e80afa3e1c
Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents:
8
diff
changeset
|
338 |
if sloppy_timer.started |
56e80afa3e1c
Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents:
8
diff
changeset
|
339 |
then |
56e80afa3e1c
Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents:
8
diff
changeset
|
340 |
sloppy_timer:again() |
56e80afa3e1c
Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents:
8
diff
changeset
|
341 |
else |
56e80afa3e1c
Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents:
8
diff
changeset
|
342 |
sloppy_timer:start() |
56e80afa3e1c
Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents:
8
diff
changeset
|
343 |
end |
8 | 344 |
sloppy_last_client = c |
345 |
end |
|
346 |
end |
|
347 |
||
348 |
function sloppy_on_timeout() |
|
349 |
if sloppy |
|
350 |
then |
|
351 |
local c = awful.mouse.client_under_pointer() |
|
352 |
if c and |
|
353 |
c == sloppy_last_client |
|
354 |
then |
|
355 |
capi.client.focus = c |
|
9
56e80afa3e1c
Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents:
8
diff
changeset
|
356 |
sloppy_timer:stop() |
8 | 357 |
end |
358 |
end |
|
359 |
end |
|
360 |
||
361 |
sloppy = true |
|
362 |
sloppy_last_client = nil |
|
363 |
sloppy_timer = nil |
|
364 |
||
365 |
function sloppy_install(delay) |
|
366 |
sloppy_timer = timer({ timeout = delay }) |
|
11 | 367 |
sloppy_timer:connect_signal("timeout", sloppy_on_timeout) |
8 | 368 |
sloppy_timer:start() |
11 | 369 |
capi.client.connect_signal("manage", function (c) |
370 |
c:connect_signal("mouse::enter", sloppy_mouse_enter) |
|
8 | 371 |
end) |
12 | 372 |
capi.client.connect_signal("focus", function () |
373 |
if sloppy_timer.started then |
|
374 |
sloppy_timer:stop() |
|
375 |
end |
|
376 |
end) |
|
8 | 377 |
end |
13
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
378 |
|
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
379 |
-- theme menu |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
380 |
function theme_load(theme) |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
381 |
local cfg_path = awful.util.getdir("config") |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
382 |
awful.util.spawn("ln -sfn " .. cfg_path .. "/themes/" .. theme .. " " .. cfg_path .. "/current_theme") |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
383 |
awesome.restart() |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
384 |
end |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
385 |
|
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
386 |
function theme_menu() |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
387 |
-- List your theme files and feed the menu table |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
388 |
local cmd = "ls -1 " .. awful.util.getdir("config") .. "/themes/" |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
389 |
local f = io.popen(cmd) |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
390 |
|
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
391 |
local themes = {} |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
392 |
for l in f:lines() do |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
393 |
local item = { l, function () theme_load(l) end } |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
394 |
table.insert(themes, item) |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
395 |
end |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
396 |
|
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
397 |
f:close() |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
398 |
return themes |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
399 |
end |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
400 |
|
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
401 |
function set_wallpaper(wallpaper) |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
402 |
local cfg_path = awful.util.getdir("config") |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
403 |
local source_path = cfg_path .. "/wallpapers/" .. wallpaper |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
404 |
local default_path = cfg_path .. "/default" |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
405 |
awful.util.spawn("ln -sfn " .. source_path .. " " .. default_path ) |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
406 |
awful.util.spawn("fbsetbg -a " .. default_path) |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
407 |
end |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
408 |
|
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
409 |
function wallpaper_menu() |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
410 |
local cmd = "ls " .. awful.util.getdir("config") .. "/wallpapers/" |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
411 |
local f = io.popen(cmd) |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
412 |
local wallpapers = {} |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
413 |
for l in f:lines() do |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
414 |
local name, ext = capi.string.match(l, "(.-)(%.[^%.]+)$") |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
415 |
local item = { name, function () set_wallpaper(l) end } |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
416 |
table.insert(wallpapers, item) |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
417 |
end |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
418 |
|
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
419 |
f:close() |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
420 |
return wallpapers |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
421 |
end |
e9e2f624cd99
Add themes and wallpapers menus.
Fabien Ninoles <fabien@tzone.org>
parents:
12
diff
changeset
|
422 |