Cleanup: make modal event double click handling more straightforward
This commit is contained in:
@@ -1929,46 +1929,53 @@ static bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi)
|
|||||||
return true;
|
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 */
|
/* operator exists */
|
||||||
static void wm_event_modalkeymap(const bContext *C, wmOperator *op, wmEvent *event, bool *dbl_click_disabled)
|
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 */
|
/* support for modal keymap in macros */
|
||||||
if (op->opm)
|
if (op->opm)
|
||||||
op = op->opm;
|
op = op->opm;
|
||||||
|
|
||||||
if (op->type->modalkeymap) {
|
if (op->type->modalkeymap) {
|
||||||
wmKeyMap *keymap = WM_keymap_active(CTX_wm_manager(C), 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) {
|
const wmEvent *event_match = NULL;
|
||||||
if (wm_eventmatch(event, kmi)) {
|
wmEvent event_no_dbl_click;
|
||||||
if ((keymap->poll_modal_item == NULL) ||
|
|
||||||
(keymap->poll_modal_item(op, kmi->propvalue)))
|
if ((kmi = wm_eventmatch_modal_keymap_items(keymap, op, event))) {
|
||||||
{
|
event_match = event;
|
||||||
event->prevtype = event->type;
|
}
|
||||||
event->prevval = event->val;
|
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->type = EVT_MODAL_MAP;
|
||||||
event->val = kmi->propvalue;
|
event->val = kmi->propvalue;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
/* modal keymap checking returns handled events fine, but all hardcoded modal
|
/* modal keymap checking returns handled events fine, but all hardcoded modal
|
||||||
* handling typically swallows all events (OPERATOR_RUNNING_MODAL).
|
* handling typically swallows all events (OPERATOR_RUNNING_MODAL).
|
||||||
|
Reference in New Issue
Block a user