WM: improve support for binding actions to modifier keys
authorCampbell Barton <ideasman42@gmail.com>
Fri, 1 Mar 2019 05:46:10 +0000 (16:46 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 1 Mar 2019 05:59:28 +0000 (16:59 +1100)
Previously a modifier key-map type only worked when the same key was
enabled as a modifier as well.

This allows for users to assign an action to double-tap-shift for eg.

source/blender/windowmanager/intern/wm_event_system.c

index ebf09af..139e1a5 100644 (file)
@@ -1886,24 +1886,33 @@ static bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi)
                }
        }
 
-       /* modifiers also check bits, so it allows modifier order */
+       /* Modifiers also check bits, so it allows modifier order.
+        * Account for rare case of when these keys are used as the 'type' not as modifiers. */
        if (kmi->shift != KM_ANY) {
-               if (winevent->shift != kmi->shift && !(winevent->shift & kmi->shift)) {
+               if ((winevent->shift != kmi->shift) && !(winevent->shift & kmi->shift) &&
+                   !ELEM(winevent->type, LEFTSHIFTKEY, RIGHTSHIFTKEY))
+               {
                        return false;
                }
        }
        if (kmi->ctrl != KM_ANY) {
-               if (winevent->ctrl != kmi->ctrl && !(winevent->ctrl & kmi->ctrl)) {
+               if (winevent->ctrl != kmi->ctrl && !(winevent->ctrl & kmi->ctrl) &&
+                   !ELEM(winevent->type, LEFTCTRLKEY, RIGHTCTRLKEY))
+               {
                        return false;
                }
        }
        if (kmi->alt != KM_ANY) {
-               if (winevent->alt != kmi->alt && !(winevent->alt & kmi->alt)) {
+               if (winevent->alt != kmi->alt && !(winevent->alt & kmi->alt) &&
+                   !ELEM(winevent->type, LEFTALTKEY, RIGHTALTKEY))
+               {
                        return false;
                }
        }
        if (kmi->oskey != KM_ANY) {
-               if (winevent->oskey != kmi->oskey && !(winevent->oskey & kmi->oskey)) {
+               if (winevent->oskey != kmi->oskey && !(winevent->oskey & kmi->oskey) &&
+                   (winevent->type != OSKEY))
+               {
                        return false;
                }
        }