From 29ccfbbf20f65eed2652049fb8c79a84fbbd303d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Fri, 4 Oct 2013 23:12:29 +0200 Subject: [PATCH] Avoid loop in keybinding check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch changes the keybinding check in cycling keyrelease. Now, the variable binding contains the keypressed, so we can check if the key pressed is the same than the keybinding. If the keybinding is different (user press other key) then finish. Without the loop, the code is faster. Then, the keybinding variable is not used anymore, and can be removed. Signed-off-by: Rodolfo García Peñas (kix) --- src/cycling.c | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/src/cycling.c b/src/cycling.c index 0ee39dbc..a6042714 100644 --- a/src/cycling.c +++ b/src/cycling.c @@ -80,7 +80,6 @@ static WWindow *change_focus_and_raise(WWindow *newFocused, WWindow *oldFocused, void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only) { - XModifierKeymap *keymap = NULL; WShortKey binding; WSwitchPanel *swpanel = NULL; WScreen *scr = wScreenForRootWindow(event->xkey.root); @@ -118,10 +117,8 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only) } hasModifier = (binding.modifier != 0); - if (hasModifier) { - keymap = XGetModifierMapping(dpy); + if (hasModifier) XGrabKeyboard(dpy, scr->root_win, False, GrabModeAsync, GrabModeAsync, CurrentTime); - } scr->flags.doing_alt_tab = 1; @@ -129,7 +126,6 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only) oldFocused = wwin; if (swpanel) { - if (wwin->flags.mapped && !wPreferences.panel_only_open) newFocused = wSwitchPanelSelectNext(swpanel, !next, True, False); else @@ -144,8 +140,6 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only) } while (hasModifier && !done) { - int i; - WMMaskEvent(dpy, KeyPressMask | KeyReleaseMask | ExposureMask | PointerMotionMask | ButtonReleaseMask | EnterWindowMask, &ev); @@ -156,9 +150,7 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only) break; switch (ev.type) { - case KeyPress: - if ((wKeyBindings[WKBD_FOCUSNEXT].keycode == ev.xkey.keycode && wKeyBindings[WKBD_FOCUSNEXT].modifier == modifiers) || (wKeyBindings[WKBD_GROUPNEXT].keycode == ev.xkey.keycode @@ -203,7 +195,6 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only) break; case KeyRelease: - if (ev.xkey.keycode == shiftLKey || ev.xkey.keycode == shiftRKey) if (wPreferences.strict_windoze_cycle) break; @@ -211,19 +202,9 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only) if (ev.xkey.keycode == XK_Return) break; - for (i = 0; i < 8 * keymap->max_keypermod; i++) { + if (ev.xkey.keycode != binding.keycode) + done = True; - int mask = 1 << (i / keymap->max_keypermod); - - if (keymap->modifiermap[i] == ev.xkey.keycode && - ((wKeyBindings[WKBD_FOCUSNEXT].modifier & mask) - || (wKeyBindings[WKBD_FOCUSPREV].modifier & mask) - || (wKeyBindings[WKBD_GROUPNEXT].modifier & mask) - || (wKeyBindings[WKBD_GROUPPREV].modifier & mask))) { - done = True; - break; - } - } break; case EnterNotify: @@ -253,13 +234,9 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only) break; } } - if (keymap) - XFreeModifiermap(keymap); - - if (hasModifier) { + if (hasModifier) XUngrabKeyboard(dpy, CurrentTime); - } if (swpanel) wSwitchPanelDestroy(swpanel);