key: stop ignoring arbitrary modifier

Before, we used to ignore Mod2 and Lock.
This is now configurable.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-14 17:53:22 +02:00
parent 0215aa5b42
commit 1a18088da5
9 changed files with 222 additions and 161 deletions

View File

@ -116,29 +116,36 @@ mywibox = {}
mypromptbox = {}
mylayoutbox = {}
mytaglist = {}
mytaglist.buttons = { button({ }, 1, awful.tag.viewonly),
button({ modkey }, 1, awful.client.movetotag),
button({ }, 3, function (tag) tag.selected = not tag.selected end),
button({ modkey }, 3, awful.client.toggletag),
button({ }, 4, awful.tag.viewnext),
button({ }, 5, awful.tag.viewprev) }
mytaglist.buttons = { awful.button({ }, 1, awful.tag.viewonly),
awful.button({ modkey }, 1, awful.client.movetotag),
awful.button({ }, 3, function (tag) tag.selected = not tag.selected end),
awful.button({ modkey }, 3, awful.client.toggletag),
awful.button({ }, 4, awful.tag.viewnext),
awful.button({ }, 5, awful.tag.viewprev) }
mytasklist = {}
mytasklist.buttons = { button({ }, 1, function (c)
if not c:isvisible() then
awful.tag.viewonly(c:tags()[1])
end
client.focus = c
c:raise()
end),
button({ }, 3, function () if instance then instance:hide() instance = nil else instance = awful.menu.clients({ width=250 }) end end),
button({ }, 4, function ()
awful.client.focus.byidx(1)
if client.focus then client.focus:raise() end
end),
button({ }, 5, function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end) }
mytasklist.buttons = { awful.button({ }, 1, function (c)
if not c:isvisible() then
awful.tag.viewonly(c:tags()[1])
end
client.focus = c
c:raise()
end),
awful.button({ }, 3, function ()
if instance then
instance:hide()
instance = nil
else
instance = awful.menu.clients({ width=250 })
end
end),
awful.button({ }, 4, function ()
awful.client.focus.byidx(1)
if client.focus then client.focus:raise() end
end),
awful.button({ }, 5, function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end) }
for s = 1, screen.count() do
-- Create a promptbox for each screen
@ -146,10 +153,10 @@ for s = 1, screen.count() do
-- Create an imagebox widget which will contains an icon indicating which layout we're using.
-- We need one layoutbox per screen.
mylayoutbox[s] = widget({ type = "imagebox", align = "right" })
mylayoutbox[s]:buttons({ button({ }, 1, function () awful.layout.inc(layouts, 1) end),
button({ }, 3, function () awful.layout.inc(layouts, -1) end),
button({ }, 4, function () awful.layout.inc(layouts, 1) end),
button({ }, 5, function () awful.layout.inc(layouts, -1) end) })
mylayoutbox[s]:buttons({ awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
awful.button({ }, 3, 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
mytaglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, mytaglist.buttons)
@ -174,38 +181,38 @@ end
-- {{{ Mouse bindings
root.buttons({
button({ }, 3, function () mymainmenu:toggle() end),
button({ }, 4, awful.tag.viewnext),
button({ }, 5, awful.tag.viewprev)
awful.button({ }, 3, function () mymainmenu:toggle() end),
awful.button({ }, 4, awful.tag.viewnext),
awful.button({ }, 5, awful.tag.viewprev)
})
-- }}}
-- {{{ Key bindings
globalkeys =
{
key({ modkey, }, "Left", awful.tag.viewprev ),
key({ modkey, }, "Right", awful.tag.viewnext ),
key({ modkey, }, "Escape", awful.tag.history.restore),
awful.key({ modkey, }, "Left", awful.tag.viewprev ),
awful.key({ modkey, }, "Right", awful.tag.viewnext ),
awful.key({ modkey, }, "Escape", awful.tag.history.restore),
key({ modkey, }, "j",
awful.key({ modkey, }, "j",
function ()
awful.client.focus.byidx( 1)
if client.focus then client.focus:raise() end
end),
key({ modkey, }, "k",
awful.key({ modkey, }, "k",
function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end),
key({ modkey, }, "w", function () mymainmenu:show(true) end),
awful.key({ modkey, }, "w", function () mymainmenu:show(true) end),
-- Layout manipulation
key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
key({ modkey, "Control" }, "j", function () awful.screen.focus( 1) end),
key({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end),
key({ modkey, }, "u", awful.client.urgent.jumpto),
key({ modkey, }, "Tab",
awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
awful.key({ modkey, "Control" }, "j", function () awful.screen.focus( 1) end),
awful.key({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end),
awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
awful.key({ modkey, }, "Tab",
function ()
awful.client.focus.history.previous()
if client.focus then
@ -214,48 +221,48 @@ globalkeys =
end),
-- Standard program
key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
key({ modkey, "Control" }, "r", awesome.restart),
key({ modkey, "Shift" }, "q", awesome.quit),
awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
awful.key({ modkey, "Control" }, "r", awesome.restart),
awful.key({ modkey, "Shift" }, "q", awesome.quit),
key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
-- Prompt
key({ modkey }, "F1",
function ()
awful.prompt.run({ prompt = "Run: " },
mypromptbox[mouse.screen],
awful.util.spawn, awful.completion.shell,
awful.util.getdir("cache") .. "/history")
end),
awful.key({ modkey }, "F1",
function ()
awful.prompt.run({ prompt = "Run: " },
mypromptbox[mouse.screen],
awful.util.spawn, awful.completion.shell,
awful.util.getdir("cache") .. "/history")
end),
key({ modkey }, "F4",
function ()
awful.prompt.run({ prompt = "Run Lua code: " },
mypromptbox[mouse.screen],
awful.util.eval, nil,
awful.util.getdir("cache") .. "/history_eval")
end),
awful.key({ modkey }, "F4",
function ()
awful.prompt.run({ prompt = "Run Lua code: " },
mypromptbox[mouse.screen],
awful.util.eval, nil,
awful.util.getdir("cache") .. "/history_eval")
end),
}
-- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
clientkeys =
{
key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
key({ modkey, "Shift" }, "c", function (c) c:kill() end),
key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
key({ modkey, }, "o", awful.client.movetoscreen ),
key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
key({ modkey }, "t", awful.client.togglemarked),
key({ modkey,}, "m",
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, "Control" }, "space", awful.client.floating.toggle ),
awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
awful.key({ modkey, }, "o", awful.client.movetoscreen ),
awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
awful.key({ modkey }, "t", awful.client.togglemarked),
awful.key({ modkey,}, "m",
function (c)
c.maximized_horizontal = not c.maximized_horizontal
c.maximized_vertical = not c.maximized_vertical
@ -269,46 +276,41 @@ for s = 1, screen.count() do
end
for i = 1, keynumber do
table.insert(globalkeys,
key({ modkey }, i,
function ()
local screen = mouse.screen
if tags[screen][i] then
awful.tag.viewonly(tags[screen][i])
end
end))
table.insert(globalkeys,
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))
table.insert(globalkeys,
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))
table.insert(globalkeys,
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))
table.insert(globalkeys,
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))
table.foreach({ awful.key({ modkey }, i,
function ()
local screen = mouse.screen
if tags[screen][i] then
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
@ -365,9 +367,9 @@ awful.hooks.manage.register(function (c, startup)
end
-- Add mouse bindings
c:buttons({
button({ }, 1, function (c) client.focus = c; c:raise() end),
button({ modkey }, 1, awful.mouse.client.move),
button({ modkey }, 3, awful.mouse.client.resize)
awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
awful.button({ modkey }, 1, awful.mouse.client.move),
awful.button({ modkey }, 3, awful.mouse.client.resize)
})
-- New client may not receive focus
-- if they're not focusable, so set border anyway.

View File

@ -32,8 +32,6 @@
#include "array.h"
#define XUTIL_MASK_CLEAN(mask) (mask & ~(XCB_MOD_MASK_LOCK | XCB_MOD_MASK_2))
bool xutil_text_prop_get(xcb_connection_t *, xcb_window_t, xcb_atom_t, char **, ssize_t *);
/** Set the same handler for all errors */

View File

@ -57,7 +57,7 @@ event_handle_mouse_button(client_t *c,
{
for(int i = 0; i < buttons->len; i++)
if(button == buttons->tab[i]->button
&& XUTIL_MASK_CLEAN(state) == buttons->tab[i]->mod)
&& state == buttons->tab[i]->mod)
switch(type)
{
case XCB_BUTTON_PRESS:
@ -147,7 +147,7 @@ event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_e
for(int i = 0; i < b->len; i++)
if(ev->detail == b->tab[i]->button
&& XUTIL_MASK_CLEAN(ev->state) == b->tab[i]->mod)
&& ev->state == b->tab[i]->mod)
switch(ev->response_type)
{
case XCB_BUTTON_PRESS:
@ -177,7 +177,7 @@ event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_e
for(int i = 0; i < b->len; i++)
if(ev->detail == b->tab[i]->button
&& XUTIL_MASK_CLEAN(ev->state) == b->tab[i]->mod)
&& ev->state == b->tab[i]->mod)
switch(ev->response_type)
{
case XCB_BUTTON_PRESS:

24
key.c
View File

@ -91,20 +91,6 @@ key_cmp(const keyb_t *k1, const keyb_t *k2)
return k1->mod == k2->mod ? 0 : (k2->mod > k1->mod ? 1 : -1);
}
static void
window_grabkey_keycode(xcb_window_t win, uint16_t mod, xcb_keycode_t kc)
{
xcb_grab_key(globalconf.connection, true, win,
mod, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
xcb_grab_key(globalconf.connection, true, win,
mod | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
xcb_grab_key(globalconf.connection, true, win,
mod | XCB_MOD_MASK_2, kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
xcb_grab_key(globalconf.connection, true, win,
mod | XCB_MOD_MASK_2 | XCB_MOD_MASK_LOCK, kc, XCB_GRAB_MODE_ASYNC,
XCB_GRAB_MODE_ASYNC);
}
/** Grab key on a window.
* \param win The window.
* \param k The key.
@ -113,14 +99,16 @@ static void
window_grabkey(xcb_window_t win, keyb_t *k)
{
if(k->keycode)
window_grabkey_keycode(win, k->mod, k->keycode);
xcb_grab_key(globalconf.connection, true, win,
k->mod, k->keycode, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
else if(k->keysym)
{
xcb_keycode_t *keycodes = xcb_key_symbols_get_keycode(globalconf.keysyms, k->keysym);
if(keycodes)
{
for(xcb_keycode_t *kc = keycodes; *kc; kc++)
window_grabkey_keycode(win, k->mod, *kc);
xcb_grab_key(globalconf.connection, true, win,
k->mod, *kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
p_delete(&keycodes);
}
}
@ -243,7 +231,7 @@ keyb_t *
key_find(keybindings_t *keys, const xcb_key_press_event_t *ev)
{
const key_array_t *arr = &keys->by_sym;
int l, r, mod = XUTIL_MASK_CLEAN(ev->state);
int l, r;
xcb_keysym_t keysym;
/* get keysym ignoring shift and mod5 */
@ -255,7 +243,7 @@ key_find(keybindings_t *keys, const xcb_key_press_event_t *ev)
while(l < r)
{
int i = (r + l) / 2;
switch(key_ev_cmp(keysym, ev->detail, mod, arr->tab[i]))
switch(key_ev_cmp(keysym, ev->detail, ev->state, arr->tab[i]))
{
case -1: /* ev < arr->tab[i] */
r = i;

View File

@ -690,28 +690,28 @@ keygrabber_handlekpress(lua_State *L, xcb_key_press_event_t *e)
lua_newtable(L);
lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_CONTROL);
lua_pushboolean(L, e->state & XCB_MOD_MASK_CONTROL);
lua_setfield(L, -2, "Control");
lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_LOCK);
lua_pushboolean(L, e->state & XCB_MOD_MASK_LOCK);
lua_setfield(L, -2, "Lock");
lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_SHIFT);
lua_pushboolean(L, e->state & XCB_MOD_MASK_SHIFT);
lua_setfield(L, -2, "Shift");
lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_1);
lua_pushboolean(L, e->state & XCB_MOD_MASK_1);
lua_setfield(L, -2, "Mod1");
lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_2);
lua_pushboolean(L, e->state & XCB_MOD_MASK_2);
lua_setfield(L, -2, "Mod2");
lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_3);
lua_pushboolean(L, e->state & XCB_MOD_MASK_3);
lua_setfield(L, -2, "Mod3");
lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_4);
lua_pushboolean(L, e->state & XCB_MOD_MASK_4);
lua_setfield(L, -2, "Mod4");
lua_pushboolean(L, XUTIL_MASK_CLEAN(e->state) & XCB_MOD_MASK_5);
lua_pushboolean(L, e->state & XCB_MOD_MASK_5);
lua_setfield(L, -2, "Mod5");
lua_pushstring(L, buf);

41
lib/awful/button.lua.in Normal file
View File

@ -0,0 +1,41 @@
---------------------------------------------------------------------------
-- @author Julien Danjou &lt;julien@danjou.info&gt;
-- @copyright 2009 Julien Danjou
-- @release @AWESOME_VERSION@
---------------------------------------------------------------------------
-- Grab environment we need
local setmetatable = setmetatable
local ipairs = ipairs
local unpack = unpack
local capi = { button = button }
local util = require("awful.util")
--- Button helper for awful
module("awful.button")
--- Modifiers to ignore
ignore_modifiers = { "Lock", "Mod2" }
--- Create a new button to use as binding.
-- 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.
-- For example if you want to ignore CapsLock in your buttonbinding (which is
-- ignored by default by this function), creatina button binding with this function
-- will return 2 button objects: one with CapsLock on, and the other one with
-- CapsLock off.
-- @see C api button() function for parameters.
-- @return One or several button objects.
local function new(_, mod, ...)
local ret = {}
local subsets = util.subsets(ignore_modifiers)
for _, set in ipairs(subsets) do
ret[#ret + 1] = capi.button(util.table.concat(mod, set), unpack(arg))
end
return unpack(ret)
end
setmetatable(_M, { __call = new })
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -18,6 +18,8 @@ require("awful.widget")
require("awful.menu")
require("awful.mouse")
require("awful.remote")
require("awful.key")
require("awful.button")
require("awful.startup_notification")
--- AWesome Functions very UsefuL

41
lib/awful/key.lua.in Normal file
View File

@ -0,0 +1,41 @@
---------------------------------------------------------------------------
-- @author Julien Danjou &lt;julien@danjou.info&gt;
-- @copyright 2009 Julien Danjou
-- @release @AWESOME_VERSION@
---------------------------------------------------------------------------
-- Grab environment we need
local setmetatable = setmetatable
local ipairs = ipairs
local unpack = unpack
local capi = { key = key }
local util = require("awful.util")
--- Key helper for awful
module("awful.key")
--- Modifiers to ignore
ignore_modifiers = { "Lock", "Mod2" }
--- Create a new key to use as binding.
-- This function is useful to create several keys from one, because it will use
-- the ignore_modifier variable to create more key with or without the ignored
-- modifiers activated.
-- For example if you want to ignore CapsLock in your keybinding (which is
-- ignored by default by this function), creatina key binding with this function
-- will return 2 key objects: one with CapsLock on, and the other one with
-- CapsLock off.
-- @see C api key() function for parameters.
-- @return One or several key objects.
local function new(_, mod, ...)
local ret = {}
local subsets = util.subsets(ignore_modifiers)
for _, set in ipairs(subsets) do
ret[#ret + 1] = capi.key(util.table.concat(mod, set), unpack(arg))
end
return unpack(ret)
end
setmetatable(_M, { __call = new })
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -105,21 +105,10 @@ window_configure(xcb_window_t win, area_t geometry, int border)
void
window_buttons_grab(xcb_window_t win, button_array_t *buttons)
{
for(int i = 0; i < buttons->len; i++)
{
foreach(b, *buttons)
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
buttons->tab[i]->button, buttons->tab[i]->mod);
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
buttons->tab[i]->button, buttons->tab[i]->mod | XCB_MOD_MASK_LOCK);
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
buttons->tab[i]->button, buttons->tab[i]->mod | XCB_MOD_MASK_2);
xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
buttons->tab[i]->button, buttons->tab[i]->mod | XCB_MOD_MASK_2 | XCB_MOD_MASK_LOCK);
}
(*b)->button, (*b)->mod);
}
/** Get the opacity of a window.