2009-04-14 17:53:22 +02:00
|
|
|
---------------------------------------------------------------------------
|
2014-05-20 13:02:39 +02:00
|
|
|
--- Create easily new buttons objects ignoring certain modifiers.
|
|
|
|
--
|
2009-04-14 17:53:22 +02:00
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2009 Julien Danjou
|
2014-05-20 13:02:39 +02:00
|
|
|
-- @classmod awful.button
|
2009-04-14 17:53:22 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local ipairs = ipairs
|
|
|
|
local capi = { button = button }
|
2017-03-08 21:18:33 +01:00
|
|
|
local gmath = require("gears.math")
|
|
|
|
local gtable = require("gears.table")
|
2009-04-14 17:53:22 +02:00
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
local button = { mt = {} }
|
2009-04-14 17:53:22 +02:00
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
--- Modifiers to ignore.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
|
|
|
-- By default this is initialized as `{ "Lock", "Mod2" }`
|
|
|
|
-- so the `Caps Lock` or `Num Lock` modifier are not taking into account by awesome
|
2009-08-28 15:26:41 +02:00
|
|
|
-- when pressing keys.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
|
|
|
-- @table ignore_modifiers
|
2012-06-12 20:13:09 +02:00
|
|
|
local ignore_modifiers = { "Lock", "Mod2" }
|
2009-04-14 17:53:22 +02:00
|
|
|
|
|
|
|
--- Create a new button to use as binding.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
2009-04-14 17:53:22 +02:00
|
|
|
-- This function is useful to create several buttons from one, because it will use
|
|
|
|
-- the ignore_modifier variable to create more button with or without the ignored
|
|
|
|
-- modifiers activated.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
2009-04-14 17:53:22 +02:00
|
|
|
-- For example if you want to ignore CapsLock in your buttonbinding (which is
|
2009-08-28 15:26:41 +02:00
|
|
|
-- ignored by default by this function), creating button binding with this function
|
2009-04-14 17:53:22 +02:00
|
|
|
-- will return 2 button objects: one with CapsLock on, and the other one with
|
|
|
|
-- CapsLock off.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
|
|
|
-- @treturn table A table with one or several button objects.
|
2012-06-12 20:13:09 +02:00
|
|
|
function button.new(mod, _button, press, release)
|
2009-04-14 17:53:22 +02:00
|
|
|
local ret = {}
|
2017-03-08 21:18:33 +01:00
|
|
|
local subsets = gmath.subsets(ignore_modifiers)
|
2009-04-14 17:53:22 +02:00
|
|
|
for _, set in ipairs(subsets) do
|
2017-03-08 21:18:33 +01:00
|
|
|
ret[#ret + 1] = capi.button({ modifiers = gtable.join(mod, set),
|
2012-06-12 20:13:09 +02:00
|
|
|
button = _button })
|
2009-08-17 14:10:03 +02:00
|
|
|
if press then
|
2016-02-07 15:02:25 +01:00
|
|
|
ret[#ret]:connect_signal("press", function(_, ...) press(...) end)
|
2009-08-17 14:10:03 +02:00
|
|
|
end
|
|
|
|
if release then
|
2016-02-07 15:02:25 +01:00
|
|
|
ret[#ret]:connect_signal("release", function (_, ...) release(...) end)
|
2009-08-17 14:10:03 +02:00
|
|
|
end
|
2009-04-14 17:53:22 +02:00
|
|
|
end
|
2009-04-17 11:13:22 +02:00
|
|
|
return ret
|
2009-04-14 17:53:22 +02:00
|
|
|
end
|
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
function button.mt:__call(...)
|
|
|
|
return button.new(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(button, button.mt)
|
2009-04-14 17:53:22 +02:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|