awful.widget.button: Port to new widget layout

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-10-06 14:28:43 +02:00
parent 1b134b2361
commit 3b9150f05a
1 changed files with 6 additions and 14 deletions

View File

@ -7,16 +7,15 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local type = type local type = type
local button = require("awful.button") local button = require("awful.button")
local capi = { widget = widget, local imagebox = require("wibox.widget.imagebox")
mouse = mouse, local capi = { mouse = mouse,
oocairo = oocairo } oocairo = oocairo }
module("awful.widget.button") module("awful.widget.button")
--- Create a button widget. When clicked, the image is deplaced to make it like --- Create a button widget. When clicked, the image is deplaced to make it like
-- a real button. -- a real button.
-- @param args Standard widget table arguments, plus image for the image path or -- @param args Widget arguments. "image" is the image to display.
-- the image object.
-- @return A textbox widget configured as a button. -- @return A textbox widget configured as a button.
function new(args) function new(args)
if not args or not args.image then return end if not args or not args.image then return end
@ -25,22 +24,15 @@ function new(args)
img_release = capi.oocairo.image_surface_create_from_png(args.image) img_release = capi.oocairo.image_surface_create_from_png(args.image)
elseif type(args.image) == "userdata" and args.image.type and args.image:type() == "cairo_surface_t" then elseif type(args.image) == "userdata" and args.image.type and args.image:type() == "cairo_surface_t" then
img_release = args.image img_release = args.image
else
return
end end
local img_press = capi.oocairo.image_surface_create("argb32", img_release:get_width(), img_release:get_height()) local img_press = capi.oocairo.image_surface_create("argb32", img_release:get_width(), img_release:get_height())
local cr = capi.oocairo.context_create(img_press) local cr = capi.oocairo.context_create(img_press)
cr:set_source(img_release, 2, 2) cr:set_source(img_release, 2, 2)
cr:paint() cr:paint()
args.type = "imagebox" local w = imagebox()
local w = capi.widget(args) w:set_image(img_release)
w.image = img_release w:buttons(button({}, 1, function () w:set_image(img_press) end, function () w:set_image(img_release) end))
w:buttons(button({}, 1, function () w.image = img_press end, function () w.image = img_release end))
w:connect_signal("mouse::leave", function () w.image = img_release end)
w:connect_signal("mouse::enter", function ()
if capi.mouse.coords().buttons[1] then w.image = img_press end
end)
return w return w
end end