|
1 local os = require("os") |
|
2 local io = require("io") |
|
3 local debug = require("debug") |
|
4 local awesome = require("awesome") |
1 local naughty = require("naughty") |
5 local naughty = require("naughty") |
2 local awful = require("awful") |
6 local awful = require("awful") |
3 local debug = require("debug") |
|
4 local vicious = require("vicious") |
7 local vicious = require("vicious") |
5 local wicked = require("wicked") |
8 local wicked = require("wicked") |
6 local beautiful = require("beautiful") |
9 local beautiful = require("beautiful") |
7 local timer = require("timer") |
10 local timer = require("timer") |
8 local wibox = require("wibox") |
11 local wibox = require("wibox") |
9 |
12 |
10 local ipairs = ipairs |
13 local ipairs = ipairs |
11 local pairs = pairs |
14 local pairs = pairs |
12 |
15 |
13 local capi = { |
16 local capi = { |
14 keygrabber = keygrabber, |
17 keygrabber = require("keygrabber"), |
15 client = client, |
18 client = require("client"), |
16 string = string, |
19 string = require("string"), |
17 widget = widget, |
|
18 } |
20 } |
19 |
21 |
20 module("my") |
22 module("my") |
|
23 |
|
24 --- Stolen from shifty: Shows a popup and logs to a file |
|
25 -- @param message The text message. |
|
26 -- @param log_level 1 = INFO, 2 = WARN, 3 = ERROR, if nothting is provided 1 is used. |
|
27 function log(message, log_level) |
|
28 if log_level == nil then |
|
29 log_level = 1 |
|
30 end |
|
31 |
|
32 local log_table = { |
|
33 { level = "INFO", bg_colour = "#18F92C", fg_colour = "#0E0E0E" }, |
|
34 { level = "WARN", bg_colour = "#9E731F", fg_colour = "#0E0E0E" }, |
|
35 { level = "ERROR", bg_colour = "#FF0015", fg_colour = "#000000" } |
|
36 } |
|
37 -- %c eg: Wed Jan 30 14:25:13 2013 |
|
38 local time = os.date("%c") |
|
39 message = time .. " - " .. log_table[log_level].level .. " - " .. message .. "\n" .. debug.traceback() |
|
40 |
|
41 local home = os.getenv("HOME") |
|
42 local log_file = io.open(home .. "/.awesome.log", "a+") |
|
43 log_file:write(message .."\n") |
|
44 log_file:close() |
|
45 |
|
46 naughty.notify({ preset = naughty.config.presets.critical, text = message, bg = log_table[log_level].bg_colour, fg = log_table[log_level].fg_colour}) |
|
47 end |
|
48 |
|
49 local in_error = false |
|
50 function mk_notify_error_dialog(level) |
|
51 return function(msg) |
|
52 -- Make sure we don't go into an endless error loop |
|
53 if in_error then return end |
|
54 in_error = true |
|
55 |
|
56 log(msg, level) |
|
57 |
|
58 in_error = false |
|
59 end |
|
60 end |
|
61 |
|
62 notify_error = mk_notify_error_dialog(3) |
21 |
63 |
22 local function get_gradient_colors(c1, c2, c3) |
64 local function get_gradient_colors(c1, c2, c3) |
23 return { type = "linear", from = { 0, 0 }, to = { 0, 20 }, stops = { { 0, c1 }, { 0.5, c2 }, { 1, c3 } }} |
65 return { type = "linear", from = { 0, 0 }, to = { 0, 20 }, stops = { { 0, c1 }, { 0.5, c2 }, { 1, c3 } }} |
24 end |
|
25 |
|
26 local in_error = false |
|
27 function notify_error(err) |
|
28 -- Make sure we don't go into an endless error loop |
|
29 if in_error then return end |
|
30 in_error = true |
|
31 |
|
32 naughty.notify({ preset = naughty.config.presets.critical, |
|
33 title = "Oops, an error happened!", |
|
34 text = err }) |
|
35 in_error = false |
|
36 end |
66 end |
37 |
67 |
38 function mkspawn(p) |
68 function mkspawn(p) |
39 return function () awful.util.spawn(p) end |
69 return function () awful.util.spawn(p) end |
40 end |
70 end |
189 local function kt_handler(keytable, mod, key, event) |
222 local function kt_handler(keytable, mod, key, event) |
190 if event == "release" then |
223 if event == "release" then |
191 return true |
224 return true |
192 end |
225 end |
193 local theme = beautiful.get() |
226 local theme = beautiful.get() |
194 widgets.mode_widget.bg = theme.bg_focus |
227 widgets.mode_widget_bg:set_bg(theme.bg_focus) |
195 if key == "Escape" then |
228 if key == "Escape" then |
196 return false |
229 return false |
197 end |
230 end |
198 local skey = capi.string.lower(translate_key(mod, key)) |
231 local skey = capi.string.lower(translate_key(mod, key)) |
199 if skey == "control+h" or skey == "shift+?" then |
232 if skey == "control+h" or skey == "shift+?" then |
223 end |
256 end |
224 |
257 |
225 |
258 |
226 -- local is_in_run_kt = false |
259 -- local is_in_run_kt = false |
227 function run_kt(c, keytable, title) |
260 function run_kt(c, keytable, title) |
228 widgets.mode_widget.text = "Mode: " .. title |
261 widgets.mode_widget:set_text("Mode: " .. title) |
229 widgets.mode_widget.visible = true |
262 -- widgets.mode_widget:show() |
230 widgets.mode_widget.bg = "LightBlue" |
263 widgets.mode_widget_bg:set_bg("LightBlue") |
231 widgets.mode_widget:buttons( |
264 widgets.mode_widget:buttons( |
232 awful.util.table.join( |
265 awful.util.table.join( |
233 awful.button({}, 1, function () show_kt(keytable, "Binding") end), |
266 awful.button({}, 1, function () show_kt(keytable, "Binding") end), |
234 awful.button({}, 3, stop_kt))) |
267 awful.button({}, 3, stop_kt))) |
235 capi.keygrabber.run(function (mod, key, event) |
268 capi.keygrabber.run(function (mod, key, event) |