2009-02-27 17:22:03 +01:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008-2009 Julien Danjou
|
2014-05-20 13:02:39 +02:00
|
|
|
-- @classmod awful.widget.launcher
|
2009-02-27 17:22:03 +01:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
2017-03-08 21:18:33 +01:00
|
|
|
local gtable = require("gears.table")
|
2015-09-30 00:05:56 +02:00
|
|
|
local spawn = require("awful.spawn")
|
2009-04-17 18:08:52 +02:00
|
|
|
local wbutton = require("awful.widget.button")
|
|
|
|
local button = require("awful.button")
|
2009-02-27 17:22:03 +01:00
|
|
|
|
2012-06-14 01:08:27 +02:00
|
|
|
local launcher = { mt = {} }
|
2009-02-27 17:22:03 +01:00
|
|
|
|
|
|
|
--- Create a button widget which will launch a command.
|
|
|
|
-- @param args Standard widget table arguments, plus image for the image path
|
|
|
|
-- and command for the command to run on click, or either menu to create menu.
|
|
|
|
-- @return A launcher widget.
|
2012-06-14 01:08:27 +02:00
|
|
|
function launcher.new(args)
|
2009-02-27 17:22:03 +01:00
|
|
|
if not args.command and not args.menu then return end
|
2009-04-17 18:08:52 +02:00
|
|
|
local w = wbutton(args)
|
2009-02-27 17:22:03 +01:00
|
|
|
if not w then return end
|
|
|
|
|
2012-03-06 00:03:09 +01:00
|
|
|
local b
|
2009-02-27 17:22:03 +01:00
|
|
|
if args.command then
|
2017-03-08 21:18:33 +01:00
|
|
|
b = gtable.join(w:buttons(), button({}, 1, nil, function () spawn(args.command) end))
|
2009-02-27 17:22:03 +01:00
|
|
|
elseif args.menu then
|
2017-03-08 21:18:33 +01:00
|
|
|
b = gtable.join(w:buttons(), button({}, 1, nil, function () args.menu:toggle() end))
|
2009-02-27 17:22:03 +01:00
|
|
|
end
|
|
|
|
|
2009-08-14 16:46:35 +02:00
|
|
|
w:buttons(b)
|
2009-02-27 17:22:03 +01:00
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
2012-06-14 01:08:27 +02:00
|
|
|
function launcher.mt:__call(...)
|
|
|
|
return launcher.new(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(launcher, launcher.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
|