diff --git a/README.md b/README.md
index 513ff40..213ee98 100644
--- a/README.md
+++ b/README.md
@@ -53,6 +53,9 @@ Here some of the things you may be interested in:
- Keybindings are "autodocumented". See `lib/keydoc.lua` to see how
this works. The list of key bindings can be accessed with Mod4 +
F1.
+
+ - On the debug front, I am quite happy with `dbg()` in
+ `rc/debug.lua`.
Things in `lib/` are meant to be reused. I am using my own `loadrc()`
function to load modules and therefore, I prefix my modules with
diff --git a/rc.lua b/rc.lua
index a838d8d..5c81193 100644
--- a/rc.lua
+++ b/rc.lua
@@ -36,6 +36,8 @@ function loadrc(name, mod)
return result
end
+loadrc("errors") -- errors and debug stuff
+
-- Global configuration
modkey = "Mod4"
config = {}
@@ -66,7 +68,7 @@ config.hostname = awful.util.pread('uname -n'):gsub('\n', '')
-- Remaining modules
loadrc("xrun") -- xrun function
loadrc("appearance") -- theme and appearance settings
-loadrc("errors") -- errors and debug stuff
+loadrc("debug") -- debugging primitive `dbg()`
loadrc("start") -- programs to run on start
loadrc("bindings") -- keybindings
diff --git a/rc/bindings.lua b/rc/bindings.lua
index efa556b..6f297ed 100644
--- a/rc/bindings.lua
+++ b/rc/bindings.lua
@@ -4,38 +4,6 @@ local volume = loadrc("volume", "vbe/volume")
local brightness = loadrc("brightness", "vbe/brightness")
local keydoc = loadrc("keydoc", "vbe/keydoc")
-local function client_info()
- local v = ""
-
- -- object
- local c = client.focus
- v = v .. tostring(c)
-
- -- geometry
- local cc = c:geometry()
- local signx = (cc.x > 0 and "+") or ""
- local signy = (cc.y > 0 and "+") or ""
- v = v .. " @ " .. cc.width .. 'x' .. cc.height .. signx .. cc.x .. signy .. cc.y .. "\n\n"
-
- local inf = {
- "name", "icon_name", "type", "class", "role", "instance", "pid",
- "skip_taskbar", "id", "group_window", "leader_id", "machine",
- "screen", "hidden", "minimized", "size_hints_honor", "titlebar", "urgent",
- "focus", "opacity", "ontop", "above", "below", "fullscreen", "transient_for",
- "maximixed_horizontal", "maximixed_vertical", "sticky", "modal", "focusable"
- }
-
- for i = 1, #inf do
- v = v .. string.format('%2s: %-20s = %s\n',
- i,
- beautiful.fg_widget_label, inf[i],
- beautiful.fg_widget_value, tostring(c[inf[i]]))
- end
-
- naughty.notify{ text = string.format('%s', v:sub(1,#v-1)),
- timeout = 0, margin = 10, screen = c.screen }
-end
-
local function screenshot(client)
if not client then
client = "root"
@@ -132,7 +100,7 @@ config.keys.client = awful.util.table.join(
"Switch with master window"),
awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end,
"Stay on top"),
- awful.key({ modkey, }, "i", client_info,
+ awful.key({ modkey, }, "i", dbg,
"Get client-related information"),
awful.key({ modkey, }, "m",
function (c)
diff --git a/rc/debug.lua b/rc/debug.lua
new file mode 100644
index 0000000..44f352f
--- /dev/null
+++ b/rc/debug.lua
@@ -0,0 +1,104 @@
+local colors = {
+ header = theme.fg_widget_clock,
+ count = theme.fg_widget_label,
+ index = theme.fg_widget_label,
+ name = theme.fg_widget_value_important,
+}
+
+local function client_info()
+ local v = ""
+
+ -- object
+ local c = client.focus
+ v = v .. tostring(c)
+
+ -- geometry
+ local cc = c:geometry()
+ local signx = (cc.x > 0 and "+") or ""
+ local signy = (cc.y > 0 and "+") or ""
+ v = v .. " @ " .. cc.width .. 'x' .. cc.height .. signx .. cc.x .. signy .. cc.y .. "\n\n"
+
+ local inf = {
+ "name", "icon_name", "type", "class", "role", "instance", "pid",
+ "skip_taskbar", "id", "group_window", "leader_id", "machine",
+ "screen", "hidden", "minimized", "size_hints_honor", "titlebar", "urgent",
+ "focus", "opacity", "ontop", "above", "below", "fullscreen", "transient_for",
+ "maximixed_horizontal", "maximixed_vertical", "sticky", "modal", "focusable"
+ }
+
+ for i = 1, #inf do
+ v = v .. string.format('%2s: %-20s = %s\n',
+ i,
+ beautiful.fg_widget_label, inf[i],
+ beautiful.fg_widget_value, tostring(c[inf[i]]))
+ end
+
+ naughty.notify{ text = string.format('%s', v:sub(1,#v-1)),
+ timeout = 0, margin = 10, screen = c.screen }
+end
+
+local function dbg_get(var, depth, indent)
+ local a = ""
+ local text = ""
+ local name = ""
+ local vtype = type(var)
+ local vstring = tostring(var)
+
+ if vtype == "table" or vtype == "userdata" then
+ if vtype == "userdata" then var = getmetatable(var) end
+ -- element count and longest key
+ local count = 0
+ local longest_key = 3
+ for k,v in pairs(var) do
+ count = count + 1
+ longest_key = math.max(#tostring(k), longest_key)
+ end
+ text = text .. vstring .. " #" .. count .. ""
+ -- descend a table
+ if depth > 0 then
+ -- sort keys FIXME: messes up sorting number
+ local sorted = {}
+ for k, v in pairs(var) do table.insert(sorted, { k, v }) end
+ table.sort(sorted, function(a, b) return tostring(a[1]) < tostring(b[1]) end)
+ -- go through elements
+ for _, p in ipairs(sorted) do
+ local key = p[1]; local value = p[2]
+ -- don't descend _M
+ local d; if key ~= "_M" then d = depth - 1 else d = 0 end
+ -- get content and add to output
+ local content = dbg_get(value, d, indent + longest_key + 1)
+ text = text .. '\n' .. string.rep(" ", indent) ..
+ string.format("%-"..longest_key.."s %s",
+ tostring(key), content)
+ end
+ end
+ else
+ if vtype == "tag" or vtype == "client" then
+ name = " [" .. var.name:sub(1,10) .. "]"
+ end
+ text = text .. vstring .. name or ""
+ end
+
+ return text
+end
+
+function dbg(...)
+ local num = table.maxn(arg)
+ local text = "dbg #"..num..""
+ local depth = 2
+ local clients = 0
+
+ for i = 1, num do
+ local desc = dbg_get(arg[i], depth, 3)
+ text = text .. string.format("\n%2d %s", i, desc)
+ if type(arg[i]) == "client" then
+ client_info(arg[i])
+ clients = clients + 1
+ end
+ end
+
+ -- Display only if we don't have only clients to be displayed
+ if clients ~= num then
+ naughty.notify{ text = text, timeout = 0, hover_timeout = 0.05, screen = screen.count() }
+ end
+end
diff --git a/rc/errors.lua b/rc/errors.lua
index 1dc296f..3ec5ee0 100644
--- a/rc/errors.lua
+++ b/rc/errors.lua
@@ -1,6 +1,3 @@
-require("awesome")
-require("naughty")
-
-- Handle runtime errors after startup
do
local in_error = false
@@ -15,68 +12,3 @@ do
in_error = false
end)
end
-
-local colors = {
- header = theme.fg_widget_clock,
- count = theme.fg_widget_label,
- index = theme.fg_widget_label,
- name = theme.fg_widget_value_important,
-}
-
-local function dbg_get(var, depth, indent)
- local a = ""
- local text = ""
- local name = ""
- local vtype = type(var)
- local vstring = tostring(var)
-
- if vtype == "table" or vtype == "userdata" then
- if vtype == "userdata" then var = getmetatable(var) end
- -- element count and longest key
- local count = 0
- local longest_key = 3
- for k,v in pairs(var) do
- count = count + 1
- longest_key = math.max(#tostring(k), longest_key)
- end
- text = text .. vstring .. " #" .. count .. ""
- -- descend a table
- if depth > 0 then
- -- sort keys FIXME: messes up sorting number
- local sorted = {}
- for k, v in pairs(var) do table.insert(sorted, { k, v }) end
- table.sort(sorted, function(a, b) return tostring(a[1]) < tostring(b[1]) end)
- -- go through elements
- for _, p in ipairs(sorted) do
- local key = p[1]; local value = p[2]
- -- don't descend _M
- local d; if key ~= "_M" then d = depth - 1 else d = 0 end
- -- get content and add to output
- local content = dbg_get(value, d, indent + longest_key + 1)
- text = text .. '\n' .. string.rep(" ", indent) ..
- string.format("%-"..longest_key.."s %s",
- tostring(key), content)
- end
- end
- else
- if vtype == "tag" or vtype == "client" then
- name = " [" .. var.name:sub(1,10) .. "]"
- end
- text = text .. vstring .. name or ""
- end
-
- return text
-end
-
-function dbg(...)
- local num = table.maxn(arg)
- local text = "dbg #"..num..""
- local depth = 2
-
- for i = 1, num do
- local desc = dbg_get(arg[i], depth, 3)
- text = text .. string.format("\n%2d %s", i, desc)
- end
-
- naughty.notify{ text = text, timeout = 0, hover_timeout = 0.05, screen = screen.count() }
-end