2009-02-27 17:22:03 +01:00
|
|
|
---------------------------------------------------------------------------
|
2019-12-04 06:08:40 +01:00
|
|
|
-- A button widget which hosts a menu or starts a command.
|
|
|
|
--
|
|
|
|
-- Implementation of `awful.widget.button` with the ability to host an
|
|
|
|
-- `awful.menu` or a command to execute on user click.
|
|
|
|
--
|
|
|
|
-- This example is the default launcher.
|
|
|
|
--
|
|
|
|
--@DOC_awful_widget_launcher_default_EXAMPLE@
|
|
|
|
--
|
2009-02-27 17:22:03 +01:00
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008-2009 Julien Danjou
|
2019-06-06 08:15:53 +02:00
|
|
|
-- @widgetmod awful.widget.launcher
|
2009-02-27 17:22:03 +01:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
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.
|
2019-12-04 06:08:40 +01:00
|
|
|
---
|
|
|
|
-- **NOTE**: You need either command or menu argument for widget to create
|
|
|
|
-- successfully
|
|
|
|
-- @tparam table args
|
|
|
|
-- @tparam image args.image The image to display on the launcher button (refer to `wibox.widget.imagebox`).
|
|
|
|
-- @tparam[opt] string args.command Command to run on user click.
|
|
|
|
-- @tparam[opt] table args.menu Table of items to create a menu based on `awful.menu`.
|
|
|
|
-- @treturn awful.widget.launcher A launcher widget.
|
2019-06-07 20:59:34 +02:00
|
|
|
-- @constructorfct awful.widget.launcher
|
2019-12-04 06:08:40 +01:00
|
|
|
-- @see wibox.widget.imagebox
|
|
|
|
-- @see awful.menu
|
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
|
|
|
|
|
|
|
|
if args.command then
|
2018-12-28 09:06:03 +01:00
|
|
|
w:add_button(button({}, 1, nil, function () spawn(args.command) end))
|
2009-02-27 17:22:03 +01:00
|
|
|
elseif args.menu then
|
2018-12-28 09:06:03 +01:00
|
|
|
w:add_button(button({}, 1, nil, function () args.menu:toggle() end))
|
2009-02-27 17:22:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
2012-06-14 01:08:27 +02:00
|
|
|
function launcher.mt:__call(...)
|
|
|
|
return launcher.new(...)
|
|
|
|
end
|
|
|
|
|
2019-12-22 06:53:57 +01:00
|
|
|
--@DOC_widget_COMMON@
|
|
|
|
|
|
|
|
--@DOC_object_COMMON@
|
|
|
|
|
2012-06-14 01:08:27 +02:00
|
|
|
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
|