Fix T83177: Industry Compatible keymap: MMB-dragging to transform engages axis-constraining on release

Release confirm did not consider modal keymap events.
This commit is contained in:
Germano Cavalcante 2020-11-30 13:11:46 -03:00
parent 3bdc42f97a
commit c0677b662f
Notes: blender-bot 2023-12-22 20:14:11 +01:00
Referenced by commit 2de49d1ff7, Revert "Fix T83177: Industry Compatible keymap: MMB-dragging to transform engages axis-constraining on release"
Referenced by issue #83177, Industry Compatible keymap: MMB-dragging to transform engages axis-constraining on release
6 changed files with 67 additions and 54 deletions

View File

@ -818,9 +818,15 @@ int transformEvent(TransInfo *t, const wmEvent *event)
t->redraw |= handleSnapping(t, event);
handled = true;
}
/* handle modal keymap first */
/* enforce redraw of transform when modifiers are used */
else if (event->val == t->release_confirm_event_val &&
event->type == t->release_confirm_event_type) {
/* Confirm transform if launch key is released after mouse move. */
BLI_assert(t->flag & T_RELEASE_CONFIRM);
t->state = TRANS_CONFIRM;
}
else if (event->type == EVT_MODAL_MAP) {
/* Handle modal keymap first. */
/* Enforce redraw of transform when modifiers are used */
switch (event->val) {
case TFM_MODAL_CANCEL:
t->state = TRANS_CANCEL;
@ -1122,8 +1128,8 @@ int transformEvent(TransInfo *t, const wmEvent *event)
break;
}
}
/* Else do non-mapped events. */
else if (event->val == KM_PRESS) {
/* Do non-mapped events. */
switch (event->type) {
case EVT_CKEY:
if (event->is_repeat) {
@ -1211,11 +1217,6 @@ int transformEvent(TransInfo *t, const wmEvent *event)
}
break;
}
/* confirm transform if launch key is released after mouse move */
if ((t->flag & T_RELEASE_CONFIRM) && event->type == t->launch_event) {
t->state = TRANS_CONFIRM;
}
}
/* if we change snap options, get the unsnapped values back */
@ -1687,17 +1688,6 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
t->mode = mode;
/* Needed to translate tweak events to mouse buttons. */
t->launch_event = event ? WM_userdef_event_type_from_keymap_type(event->type) : -1;
t->is_launch_event_tweak = event ? ISTWEAK(event->type) : false;
/* XXX Remove this when wm_operator_call_internal doesn't use window->eventstate
* (which can have type = 0) */
/* For gizmo only, so assume LEFTMOUSE. */
if (t->launch_event == 0) {
t->launch_event = LEFTMOUSE;
}
unit_m3(t->spacemtx);
initTransInfo(C, t, op, event);
@ -1771,37 +1761,6 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
}
if (event) {
/* keymap for shortcut header prints */
t->keymap = WM_keymap_active(CTX_wm_manager(C), op->type->modalkeymap);
/* Stupid code to have Ctrl-Click on gizmo work ok.
*
* Do this only for translation/rotation/resize because only these
* modes are available from gizmo and doing such check could
* lead to keymap conflicts for other modes (see T31584)
*/
if (ELEM(mode, TFM_TRANSLATION, TFM_ROTATION, TFM_RESIZE)) {
wmKeyMapItem *kmi;
for (kmi = t->keymap->items.first; kmi; kmi = kmi->next) {
if (kmi->flag & KMI_INACTIVE) {
continue;
}
if (kmi->propvalue == TFM_MODAL_SNAP_INV_ON && kmi->val == KM_PRESS) {
if ((ELEM(kmi->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY) && event->ctrl) ||
(ELEM(kmi->type, EVT_LEFTSHIFTKEY, EVT_RIGHTSHIFTKEY) && event->shift) ||
(ELEM(kmi->type, EVT_LEFTALTKEY, EVT_RIGHTALTKEY) && event->alt) ||
((kmi->type == EVT_OSKEY) && event->oskey)) {
t->modifiers |= MOD_SNAP_INVERT;
}
break;
}
}
}
}
initSnapping(t, op); /* Initialize snapping data AFTER mode flags */
initSnapSpatial(t, t->snap_spatial);

View File

@ -351,7 +351,8 @@ typedef struct TransInfo {
/*************** NEW STUFF *********************/
/** event type used to launch transform. */
short launch_event;
short release_confirm_event_type;
short release_confirm_event_val;
/** Is the actual launch event a tweak event? (launch_event above is set to the corresponding
* mouse button then.) */
bool is_launch_event_tweak;

View File

@ -593,18 +593,60 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
transform_orientations_current_set(t, (t->con.mode & CON_APPLY) ? 2 : 0);
}
if (event) {
t->release_confirm_event_type = WM_userdef_event_type_from_keymap_type(event->type);
t->is_launch_event_tweak = ISTWEAK(event->type);
/* XXX Remove this when wm_operator_call_internal doesn't use window->eventstate
* (which can have type = 0) */
/* For gizmo only, so assume LEFTMOUSE. */
if (t->release_confirm_event_type == 0) {
t->release_confirm_event_type = LEFTMOUSE;
}
}
else {
/* Needed to translate tweak events to mouse buttons. */
t->release_confirm_event_type = -1;
}
t->release_confirm_event_val = -2;
if (op && ((prop = RNA_struct_find_property(op->ptr, "release_confirm")) &&
RNA_property_is_set(op->ptr, prop))) {
if (RNA_property_boolean_get(op->ptr, prop)) {
t->flag |= T_RELEASE_CONFIRM;
t->release_confirm_event_val = KM_RELEASE;
}
}
else {
/* Release confirms preference should not affect node editor (T69288, T70504). */
if (ISMOUSE(t->launch_event) &&
if (ISMOUSE(t->release_confirm_event_type) &&
((U.flag & USER_RELEASECONFIRM) || (t->spacetype == SPACE_NODE))) {
/* Global "release confirm" on mouse bindings */
t->flag |= T_RELEASE_CONFIRM;
t->release_confirm_event_val = KM_RELEASE;
}
}
if (op && event) {
/* Keymap for shortcut header prints. */
t->keymap = WM_keymap_active(CTX_wm_manager(C), op->type->modalkeymap);
/* Stupid code to have Relase confirm and Ctrl-Click on gizmo work ok. */
wmKeyMapItem *kmi = WM_event_match_modal_keymap_item(t->keymap, op, event);
if (kmi) {
if ((t->flag & T_RELEASE_CONFIRM) && (event->val == KM_PRESS) && (kmi->val != KM_PRESS)) {
t->release_confirm_event_type = EVT_MODAL_MAP;
t->release_confirm_event_val = kmi->propvalue;
}
if ((kmi->propvalue == TFM_MODAL_SNAP_INV_ON) &&
ELEM(t->mode, TFM_TRANSLATION, TFM_ROTATION, TFM_RESIZE)) {
/* Do this only for translation/rotation/resize because only these
* modes are available from gizmo and doing such check could
* lead to keymap conflicts for other modes (see T31584) */
t->modifiers |= MOD_SNAP_INVERT;
}
}
}

View File

@ -376,7 +376,7 @@ static int transformops_data(bContext *C, wmOperator *op, const wmEvent *event)
{
int retval = 1;
if (op->customdata == NULL) {
TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data2");
TransInfo *t = op->customdata = MEM_callocN(sizeof(TransInfo), "TransInfo data2");
TransformModeItem *tmode;
int mode = -1;
@ -396,10 +396,10 @@ static int transformops_data(bContext *C, wmOperator *op, const wmEvent *event)
/* store data */
if (retval) {
G.moving = special_transform_moving(t);
op->customdata = t;
}
else {
MEM_freeN(t);
op->customdata = NULL;
}
}

View File

@ -47,6 +47,7 @@ struct ImBuf;
struct ImageFormatData;
struct Main;
struct MenuType;
struct Operator;
struct PointerRNA;
struct PropertyRNA;
struct ScrArea;
@ -255,6 +256,9 @@ void WM_event_set_keymap_handler_post_callback(struct wmEventHandler_Keymap *han
wmKeyMap *WM_event_get_keymap_from_handler(wmWindowManager *wm,
struct wmEventHandler_Keymap *handler);
wmKeyMapItem *WM_event_match_modal_keymap_item(const wmKeyMap *keymap,
struct wmOperator *op,
const struct wmEvent *event);
wmKeyMapItem *WM_event_match_keymap_item(struct bContext *C,
wmKeyMap *keymap,
const struct wmEvent *event);

View File

@ -1911,6 +1911,13 @@ static wmKeyMapItem *wm_eventmatch_modal_keymap_items(const wmKeyMap *keymap,
return NULL;
}
wmKeyMapItem *WM_event_match_modal_keymap_item(const wmKeyMap *keymap,
wmOperator *op,
const wmEvent *event)
{
return wm_eventmatch_modal_keymap_items(keymap, op, event);
}
/**
* This function prepares events for use with #wmOperatorType.modal by:
*