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-10-06 14:28:43 +02:00
|
|
|
local imagebox = require("wibox.widget.imagebox")
|
2012-11-27 22:55:42 +01:00
|
|
|
local widget = require("wibox.widget.base")
|
2012-05-27 19:20:34 +02:00
|
|
|
local surface = require("gears.surface")
|
|
|
|
local cairo = require("lgi").cairo
|
|
|
|
local capi = { mouse = mouse }
|
2009-02-27 17:22:03 +01:00
|
|
|
|
2012-06-14 01:08:27 +02:00
|
|
|
-- awful.widget.button
|
|
|
|
local button = { mt = {} }
|
2009-02-27 17:22:03 +01:00
|
|
|
|
|
|
|
--- Create a button widget. When clicked, the image is deplaced to make it like
|
|
|
|
-- a real button.
|
2010-10-06 14:28:43 +02:00
|
|
|
-- @param args Widget arguments. "image" is the image to display.
|
2009-02-27 17:22:03 +01:00
|
|
|
-- @return A textbox widget configured as a button.
|
2012-06-14 01:08:27 +02:00
|
|
|
function button.new(args)
|
2012-11-27 22:55:42 +01:00
|
|
|
if not args or not args.image then
|
|
|
|
return widget.empty_widget()
|
|
|
|
end
|
2012-05-27 19:20:34 +02:00
|
|
|
local img_release = surface.load(args.image)
|
|
|
|
local img_press = cairo.ImageSurface(cairo.Format.ARGB32, img_release.width, img_release.height)
|
|
|
|
local cr = cairo.Context(img_press)
|
|
|
|
cr:set_source_surface(img_release, 2, 2)
|
2010-09-29 15:57:10 +02:00
|
|
|
cr:paint()
|
|
|
|
|
2010-10-06 14:28:43 +02:00
|
|
|
local w = imagebox()
|
|
|
|
w:set_image(img_release)
|
|
|
|
w:buttons(button({}, 1, function () w:set_image(img_press) end, function () w:set_image(img_release) end))
|
2009-02-27 17:22:03 +01:00
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
2012-06-14 01:08:27 +02:00
|
|
|
function button.mt:__call(...)
|
|
|
|
return button.new(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(button, button.mt)
|
2009-02-27 17:22:03 +01:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|