diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-12-12 13:39:55 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-12-12 13:43:26 +0300 |
commit | 4357fb63db77d8bee9b1a3d10fdf6abd55e4c798 (patch) | |
tree | 477adefe8069f2e09d091086fbf4bfb2968878fd /source/blender/windowmanager/intern | |
parent | adaadb2fa0a4fde53f5f09bc05f6758926e71f44 (diff) |
Keymap: event type filter w/ finding keymap items
Now its possibly to ask for only keyboard/mouse/ndof events
when finding key map items.
Diffstat (limited to 'source/blender/windowmanager/intern')
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 48 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_keymap.c | 21 |
2 files changed, 62 insertions, 7 deletions
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 58773bd4283..81544c2de62 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -3534,6 +3534,54 @@ bool WM_event_is_modal_tweak_exit(const wmEvent *event, int tweak_event) return 0; } +bool WM_event_type_mask_test(const int event_type, const enum eEventType_Mask mask) +{ + /* Keyboard. */ + if (mask & EVT_TYPE_MASK_KEYBOARD) { + if (ISKEYBOARD(event_type)) { + return true; + } + } + else if (mask & EVT_TYPE_MASK_KEYBOARD_MODIFIER) { + if (ISKEYMODIFIER(event_type)) { + return true; + } + } + + /* Mouse. */ + if (mask & EVT_TYPE_MASK_MOUSE) { + if (ISMOUSE(event_type)) { + return true; + } + } + else if (mask & EVT_TYPE_MASK_MOUSE_WHEEL) { + if (ISMOUSE_WHEEL(event_type)) { + return true; + } + } + else if (mask & EVT_TYPE_MASK_MOUSE_GESTURE) { + if (ISMOUSE_GESTURE(event_type)) { + return true; + } + } + + /* Tweak. */ + if (mask & EVT_TYPE_MASK_TWEAK) { + if (ISTWEAK(event_type)) { + return true; + } + } + + /* Action Zone. */ + if (mask & EVT_TYPE_MASK_ACTIONZONE) { + if (IS_EVENT_ACTIONZONE(event_type)) { + return true; + } + } + + return false; +} + /* ********************* ghost stuff *************** */ static int convert_key(GHOST_TKey key) diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index 13744aa04af..2d7814b0377 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -64,7 +64,6 @@ #include "wm_event_system.h" #include "wm_event_types.h" - struct wmKeyMapItemFind_Params { bool (*filter_fn)(const wmKeyMap *km, const wmKeyMapItem *kmi, void *user_data); void *user_data; @@ -1415,21 +1414,29 @@ char *WM_key_event_operator_string( return NULL; } -static bool kmi_filter_is_visible_hotkey(const wmKeyMap *km, const wmKeyMapItem *kmi, void *user_data) +static bool kmi_filter_is_visible_type_mask(const wmKeyMap *km, const wmKeyMapItem *kmi, void *user_data) { - return (ISHOTKEY(kmi->type) && kmi_filter_is_visible(km, kmi, user_data)); + short *mask_pair = user_data; + return ((WM_event_type_mask_test(kmi->type, mask_pair[0]) == true) && + (WM_event_type_mask_test(kmi->type, mask_pair[1]) == false) && + kmi_filter_is_visible(km, kmi, user_data)); } +/** + * \param include_mask, exclude_mask: Event types to include/exclude when looking up keys (#eEventType_Mask). + */ wmKeyMapItem *WM_key_event_operator( - const bContext *C, const char *opname, int opcontext, - IDProperty *properties, const bool is_hotkey, + const bContext *C, const char *opname, int opcontext, IDProperty *properties, + const short include_mask, const short exclude_mask, wmKeyMap **r_keymap) { + short user_data_mask[2] = {include_mask, exclude_mask}; + bool use_mask = (include_mask != EVT_TYPE_MASK_ALL) || (exclude_mask != 0); return wm_keymap_item_find( C, opname, opcontext, properties, true, &(struct wmKeyMapItemFind_Params){ - .filter_fn = is_hotkey ? kmi_filter_is_visible_hotkey : kmi_filter_is_visible, - .user_data = NULL, + .filter_fn = use_mask ? kmi_filter_is_visible_type_mask : kmi_filter_is_visible, + .user_data = use_mask ? user_data_mask : NULL, }, r_keymap); } |