Put keybindings in binary searchable arrays.
This patch sorts keybindings in arrays by keycode or keysym to speed up look
up using binary searches. This is a preliminary work to enable more powerful
keybindings stuff, where keybindings can be cascaded or why not, attached to
specific clients.
Interstingly enough, this patch saves 100ko of initial memory (Heap) usage here.
The underlying idea is that we should be able to define keybindings_t as
trees of keybindings_t which would then define key sequences.
The OO approach kind of make sense in fact, since you create a base
keybinding (e.g. reacting on Mod4-w) and then you will probably (with
appropriate apis) be able to populate new submaps from that point more or
less dynamically.
And if you have two keybindings on Mod4-w, then adding them will replace the
previous one. This means that you can fake per-client bindings with e.g.:
k_default = keybindings.new({"Mod4"}, "w", something);
k_mplayer = keybindings.new({"Mod4"}, "w", something_else);
k_default:add()
and in your focus hook:
if /* code for testing if it's mplayer */ then
k_mplayer:add()
else
k_default:add()
end
This would not work before, it does now.
It will take way more sense with submaps of course.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
2008-06-25 01:00:25 +02:00
|
|
|
/*
|
|
|
|
* keybinding.h - Keybinding helpers
|
|
|
|
*
|
|
|
|
* Copyright © 2008 Pierre Habouzit <madcoder@debian.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AWESOME_KEYBINDING_H
|
|
|
|
#define AWESOME_KEYBINDING_H
|
|
|
|
|
2008-06-30 22:49:10 +02:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include "lua.h"
|
|
|
|
|
2008-06-30 22:49:11 +02:00
|
|
|
typedef struct keybinding_t
|
2008-06-30 22:49:10 +02:00
|
|
|
{
|
|
|
|
/** Ref count */
|
|
|
|
int refcount;
|
|
|
|
/** Key modifier */
|
|
|
|
unsigned long mod;
|
|
|
|
/** Keysym */
|
|
|
|
xcb_keysym_t keysym;
|
|
|
|
/** Keycode */
|
|
|
|
xcb_keycode_t keycode;
|
|
|
|
/** Lua function to execute. */
|
2008-08-11 10:12:12 +02:00
|
|
|
luaA_ref fct;
|
2008-06-30 22:49:11 +02:00
|
|
|
} keybinding_t;
|
Put keybindings in binary searchable arrays.
This patch sorts keybindings in arrays by keycode or keysym to speed up look
up using binary searches. This is a preliminary work to enable more powerful
keybindings stuff, where keybindings can be cascaded or why not, attached to
specific clients.
Interstingly enough, this patch saves 100ko of initial memory (Heap) usage here.
The underlying idea is that we should be able to define keybindings_t as
trees of keybindings_t which would then define key sequences.
The OO approach kind of make sense in fact, since you create a base
keybinding (e.g. reacting on Mod4-w) and then you will probably (with
appropriate apis) be able to populate new submaps from that point more or
less dynamically.
And if you have two keybindings on Mod4-w, then adding them will replace the
previous one. This means that you can fake per-client bindings with e.g.:
k_default = keybindings.new({"Mod4"}, "w", something);
k_mplayer = keybindings.new({"Mod4"}, "w", something_else);
k_default:add()
and in your focus hook:
if /* code for testing if it's mplayer */ then
k_mplayer:add()
else
k_default:add()
end
This would not work before, it does now.
It will take way more sense with submaps of course.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
2008-06-25 01:00:25 +02:00
|
|
|
|
2008-06-30 22:49:10 +02:00
|
|
|
keybinding_t *keybinding_find(const xcb_key_press_event_t *);
|
Put keybindings in binary searchable arrays.
This patch sorts keybindings in arrays by keycode or keysym to speed up look
up using binary searches. This is a preliminary work to enable more powerful
keybindings stuff, where keybindings can be cascaded or why not, attached to
specific clients.
Interstingly enough, this patch saves 100ko of initial memory (Heap) usage here.
The underlying idea is that we should be able to define keybindings_t as
trees of keybindings_t which would then define key sequences.
The OO approach kind of make sense in fact, since you create a base
keybinding (e.g. reacting on Mod4-w) and then you will probably (with
appropriate apis) be able to populate new submaps from that point more or
less dynamically.
And if you have two keybindings on Mod4-w, then adding them will replace the
previous one. This means that you can fake per-client bindings with e.g.:
k_default = keybindings.new({"Mod4"}, "w", something);
k_mplayer = keybindings.new({"Mod4"}, "w", something_else);
k_default:add()
and in your focus hook:
if /* code for testing if it's mplayer */ then
k_mplayer:add()
else
k_default:add()
end
This would not work before, it does now.
It will take way more sense with submaps of course.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
2008-06-25 01:00:25 +02:00
|
|
|
|
|
|
|
#endif
|