2009-02-27 17:22:03 +01:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008-2009 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local type = type
|
2009-04-17 18:08:52 +02:00
|
|
|
local button = require("awful.button")
|
2010-09-29 15:57:10 +02:00
|
|
|
local capi = { widget = widget,
|
|
|
|
mouse = mouse,
|
|
|
|
oocairo = oocairo }
|
2009-02-27 17:22:03 +01:00
|
|
|
|
|
|
|
module("awful.widget.button")
|
|
|
|
|
|
|
|
--- Create a button widget. When clicked, the image is deplaced to make it like
|
|
|
|
-- a real button.
|
|
|
|
-- @param args Standard widget table arguments, plus image for the image path or
|
|
|
|
-- the image object.
|
|
|
|
-- @return A textbox widget configured as a button.
|
2009-04-27 18:39:55 +02:00
|
|
|
function new(args)
|
2009-02-27 17:22:03 +01:00
|
|
|
if not args or not args.image then return end
|
|
|
|
local img_release
|
|
|
|
if type(args.image) == "string" then
|
2010-09-29 15:57:10 +02:00
|
|
|
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
|
2009-02-27 17:22:03 +01:00
|
|
|
img_release = args.image
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
2010-09-29 15:57:10 +02:00
|
|
|
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)
|
|
|
|
cr:set_source(img_release, 2, 2)
|
|
|
|
cr:paint()
|
|
|
|
|
2009-02-27 17:22:03 +01:00
|
|
|
args.type = "imagebox"
|
|
|
|
local w = capi.widget(args)
|
|
|
|
w.image = img_release
|
2009-08-14 16:46:35 +02:00
|
|
|
w:buttons(button({}, 1, function () w.image = img_press end, function () w.image = img_release end))
|
2009-10-09 20:39:55 +02:00
|
|
|
w:connect_signal("mouse::leave", function () w.image = img_release end)
|
|
|
|
w:connect_signal("mouse::enter", function ()
|
2009-08-17 15:43:32 +02:00
|
|
|
if capi.mouse.coords().buttons[1] then w.image = img_press end
|
|
|
|
end)
|
2009-02-27 17:22:03 +01:00
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
2009-05-25 11:14:08 +02:00
|
|
|
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
2009-02-27 17:22:03 +01:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|