1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 20:38:08 +01:00

Avoid loop in keybinding check

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) <kix@kix.es>
This commit is contained in:
Rodolfo García Peñas (kix)
2013-10-04 23:12:29 +02:00
committed by Carlos R. Mafra
parent 1d09b9fdcd
commit 29ccfbbf20

View File

@@ -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) void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only)
{ {
XModifierKeymap *keymap = NULL;
WShortKey binding; WShortKey binding;
WSwitchPanel *swpanel = NULL; WSwitchPanel *swpanel = NULL;
WScreen *scr = wScreenForRootWindow(event->xkey.root); 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); hasModifier = (binding.modifier != 0);
if (hasModifier) { if (hasModifier)
keymap = XGetModifierMapping(dpy);
XGrabKeyboard(dpy, scr->root_win, False, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabKeyboard(dpy, scr->root_win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
}
scr->flags.doing_alt_tab = 1; scr->flags.doing_alt_tab = 1;
@@ -129,7 +126,6 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only)
oldFocused = wwin; oldFocused = wwin;
if (swpanel) { if (swpanel) {
if (wwin->flags.mapped && !wPreferences.panel_only_open) if (wwin->flags.mapped && !wPreferences.panel_only_open)
newFocused = wSwitchPanelSelectNext(swpanel, !next, True, False); newFocused = wSwitchPanelSelectNext(swpanel, !next, True, False);
else else
@@ -144,8 +140,6 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only)
} }
while (hasModifier && !done) { while (hasModifier && !done) {
int i;
WMMaskEvent(dpy, KeyPressMask | KeyReleaseMask | ExposureMask WMMaskEvent(dpy, KeyPressMask | KeyReleaseMask | ExposureMask
| PointerMotionMask | ButtonReleaseMask | EnterWindowMask, &ev); | PointerMotionMask | ButtonReleaseMask | EnterWindowMask, &ev);
@@ -156,9 +150,7 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only)
break; break;
switch (ev.type) { switch (ev.type) {
case KeyPress: case KeyPress:
if ((wKeyBindings[WKBD_FOCUSNEXT].keycode == ev.xkey.keycode if ((wKeyBindings[WKBD_FOCUSNEXT].keycode == ev.xkey.keycode
&& wKeyBindings[WKBD_FOCUSNEXT].modifier == modifiers) && wKeyBindings[WKBD_FOCUSNEXT].modifier == modifiers)
|| (wKeyBindings[WKBD_GROUPNEXT].keycode == ev.xkey.keycode || (wKeyBindings[WKBD_GROUPNEXT].keycode == ev.xkey.keycode
@@ -203,7 +195,6 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only)
break; break;
case KeyRelease: case KeyRelease:
if (ev.xkey.keycode == shiftLKey || ev.xkey.keycode == shiftRKey) if (ev.xkey.keycode == shiftLKey || ev.xkey.keycode == shiftRKey)
if (wPreferences.strict_windoze_cycle) if (wPreferences.strict_windoze_cycle)
break; break;
@@ -211,19 +202,9 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only)
if (ev.xkey.keycode == XK_Return) if (ev.xkey.keycode == XK_Return)
break; 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; break;
case EnterNotify: case EnterNotify:
@@ -253,13 +234,9 @@ void StartWindozeCycle(WWindow *wwin, XEvent *event, Bool next, Bool class_only)
break; break;
} }
} }
if (keymap)
XFreeModifiermap(keymap);
if (hasModifier) {
if (hasModifier)
XUngrabKeyboard(dpy, CurrentTime); XUngrabKeyboard(dpy, CurrentTime);
}
if (swpanel) if (swpanel)
wSwitchPanelDestroy(swpanel); wSwitchPanelDestroy(swpanel);