wibox.drawable: add __tostring meta method

This commit is contained in:
Daniel Hahler 2015-07-29 21:12:41 +02:00
parent fa6b7c390f
commit 430e8664be
3 changed files with 13 additions and 3 deletions

View File

@ -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))

View File

@ -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()

View File

@ -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