Merge pull request #376 from blueyed/more-tostring

More tostring metamethods for drawable and wibox
This commit is contained in:
Daniel Hahler 2015-08-01 11:22:00 +02:00
commit 896ab0a286
4 changed files with 24 additions and 4 deletions

View File

@ -75,7 +75,7 @@ local function new(c, args)
local ret local ret
if not bars[position] then if not bars[position] then
ret = drawable(d, nil) ret = drawable(d, nil, "awful.titlebar")
local function update_colors() local function update_colors()
local args = bars[position].args local args = bars[position].args
ret:set_bg(get_color("bg", c, args)) ret:set_bg(get_color("bg", c, args))

View File

@ -229,7 +229,7 @@ local function setup_signals(_drawable)
clone_signal("property::y") clone_signal("property::y")
end end
function drawable.new(d, widget_arg) function drawable.new(d, widget_arg, drawable_name)
local ret = object() local ret = object()
ret.drawable = d ret.drawable = d
ret.widget_arg = widget_arg or ret 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::move", function(_, x, y) handle_motion(ret, x, y) end)
d:connect_signal("mouse::leave", function() handle_leave(ret) 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 -- Make sure the drawable is drawn at least once
ret.draw() ret.draw()

View File

@ -108,7 +108,8 @@ local function new(args)
local ret = object() local ret = object()
local w = capi.drawin(args) local w = capi.drawin(args)
ret.drawin = w 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 for k, v in pairs(wibox) do
if type(v) == "function" then if type(v) == "function" then
@ -126,6 +127,15 @@ local function new(args)
ret:set_bg(args.bg or beautiful.bg_normal) ret:set_bg(args.bg or beautiful.bg_normal)
ret:set_fg(args.fg or beautiful.fg_normal) ret:set_fg(args.fg or beautiful.fg_normal)
-- Add __tostring method to metatable.
local mt = {}
local orig_string = tostring(ret)
mt.__tostring = function(o)
return string.format("wibox: %s (%s)",
tostring(ret._drawable), orig_string)
end
ret = setmetatable(ret, mt)
-- Make sure the wibox is drawn at least once -- Make sure the wibox is drawn at least once
ret.draw() ret.draw()

View File

@ -110,8 +110,9 @@ function base.make_widget(proxy, widget_name)
-- Add __tostring method to metatable. -- Add __tostring method to metatable.
ret.widget_name = widget_name or object.modulename(3) ret.widget_name = widget_name or object.modulename(3)
local mt = {} local mt = {}
local orig_string = tostring(ret)
mt.__tostring = function(o) mt.__tostring = function(o)
return ret.widget_name return string.format("%s (%s)", ret.widget_name, orig_string)
end end
return setmetatable(ret, mt) return setmetatable(ret, mt)
end end