From 5daab0fb472f85a22736551782cc7aee3ee845a6 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 31 Aug 2009 13:54:36 +0200 Subject: [PATCH] key: move grabbing code to window Signed-off-by: Julien Danjou --- key.c | 30 ------------------------------ key.h | 1 - root.c | 1 + window.c | 30 ++++++++++++++++++++++++++++++ window.h | 1 + 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/key.c b/key.c index cc8587b0d..9be9cd759 100644 --- a/key.c +++ b/key.c @@ -32,36 +32,6 @@ #include "common/xutil.h" #include "common/luaobject.h" -/** Grab key on a window. - * \param win The window. - * \param k The key. - */ -static void -window_grabkey(xcb_window_t win, keyb_t *k) -{ - if(k->keycode) - xcb_grab_key(globalconf.connection, true, win, - k->modifiers, 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++) - xcb_grab_key(globalconf.connection, true, win, - k->modifiers, *kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); - p_delete(&keycodes); - } - } -} - -void -window_grabkeys(xcb_window_t win, key_array_t *keys) -{ - foreach(k, *keys) - window_grabkey(win, *k); -} - /** XCB equivalent of XLookupString which translate the keycode given * by PressEvent to a KeySym and a string * \todo use XKB! diff --git a/key.h b/key.h index 86c37c110..220530037 100644 --- a/key.h +++ b/key.h @@ -47,7 +47,6 @@ xcb_keysym_t key_getkeysym(xcb_keycode_t, uint16_t); void luaA_key_array_set(lua_State *, int, int, key_array_t *); int luaA_key_array_get(lua_State *, int, key_array_t *); -void window_grabkeys(xcb_window_t, key_array_t *); int luaA_pushmodifiers(lua_State *, uint16_t); uint16_t luaA_tomodifiers(lua_State *L, int ud); diff --git a/root.c b/root.c index 88cef01fe..b91067a23 100644 --- a/root.c +++ b/root.c @@ -25,6 +25,7 @@ #include "button.h" #include "wibox.h" #include "luaa.h" +#include "window.h" #include "common/xcursor.h" #include "common/tokenize.h" #include "common/xutil.h" diff --git a/window.c b/window.c index 23ce5e0a5..5e9c73469 100644 --- a/window.c +++ b/window.c @@ -109,6 +109,36 @@ window_buttons_grab(xcb_window_t win, button_array_t *buttons) (*b)->button, (*b)->modifiers); } +/** Grab key on a window. + * \param win The window. + * \param k The key. + */ +static void +window_grabkey(xcb_window_t win, keyb_t *k) +{ + if(k->keycode) + xcb_grab_key(globalconf.connection, true, win, + k->modifiers, 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++) + xcb_grab_key(globalconf.connection, true, win, + k->modifiers, *kc, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); + p_delete(&keycodes); + } + } +} + +void +window_grabkeys(xcb_window_t win, key_array_t *keys) +{ + foreach(k, *keys) + window_grabkey(win, *k); +} + /** Get the opacity of a window. * \param win The window. * \return The opacity, between 0 and 1 or -1 or no opacity set. diff --git a/window.h b/window.h index d606736d1..09214e0ea 100644 --- a/window.h +++ b/window.h @@ -33,6 +33,7 @@ double window_opacity_get(xcb_window_t); double window_opacity_get_from_reply(xcb_get_property_reply_t *); void window_opacity_set(xcb_window_t, double); void window_grabbuttons(xcb_window_t, xcb_window_t, button_array_t *); +void window_grabkeys(xcb_window_t, key_array_t *); void window_takefocus(xcb_window_t); void window_set_cursor(xcb_window_t, xcb_cursor_t);