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")
|
2009-02-27 17:22:03 +01:00
|
|
|
local capi = { image = image,
|
|
|
|
widget = widget,
|
2009-04-17 18:08:52 +02:00
|
|
|
mouse = mouse }
|
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
|
|
|
|
img_release = capi.image(args.image)
|
|
|
|
elseif type(args.image) == "image" then
|
|
|
|
img_release = args.image
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local img_press = img_release:crop(-2, -2, img_release.width, img_release.height)
|
|
|
|
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-02-27 17:22:03 +01:00
|
|
|
function w.mouse_leave(s) w.image = img_release end
|
|
|
|
function w.mouse_enter(s) if capi.mouse.coords().buttons[1] then w.image = img_press end end
|
|
|
|
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
|