diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-08 06:16:32 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-08 06:19:27 +0300 |
commit | 6db49261cc18cb70766c3e5f41180839d24b4c9b (patch) | |
tree | e29c783e5df42a58749a49c1b7aeb7f57c88b8e1 /source/blender/windowmanager/intern | |
parent | 96af595f63414deb6a9247bb548023db86f923a1 (diff) |
Cleanup: make modal event double click handling more straightforward
Diffstat (limited to 'source/blender/windowmanager/intern')
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 0ac5265fac4..1ae3f7ffb79 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -1929,45 +1929,52 @@ static bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi) return true; } +static wmKeyMapItem *wm_eventmatch_modal_keymap_items(const wmKeyMap *keymap, wmOperator *op, const wmEvent *event) +{ + for (wmKeyMapItem *kmi = keymap->items.first; kmi; kmi = kmi->next) { + if (wm_eventmatch(event, kmi)) { + if ((keymap->poll_modal_item == NULL) || + (keymap->poll_modal_item(op, kmi->propvalue))) + { + return kmi; + } + } + } + return NULL; +} + /* operator exists */ static void wm_event_modalkeymap(const bContext *C, wmOperator *op, wmEvent *event, bool *dbl_click_disabled) { - wmOperator *op_init = op; - /* support for modal keymap in macros */ if (op->opm) op = op->opm; if (op->type->modalkeymap) { wmKeyMap *keymap = WM_keymap_active(CTX_wm_manager(C), op->type->modalkeymap); - wmKeyMapItem *kmi; + wmKeyMapItem *kmi = NULL; - for (kmi = keymap->items.first; kmi; kmi = kmi->next) { - if (wm_eventmatch(event, kmi)) { - if ((keymap->poll_modal_item == NULL) || - (keymap->poll_modal_item(op, kmi->propvalue))) - { - event->prevtype = event->type; - event->prevval = event->val; - event->type = EVT_MODAL_MAP; - event->val = kmi->propvalue; - break; - } - } - } + const wmEvent *event_match = NULL; + wmEvent event_no_dbl_click; - /* If double click isn't handled, re-run this function with with press. */ - if ((event->type != EVT_MODAL_MAP) && - (event->val == KM_DBL_CLICK)) - { - event->val = KM_PRESS; - wm_event_modalkeymap(C, op_init, event, NULL); - if (event->type != EVT_MODAL_MAP) { - event->val = KM_DBL_CLICK; + if ((kmi = wm_eventmatch_modal_keymap_items(keymap, op, event))) { + event_match = event; + } + else if (event->val == KM_DBL_CLICK) { + event_no_dbl_click = *event; + event_no_dbl_click.val = KM_PRESS; + if ((kmi = wm_eventmatch_modal_keymap_items(keymap, op, &event_no_dbl_click))) { + event_match = &event_no_dbl_click; } } + if (event_match != NULL) { + event->prevtype = event_match->type; + event->prevval = event_match->val; + event->type = EVT_MODAL_MAP; + event->val = kmi->propvalue; + } } else { /* modal keymap checking returns handled events fine, but all hardcoded modal |