awful.{key,button}: return a table

Fix a wrong assertian that actually:
function a() return 1, 2, 3 end
c = { a(), a() }
Won't make #c == 6 but c == 4 because only the last call to a() will
fill the table with 3 results.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-17 11:13:22 +02:00
parent ece9eb8874
commit 937cab0a30
3 changed files with 85 additions and 84 deletions

View File

@ -116,36 +116,39 @@ mywibox = {}
mypromptbox = {} mypromptbox = {}
mylayoutbox = {} mylayoutbox = {}
mytaglist = {} mytaglist = {}
mytaglist.buttons = { awful.button({ }, 1, awful.tag.viewonly), mytaglist.buttons = awful.util.table.join(
awful.button({ modkey }, 1, awful.client.movetotag), awful.button({ }, 1, awful.tag.viewonly),
awful.button({ }, 3, function (tag) tag.selected = not tag.selected end), awful.button({ modkey }, 1, awful.client.movetotag),
awful.button({ modkey }, 3, awful.client.toggletag), awful.button({ }, 3, function (tag) tag.selected = not tag.selected end),
awful.button({ }, 4, awful.tag.viewnext), awful.button({ modkey }, 3, awful.client.toggletag),
awful.button({ }, 5, awful.tag.viewprev) } awful.button({ }, 4, awful.tag.viewnext),
awful.button({ }, 5, awful.tag.viewprev)
)
mytasklist = {} mytasklist = {}
mytasklist.buttons = { awful.button({ }, 1, function (c) mytasklist.buttons = awful.util.table.join(
if not c:isvisible() then awful.button({ }, 1, function (c)
awful.tag.viewonly(c:tags()[1]) if not c:isvisible() then
end awful.tag.viewonly(c:tags()[1])
client.focus = c end
c:raise() client.focus = c
end), c:raise()
awful.button({ }, 3, function () end),
if instance then awful.button({ }, 3, function ()
instance:hide() if instance then
instance = nil instance:hide()
else instance = nil
instance = awful.menu.clients({ width=250 }) else
end instance = awful.menu.clients({ width=250 })
end), end
awful.button({ }, 4, function () end),
awful.client.focus.byidx(1) awful.button({ }, 4, function ()
if client.focus then client.focus:raise() end awful.client.focus.byidx(1)
end), if client.focus then client.focus:raise() end
awful.button({ }, 5, function () end),
awful.client.focus.byidx(-1) awful.button({ }, 5, function ()
if client.focus then client.focus:raise() end awful.client.focus.byidx(-1)
end) } if client.focus then client.focus:raise() end
end))
for s = 1, screen.count() do for s = 1, screen.count() do
-- Create a promptbox for each screen -- Create a promptbox for each screen
@ -153,10 +156,11 @@ for s = 1, screen.count() do
-- Create an imagebox widget which will contains an icon indicating which layout we're using. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
-- We need one layoutbox per screen. -- We need one layoutbox per screen.
mylayoutbox[s] = widget({ type = "imagebox", align = "right" }) mylayoutbox[s] = widget({ type = "imagebox", align = "right" })
mylayoutbox[s]:buttons({ awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end), mylayoutbox[s]:buttons(awful.util.table.join(
awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end), awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end), awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end) }) awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
-- Create a taglist widget -- Create a taglist widget
mytaglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, mytaglist.buttons) mytaglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, mytaglist.buttons)
@ -180,16 +184,15 @@ end
-- }}} -- }}}
-- {{{ Mouse bindings -- {{{ Mouse bindings
root.buttons({ root.buttons(awful.util.table.join(
awful.button({ }, 3, function () mymainmenu:toggle() end), awful.button({ }, 3, function () mymainmenu:toggle() end),
awful.button({ }, 4, awful.tag.viewnext), awful.button({ }, 4, awful.tag.viewnext),
awful.button({ }, 5, awful.tag.viewprev) awful.button({ }, 5, awful.tag.viewprev)
}) ))
-- }}} -- }}}
-- {{{ Key bindings -- {{{ Key bindings
globalkeys = globalkeys = awful.util.table.join(
{
awful.key({ modkey, }, "Left", awful.tag.viewprev ), awful.key({ modkey, }, "Left", awful.tag.viewprev ),
awful.key({ modkey, }, "Right", awful.tag.viewnext ), awful.key({ modkey, }, "Right", awful.tag.viewnext ),
awful.key({ modkey, }, "Escape", awful.tag.history.restore), awful.key({ modkey, }, "Escape", awful.tag.history.restore),
@ -249,12 +252,11 @@ globalkeys =
mypromptbox[mouse.screen], mypromptbox[mouse.screen],
awful.util.eval, nil, awful.util.eval, nil,
awful.util.getdir("cache") .. "/history_eval") awful.util.getdir("cache") .. "/history_eval")
end), end)
} )
-- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
clientkeys = clientkeys = awful.util.table.join(
{
awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end), awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end), awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ), awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
@ -266,8 +268,8 @@ clientkeys =
function (c) function (c)
c.maximized_horizontal = not c.maximized_horizontal c.maximized_horizontal = not c.maximized_horizontal
c.maximized_vertical = not c.maximized_vertical c.maximized_vertical = not c.maximized_vertical
end), end)
} )
-- Compute the maximum number of digit we need, limited to 9 -- Compute the maximum number of digit we need, limited to 9
keynumber = 0 keynumber = 0
@ -276,44 +278,43 @@ for s = 1, screen.count() do
end end
for i = 1, keynumber do for i = 1, keynumber do
table.foreach({ awful.key({ modkey }, i, table.foreach(awful.key({ modkey }, i,
function () function ()
local screen = mouse.screen local screen = mouse.screen
if tags[screen][i] then if tags[screen][i] then
awful.tag.viewonly(tags[screen][i]) awful.tag.viewonly(tags[screen][i])
end
end), function(_, k) table.insert(globalkeys, k) end)
table.foreach(awful.key({ modkey, "Control" }, i,
function ()
local screen = mouse.screen
if tags[screen][i] then
tags[screen][i].selected = not tags[screen][i].selected
end
end), function(_, k) table.insert(globalkeys, k) end)
table.foreach(awful.key({ modkey, "Shift" }, i,
function ()
if client.focus and tags[client.focus.screen][i] then
awful.client.movetotag(tags[client.focus.screen][i])
end
end), function(_, k) table.insert(globalkeys, k) end)
table.foreach(awful.key({ modkey, "Control", "Shift" }, i,
function ()
if client.focus and tags[client.focus.screen][i] then
awful.client.toggletag(tags[client.focus.screen][i])
end
end), function(_, k) table.insert(globalkeys, k) end)
table.foreach(awful.key({ modkey, "Shift" }, "F" .. i,
function ()
local screen = mouse.screen
if tags[screen][i] then
for k, c in pairs(awful.client.getmarked()) do
awful.client.movetotag(tags[screen][i], c)
end end
end) }, function(_, k) table.insert(globalkeys, k) end) end
table.foreach({ awful.key({ modkey, "Control" }, i, end), function(_, k) table.insert(globalkeys, k) end)
function ()
local screen = mouse.screen
if tags[screen][i] then
tags[screen][i].selected = not tags[screen][i].selected
end
end) }, function(_, k) table.insert(globalkeys, k) end)
table.foreach({ awful.key({ modkey, "Shift" }, i,
function ()
if client.focus and tags[client.focus.screen][i] then
awful.client.movetotag(tags[client.focus.screen][i])
end
end) }, function(_, k) table.insert(globalkeys, k) end)
table.foreach({ awful.key({ modkey, "Control", "Shift" }, i,
function ()
if client.focus and tags[client.focus.screen][i] then
awful.client.toggletag(tags[client.focus.screen][i])
end
end) }, function(_, k) table.insert(globalkeys, k) end)
table.foreach({ awful.key({ modkey, "Shift" }, "F" .. i,
function ()
local screen = mouse.screen
if tags[screen][i] then
for k, c in pairs(awful.client.getmarked()) do
awful.client.movetotag(tags[screen][i], c)
end
end
end) }, function(_, k) table.insert(globalkeys, k) end)
end end
-- Set keys -- Set keys
root.keys(globalkeys) root.keys(globalkeys)
-- }}} -- }}}
@ -366,11 +367,11 @@ awful.hooks.manage.register(function (c, startup)
awful.titlebar.add(c, { modkey = modkey }) awful.titlebar.add(c, { modkey = modkey })
end end
-- Add mouse bindings -- Add mouse bindings
c:buttons({ c:buttons(awful.util.table.join(
awful.button({ }, 1, function (c) client.focus = c; c:raise() end), awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
awful.button({ modkey }, 1, awful.mouse.client.move), awful.button({ modkey }, 1, awful.mouse.client.move),
awful.button({ modkey }, 3, awful.mouse.client.resize) awful.button({ modkey }, 3, awful.mouse.client.resize)
}) ))
-- New client may not receive focus -- New client may not receive focus
-- if they're not focusable, so set border anyway. -- if they're not focusable, so set border anyway.
c.border_width = beautiful.border_width c.border_width = beautiful.border_width

View File

@ -26,14 +26,14 @@ ignore_modifiers = { "Lock", "Mod2" }
-- will return 2 button objects: one with CapsLock on, and the other one with -- will return 2 button objects: one with CapsLock on, and the other one with
-- CapsLock off. -- CapsLock off.
-- @see C api button() function for parameters. -- @see C api button() function for parameters.
-- @return One or several button objects. -- @return A table with one or several button objects.
local function new(_, mod, ...) local function new(_, mod, ...)
local ret = {} local ret = {}
local subsets = util.subsets(ignore_modifiers) local subsets = util.subsets(ignore_modifiers)
for _, set in ipairs(subsets) do for _, set in ipairs(subsets) do
ret[#ret + 1] = capi.button(util.table.join(mod, set), unpack(arg)) ret[#ret + 1] = capi.button(util.table.join(mod, set), unpack(arg))
end end
return unpack(ret) return ret
end end
setmetatable(_M, { __call = new }) setmetatable(_M, { __call = new })

View File

@ -26,14 +26,14 @@ ignore_modifiers = { "Lock", "Mod2" }
-- will return 2 key objects: one with CapsLock on, and the other one with -- will return 2 key objects: one with CapsLock on, and the other one with
-- CapsLock off. -- CapsLock off.
-- @see C api key() function for parameters. -- @see C api key() function for parameters.
-- @return One or several key objects. -- @return A table with one or several key objects.
local function new(_, mod, ...) local function new(_, mod, ...)
local ret = {} local ret = {}
local subsets = util.subsets(ignore_modifiers) local subsets = util.subsets(ignore_modifiers)
for _, set in ipairs(subsets) do for _, set in ipairs(subsets) do
ret[#ret + 1] = capi.key(util.table.join(mod, set), unpack(arg)) ret[#ret + 1] = capi.key(util.table.join(mod, set), unpack(arg))
end end
return unpack(ret) return ret
end end
setmetatable(_M, { __call = new }) setmetatable(_M, { __call = new })