From 8c717622fd7e1249e5f5991b2f5c4a611d5a53f8 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Wed, 25 Jun 2008 00:08:40 +0200 Subject: [PATCH] Put keybindings in arrays. Signed-off-by: Pierre Habouzit --- event.c | 6 ++++-- keybinding.c | 23 ++++++++++++++++------- structs.h | 10 +++++----- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/event.c b/event.c index f9d650405..057fd77a6 100644 --- a/event.c +++ b/event.c @@ -391,7 +391,6 @@ event_handle_keypress(void *data __attribute__ ((unused)), xcb_key_press_event_t *ev) { xcb_keysym_t keysym; - keybinding_t *k; if(globalconf.keygrabber != LUA_REFNIL) { @@ -412,10 +411,13 @@ event_handle_keypress(void *data __attribute__ ((unused)), { keysym = xcb_key_symbols_get_keysym(globalconf.keysyms, ev->detail, 0); - for(k = globalconf.keys; k; k = k->next) + for(int i = 0; i < globalconf.keys.len; i++) + { + keybinding_t *k = globalconf.keys.tab[i]; if(((k->keycode && ev->detail == k->keycode) || (k->keysym && keysym == k->keysym)) && k->fct && CLEANMASK(k->mod) == CLEANMASK(ev->state)) luaA_dofunction(globalconf.L, k->fct, 0); + } } return 0; diff --git a/keybinding.c b/keybinding.c index 788189eaf..94711d1c1 100644 --- a/keybinding.c +++ b/keybinding.c @@ -31,6 +31,11 @@ extern awesome_t globalconf; DO_LUA_NEW(static, keybinding_t, keybinding, "keybinding", keybinding_ref) DO_LUA_GC(keybinding_t, keybinding, "keybinding", keybinding_unref) +void keybinding_delete(keybinding_t **kbp) +{ + p_delete(kbp); +} + static void __luaA_keystore(keybinding_t *key, const char *str) { @@ -96,14 +101,14 @@ luaA_keybinding_new(lua_State *L) static int luaA_keybinding_add(lua_State *L) { - keybinding_t *key, **k = luaA_checkudata(L, 1, "keybinding"); + keybinding_t **k = luaA_checkudata(L, 1, "keybinding"); /* Check that the keybinding has not been already added. */ - for(key = globalconf.keys; key; key = key->next) - if(key == *k) + for(int i = 0; i < globalconf.keys.len; i++) + if(globalconf.keys.tab[i] == *k) luaL_error(L, "keybinding already added"); - keybinding_list_push(&globalconf.keys, keybinding_ref(k)); + keybinding_array_append(&globalconf.keys, keybinding_ref(k)); window_root_grabkey(*k); return 0; @@ -120,9 +125,13 @@ luaA_keybinding_remove(lua_State *L) { keybinding_t **k = luaA_checkudata(L, 1, "keybinding"); - keybinding_list_detach(&globalconf.keys, *k); - window_root_ungrabkey(*k); - keybinding_unref(k); + for(int i = 0; i < globalconf.keys.len; i++) + if(globalconf.keys.tab[i] == *k) + { + keybinding_array_take(&globalconf.keys, i); + window_root_ungrabkey(*k); + keybinding_unref(k); + } return 0; } diff --git a/structs.h b/structs.h index a31fabce0..70c62a7e9 100644 --- a/structs.h +++ b/structs.h @@ -206,6 +206,7 @@ titlebar_delete(titlebar_t **t) DO_RCNT(titlebar_t, titlebar, titlebar_delete) /** Keys bindings */ +ARRAY_TYPE(struct keybinding_t *, keybinding); struct keybinding_t { /** Ref count */ @@ -218,12 +219,11 @@ struct keybinding_t xcb_keycode_t keycode; /** Lua function to execute. */ luaA_function fct; - /** Next and previous keys */ - keybinding_t *prev, *next; }; -DO_SLIST(keybinding_t, keybinding, p_delete) -DO_RCNT(keybinding_t, keybinding, p_delete) +void keybinding_delete(keybinding_t **); +DO_RCNT(keybinding_t, keybinding, keybinding_delete) +ARRAY_FUNCS(keybinding_t *, keybinding, keybinding_unref) /** Status bar */ struct statusbar_t @@ -399,7 +399,7 @@ struct awesome_t /** Screens info */ screens_info_t *screens_info; /** Keys bindings list */ - keybinding_t *keys; + keybinding_array_t keys; /** Mouse bindings list */ struct {