From 06ac655b8dda53aa2122844d487ed68510211395 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 16 Sep 2021 23:20:57 +1000 Subject: WM: expose the "any" state of KeyMapItem modifiers Change KeyMapItem.alt/ctrl/shift/oskey to integer types, where -1 is used to ignore the modifier when matching key-map items. It was only possible to set all modifiers to -1 at once from RNA using the 'any' property. Afterwards individual modifiers could be set back to true/false. Although these key-map items could not be exported/imported. Exposing the values directly avoids the need for cumbersome workarounds. --- source/blender/windowmanager/intern/wm_keymap.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_keymap.c') diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index bcd21fd7ac3..f955abaed53 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -484,10 +484,20 @@ static void keymap_event_set( kmi->shift = kmi->ctrl = kmi->alt = kmi->oskey = KM_ANY; } else { - kmi->shift = (modifier & KM_SHIFT) ? KM_MOD_HELD : KM_NOTHING; - kmi->ctrl = (modifier & KM_CTRL) ? KM_MOD_HELD : KM_NOTHING; - kmi->alt = (modifier & KM_ALT) ? KM_MOD_HELD : KM_NOTHING; - kmi->oskey = (modifier & KM_OSKEY) ? KM_MOD_HELD : KM_NOTHING; + /* Only one of the flags should be set. */ + BLI_assert(((modifier & (KM_SHIFT | KM_SHIFT_ANY)) != (KM_SHIFT | KM_SHIFT_ANY)) && + ((modifier & (KM_CTRL | KM_CTRL_ANY)) != (KM_CTRL | KM_CTRL_ANY)) && + ((modifier & (KM_ALT | KM_ALT_ANY)) != (KM_ALT | KM_ALT_ANY)) && + ((modifier & (KM_OSKEY | KM_OSKEY_ANY)) != (KM_OSKEY | KM_OSKEY_ANY))); + + kmi->shift = ((modifier & KM_SHIFT) ? KM_MOD_HELD : + ((modifier & KM_SHIFT_ANY) ? KM_ANY : KM_NOTHING)); + kmi->ctrl = ((modifier & KM_CTRL) ? KM_MOD_HELD : + ((modifier & KM_CTRL_ANY) ? KM_ANY : KM_NOTHING)); + kmi->alt = ((modifier & KM_ALT) ? KM_MOD_HELD : + ((modifier & KM_ALT_ANY) ? KM_ANY : KM_NOTHING)); + kmi->oskey = ((modifier & KM_OSKEY) ? KM_MOD_HELD : + ((modifier & KM_OSKEY_ANY) ? KM_ANY : KM_NOTHING)); } } -- cgit v1.2.3