From 430e8664be753020d21a2396c9aee2fd7d2522b2 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 29 Jul 2015 21:12:41 +0200 Subject: [PATCH] wibox.drawable: add __tostring meta method --- lib/awful/titlebar.lua | 2 +- lib/wibox/drawable.lua | 11 ++++++++++- lib/wibox/init.lua | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/awful/titlebar.lua b/lib/awful/titlebar.lua index 40aaecbc..b34cdbed 100644 --- a/lib/awful/titlebar.lua +++ b/lib/awful/titlebar.lua @@ -75,7 +75,7 @@ local function new(c, args) local ret if not bars[position] then - ret = drawable(d, nil) + ret = drawable(d, nil, "awful.titlebar") local function update_colors() local args = bars[position].args ret:set_bg(get_color("bg", c, args)) diff --git a/lib/wibox/drawable.lua b/lib/wibox/drawable.lua index b5ac9ba1..7b023a04 100644 --- a/lib/wibox/drawable.lua +++ b/lib/wibox/drawable.lua @@ -229,7 +229,7 @@ local function setup_signals(_drawable) clone_signal("property::y") end -function drawable.new(d, widget_arg) +function drawable.new(d, widget_arg, drawable_name) local ret = object() ret.drawable = d ret.widget_arg = widget_arg or ret @@ -287,6 +287,15 @@ function drawable.new(d, widget_arg) d:connect_signal("mouse::move", function(_, x, y) handle_motion(ret, x, y) end) d:connect_signal("mouse::leave", function() handle_leave(ret) end) + -- Add __tostring method to metatable. + ret.drawable_name = drawable_name or object.modulename(3) + local mt = {} + local orig_string = tostring(ret) + mt.__tostring = function(o) + return string.format("%s (%s)", ret.drawable_name, orig_string) + end + ret = setmetatable(ret, mt) + -- Make sure the drawable is drawn at least once ret.draw() diff --git a/lib/wibox/init.lua b/lib/wibox/init.lua index de727adb..bc5affc7 100644 --- a/lib/wibox/init.lua +++ b/lib/wibox/init.lua @@ -108,7 +108,8 @@ local function new(args) local ret = object() local w = capi.drawin(args) ret.drawin = w - ret._drawable = wibox.drawable(w.drawable, ret) + ret._drawable = wibox.drawable(w.drawable, ret, + "wibox drawable (" .. object.modulename(3) .. ")") for k, v in pairs(wibox) do if type(v) == "function" then