awful.widget.common: fix buttons

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-07-09 12:46:06 +02:00
parent 99b75bf486
commit 2f93980ff8
1 changed files with 9 additions and 10 deletions

View File

@ -9,8 +9,7 @@ local math = math
local type = type local type = type
local ipairs = ipairs local ipairs = ipairs
local setmetatable = setmetatable local setmetatable = setmetatable
local capi = { widget = widget } local capi = { widget = widget, button = button }
local abutton = require("awful.button")
--- Common widget code --- Common widget code
module("awful.widget.common") module("awful.widget.common")
@ -54,15 +53,15 @@ function list_update(w, buttons, label, data, widgets, objects)
if buttons then if buttons then
if not data[o] then if not data[o] then
data[o] = { } data[o] = { }
-- Replace press function by a new one calling with object as
-- argument
for kb, b in ipairs(buttons) do for kb, b in ipairs(buttons) do
-- Copy object -- Create a proxy button object: it will receive the real
local bpress, brelease = b.press, b.release -- press and release events, and will propagate them the the
local press, release -- button object the user provided, but with the object as
if bpress then press = function() bpress(o) end end -- argument.
if brelease then release = function () brelease(o) end end local btn = capi.button { modifiers = b.modifiers, button = b.button }
data[o][kb] = abutton(b.modifiers, b.button, press, release) btn:add_signal("press", function () b:emit_signal("press", o) end)
btn:add_signal("release", function () b:emit_signal("release", o) end)
data[o][#data[o] + 1] = btn
end end
end end
w[k]:buttons(data[o]) w[k]:buttons(data[o])