diff options
author | Campbell Barton <campbell@blender.org> | 2022-02-24 14:48:34 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-02-25 09:58:22 +0300 |
commit | ad0b3abf539bbb358f799d3f36649b5d46f222c8 (patch) | |
tree | d7aff552c5541880ca1ce2648595455418cafc56 | |
parent | e7cae5187773f41e62830be597c6f598bff0653f (diff) |
Cleanup: use flags for wmEvent modifier keys
Using flags makes checking multiple modifiers at once more convenient
and avoids macros/functions such as IS_EVENT_MOD & WM_event_modifier_flag
which have been removed. It also simplifies checking if modifier keys
have changed.
56 files changed, 340 insertions, 322 deletions
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index 9566402ad85..ab51702d628 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -960,7 +960,13 @@ static int ed_marker_move_modal(bContext *C, wmOperator *op, const wmEvent *even mm->evtx = event->xy[0]; fac = ((float)(event->xy[0] - mm->firstx) * dx); - apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, FPS, 0.1 * FPS, 0); + apply_keyb_grid((event->modifier & KM_SHIFT) != 0, + (event->modifier & KM_CTRL) != 0, + &fac, + 0.0, + FPS, + 0.1 * FPS, + 0); RNA_int_set(op->ptr, "frames", (int)fac); ed_marker_move_apply(C, op); diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c index e227e69f9e1..13abcefa632 100644 --- a/source/blender/editors/armature/pose_edit.c +++ b/source/blender/editors/armature/pose_edit.c @@ -427,7 +427,7 @@ static int pose_clear_paths_exec(bContext *C, wmOperator *op) /* operator callback/wrapper */ static int pose_clear_paths_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - if ((event->shift) && !RNA_struct_property_is_set(op->ptr, "only_selected")) { + if ((event->modifier & KM_SHIFT) && !RNA_struct_property_is_set(op->ptr, "only_selected")) { RNA_boolean_set(op->ptr, "only_selected", true); } return pose_clear_paths_exec(C, op); diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index b2af0643e2c..02c7f3856e8 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -1640,7 +1640,9 @@ static int insert_text_invoke(bContext *C, wmOperator *op, const wmEvent *event) EditFont *ef = cu->editfont; static int accentcode = 0; uintptr_t ascii = event->ascii; - int alt = event->alt, shift = event->shift, ctrl = event->ctrl; + const bool alt = event->modifier & KM_ALT; + const bool shift = event->modifier & KM_SHIFT; + const bool ctrl = event->modifier & KM_CTRL; int event_type = event->type, event_val = event->val; char32_t inserted_text[2] = {0}; diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c index 163b5657326..b40dda146dc 100644 --- a/source/blender/editors/gpencil/annotate_paint.c +++ b/source/blender/editors/gpencil/annotate_paint.c @@ -2060,7 +2060,7 @@ static void annotation_draw_apply_event( p->mval[1] = (float)event->mval[1] - y; /* Key to toggle stabilization. */ - if (event->shift && p->paintmode == GP_PAINTMODE_DRAW) { + if ((event->modifier & KM_SHIFT) && (p->paintmode == GP_PAINTMODE_DRAW)) { /* Using permanent stabilization, shift will deactivate the flag. */ if (p->flags & GP_PAINTFLAG_USE_STABILIZER) { if (p->flags & GP_PAINTFLAG_USE_STABILIZER_TEMP) { @@ -2075,7 +2075,7 @@ static void annotation_draw_apply_event( } } /* verify key status for straight lines */ - else if (event->ctrl || event->alt) { + else if (event->modifier & (KM_CTRL | KM_ALT)) { if (p->straight[0] == 0) { int dx = abs((int)(p->mval[0] - p->mvalo[0])); int dy = abs((int)(p->mval[1] - p->mvalo[1])); @@ -2299,7 +2299,7 @@ static int annotation_draw_invoke(bContext *C, wmOperator *op, const wmEvent *ev p->flags |= GP_PAINTFLAG_USE_STABILIZER | GP_PAINTFLAG_USE_STABILIZER_TEMP; annotation_draw_toggle_stabilizer_cursor(p, true); } - else if (event->shift) { + else if (event->modifier & KM_SHIFT) { p->flags |= GP_PAINTFLAG_USE_STABILIZER_TEMP; annotation_draw_toggle_stabilizer_cursor(p, true); } diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c index 8e5161b3245..32dc086099c 100644 --- a/source/blender/editors/gpencil/gpencil_fill.c +++ b/source/blender/editors/gpencil/gpencil_fill.c @@ -2172,7 +2172,8 @@ static int gpencil_fill_modal(bContext *C, wmOperator *op, const wmEvent *event) tgpf->on_back = RNA_boolean_get(op->ptr, "on_back"); const bool is_brush_inv = brush_settings->fill_direction == BRUSH_DIR_IN; - const bool is_inverted = (is_brush_inv && !event->ctrl) || (!is_brush_inv && event->ctrl); + const bool is_inverted = (is_brush_inv && (event->modifier & KM_CTRL) == 0) || + (!is_brush_inv && (event->modifier & KM_CTRL) != 0); const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(tgpf->gpd); const bool do_extend = (tgpf->fill_extend_fac > 0.0f); const bool help_lines = ((tgpf->flag & GP_BRUSH_FILL_SHOW_HELPLINES) || @@ -2313,7 +2314,7 @@ static int gpencil_fill_modal(bContext *C, wmOperator *op, const wmEvent *event) case EVT_PAGEUPKEY: case WHEELUPMOUSE: if (tgpf->oldkey == 1) { - tgpf->fill_extend_fac -= (event->shift) ? 0.01f : 0.1f; + tgpf->fill_extend_fac -= (event->modifier & KM_SHIFT) ? 0.01f : 0.1f; CLAMP_MIN(tgpf->fill_extend_fac, 0.0f); gpencil_update_extend(tgpf); } @@ -2321,7 +2322,7 @@ static int gpencil_fill_modal(bContext *C, wmOperator *op, const wmEvent *event) case EVT_PAGEDOWNKEY: case WHEELDOWNMOUSE: if (tgpf->oldkey == 1) { - tgpf->fill_extend_fac += (event->shift) ? 0.01f : 0.1f; + tgpf->fill_extend_fac += (event->modifier & KM_SHIFT) ? 0.01f : 0.1f; CLAMP_MAX(tgpf->fill_extend_fac, 100.0f); gpencil_update_extend(tgpf); } diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index a6691a12505..9442b2edc13 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -235,7 +235,7 @@ typedef struct tGPsdata { /** key used for invoking the operator */ short keymodifier; /** shift modifier flag */ - short shift; + bool shift; /** size in pixels for uv calculation */ float totpixlen; /** Special mode for fill brush. */ @@ -2841,11 +2841,11 @@ static void gpencil_draw_apply_event(bContext *C, * add any x,y override position */ copy_v2fl_v2i(p->mval, event->mval); - p->shift = event->shift; + p->shift = (event->modifier & KM_SHIFT) != 0; /* verify direction for straight lines and guides */ if ((is_speed_guide) || - (event->alt && (RNA_boolean_get(op->ptr, "disable_straight") == false))) { + ((event->modifier & KM_ALT) && (RNA_boolean_get(op->ptr, "disable_straight") == false))) { if (p->straight == 0) { int dx = (int)fabsf(p->mval[0] - p->mvali[0]); int dy = (int)fabsf(p->mval[1] - p->mvali[1]); @@ -2886,13 +2886,13 @@ static void gpencil_draw_apply_event(bContext *C, /* special eraser modes */ if (p->paintmode == GP_PAINTMODE_ERASER) { - if (event->shift) { + if (event->modifier & KM_SHIFT) { p->flags |= GP_PAINTFLAG_HARD_ERASER; } else { p->flags &= ~GP_PAINTFLAG_HARD_ERASER; } - if (event->alt) { + if (event->modifier & KM_ALT) { p->flags |= GP_PAINTFLAG_STROKE_ERASER; } else { @@ -3116,11 +3116,11 @@ static void gpencil_guide_event_handling(bContext *C, else if ((event->type == EVT_LKEY) && (event->val == KM_RELEASE)) { add_notifier = true; guide->use_guide = true; - if (event->ctrl) { + if (event->modifier & KM_CTRL) { guide->angle = 0.0f; guide->type = GP_GUIDE_PARALLEL; } - else if (event->alt) { + else if (event->modifier & KM_ALT) { guide->type = GP_GUIDE_PARALLEL; guide->angle = RNA_float_get(op->ptr, "guide_last_angle"); } @@ -3150,10 +3150,10 @@ static void gpencil_guide_event_handling(bContext *C, add_notifier = true; float angle = guide->angle; float adjust = (float)M_PI / 180.0f; - if (event->alt) { + if (event->modifier & KM_ALT) { adjust *= 45.0f; } - else if (!event->shift) { + else if ((event->modifier & KM_SHIFT) == 0) { adjust *= 15.0f; } angle += (event->type == EVT_JKEY) ? adjust : -adjust; @@ -3633,7 +3633,7 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) */ } else if (event->type == EVT_ZKEY) { - if (event->ctrl) { + if (event->modifier & KM_CTRL) { p->status = GP_STATUS_DONE; estate = OPERATOR_FINISHED; } diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index 2d761dd6c91..57a184b0e8d 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -1494,7 +1494,7 @@ static void gpencil_primitive_edit_event_handling( float dy = (tgpi->mval[1] - tgpi->mvalo[1]); tgpi->cp1[0] += dx; tgpi->cp1[1] += dy; - if (event->shift) { + if (event->modifier & KM_SHIFT) { copy_v2_v2(tgpi->cp2, tgpi->cp1); } } @@ -1503,7 +1503,7 @@ static void gpencil_primitive_edit_event_handling( float dy = (tgpi->mval[1] - tgpi->mvalo[1]); tgpi->cp2[0] += dx; tgpi->cp2[1] += dy; - if (event->shift) { + if (event->modifier & KM_SHIFT) { copy_v2_v2(tgpi->cp1, tgpi->cp2); } } @@ -1692,7 +1692,7 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e WM_cursor_modal_set(win, WM_CURSOR_NSEW_SCROLL); copy_v2_v2(tgpi->end, tgpi->mval); - if (event->shift) { + if (event->modifier & KM_SHIFT) { gpencil_primitive_constrain(tgpi, true); } @@ -1722,7 +1722,7 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e case EVT_FKEY: /* brush thickness/ brush strength */ { if ((event->val == KM_PRESS)) { - if (event->shift) { + if (event->modifier & KM_SHIFT) { tgpi->prev_flag = tgpi->flag; tgpi->flag = IN_BRUSH_STRENGTH; } @@ -1900,7 +1900,7 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e case EVT_FKEY: /* brush thickness/ brush strength */ { if ((event->val == KM_PRESS)) { - if (event->shift) { + if (event->modifier & KM_SHIFT) { tgpi->prev_flag = tgpi->flag; tgpi->flag = IN_BRUSH_STRENGTH; } @@ -1954,12 +1954,12 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e copy_v2_v2(tgpi->origin, tgpi->mval); } /* Keep square if shift key */ - if (event->shift) { + if (event->modifier & KM_SHIFT) { gpencil_primitive_constrain( tgpi, (ELEM(tgpi->type, GP_STROKE_LINE, GP_STROKE_POLYLINE) || tgpi->curve)); } /* Center primitive if alt key */ - if (event->alt && !ELEM(tgpi->type, GP_STROKE_POLYLINE)) { + if ((event->modifier & KM_ALT) && !ELEM(tgpi->type, GP_STROKE_POLYLINE)) { tgpi->start[0] = tgpi->origin[0] - (tgpi->end[0] - tgpi->origin[0]); tgpi->start[1] = tgpi->origin[1] - (tgpi->end[1] - tgpi->origin[1]); } diff --git a/source/blender/editors/gpencil/gpencil_sculpt_paint.c b/source/blender/editors/gpencil/gpencil_sculpt_paint.c index e8f097d0018..ebe879959c9 100644 --- a/source/blender/editors/gpencil/gpencil_sculpt_paint.c +++ b/source/blender/editors/gpencil/gpencil_sculpt_paint.c @@ -1883,7 +1883,7 @@ static void gpencil_sculpt_brush_apply_event(bContext *C, wmOperator *op, const RNA_collection_add(op->ptr, "stroke", &itemptr); RNA_float_set_array(&itemptr, "mouse", mouse); - RNA_boolean_set(&itemptr, "pen_flip", event->ctrl != false); + RNA_boolean_set(&itemptr, "pen_flip", (event->modifier & KM_CTRL) != 0); RNA_boolean_set(&itemptr, "is_start", gso->first); /* handle pressure sensitivity (which is supplied by tablets and otherwise 1.0) */ @@ -1895,7 +1895,7 @@ static void gpencil_sculpt_brush_apply_event(bContext *C, wmOperator *op, const } RNA_float_set(&itemptr, "pressure", pressure); - if (event->shift) { + if (event->modifier & KM_SHIFT) { gso->brush_prev = gso->brush; gso->brush = gpencil_sculpt_get_smooth_brush(gso); diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index da263d44fc6..fca4ff84dc5 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -2659,7 +2659,7 @@ static int gpencil_select_invoke(bContext *C, wmOperator *op, const wmEvent *eve RNA_int_set_array(op->ptr, "location", event->mval); if (!RNA_struct_property_is_set(op->ptr, "use_shift_extend")) { - RNA_boolean_set(op->ptr, "use_shift_extend", event->shift); + RNA_boolean_set(op->ptr, "use_shift_extend", event->modifier & KM_SHIFT); } return gpencil_select_exec(C, op); diff --git a/source/blender/editors/gpencil/gpencil_vertex_paint.c b/source/blender/editors/gpencil/gpencil_vertex_paint.c index 1d1b00e3f08..244942a87ba 100644 --- a/source/blender/editors/gpencil/gpencil_vertex_paint.c +++ b/source/blender/editors/gpencil/gpencil_vertex_paint.c @@ -1241,7 +1241,7 @@ static void gpencil_vertexpaint_brush_apply_event(bContext *C, RNA_collection_add(op->ptr, "stroke", &itemptr); RNA_float_set_array(&itemptr, "mouse", mouse); - RNA_boolean_set(&itemptr, "pen_flip", event->ctrl != false); + RNA_boolean_set(&itemptr, "pen_flip", event->modifier & KM_CTRL); RNA_boolean_set(&itemptr, "is_start", gso->first); /* Handle pressure sensitivity (which is supplied by tablets). */ diff --git a/source/blender/editors/gpencil/gpencil_weight_paint.c b/source/blender/editors/gpencil/gpencil_weight_paint.c index 8fe4cba7021..01e73cd2abd 100644 --- a/source/blender/editors/gpencil/gpencil_weight_paint.c +++ b/source/blender/editors/gpencil/gpencil_weight_paint.c @@ -698,7 +698,7 @@ static void gpencil_weightpaint_brush_apply_event(bContext *C, RNA_collection_add(op->ptr, "stroke", &itemptr); RNA_float_set_array(&itemptr, "mouse", mouse); - RNA_boolean_set(&itemptr, "pen_flip", event->ctrl != false); + RNA_boolean_set(&itemptr, "pen_flip", event->modifier & KM_CTRL); RNA_boolean_set(&itemptr, "is_start", gso->first); /* Handle pressure sensitivity (which is supplied by tablets). */ diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h index bd3a6bce8e8..f235f696ccc 100644 --- a/source/blender/editors/include/ED_util.h +++ b/source/blender/editors/include/ED_util.h @@ -106,7 +106,7 @@ void ED_slider_allow_overshoot_set(struct tSlider *slider, bool value); * \note Shift/Control are not configurable key-bindings. */ void apply_keyb_grid( - int shift, int ctrl, float *val, float fac1, float fac2, float fac3, int invert); + bool shift, bool ctrl, float *val, float fac1, float fac2, float fac3, int invert); /* where else to go ? */ void unpack_menu(struct bContext *C, diff --git a/source/blender/editors/interface/interface_eyedropper_gpencil_color.c b/source/blender/editors/interface/interface_eyedropper_gpencil_color.c index d6f529f9f94..f3c70e6a96a 100644 --- a/source/blender/editors/interface/interface_eyedropper_gpencil_color.c +++ b/source/blender/editors/interface/interface_eyedropper_gpencil_color.c @@ -222,9 +222,9 @@ static void eyedropper_add_palette_color(bContext *C, const float col_conv[4]) static void eyedropper_gpencil_color_set(bContext *C, const wmEvent *event, EyedropperGPencil *eye) { - const bool only_stroke = ((!event->ctrl) && (!event->shift)); - const bool only_fill = ((!event->ctrl) && (event->shift)); - const bool both = ((event->ctrl) && (event->shift)); + const bool only_stroke = (event->modifier & (KM_CTRL | KM_SHIFT)) == 0; + const bool only_fill = ((event->modifier & KM_CTRL) == 0 && (event->modifier & KM_SHIFT)); + const bool both = ((event->modifier & KM_CTRL) && (event->modifier & KM_SHIFT)); float col_conv[4]; diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 9dcee73f6bb..3d92cd6c397 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -275,7 +275,7 @@ static void ui_selectcontext_apply(bContext *C, const double value, const double value_orig); -# define IS_ALLSELECT_EVENT(event) ((event)->alt != 0) +# define IS_ALLSELECT_EVENT(event) (((event)->modifier & KM_ALT) != 0) /** just show a tinted color so users know its activated */ # define UI_BUT_IS_SELECT_CONTEXT UI_BUT_NODE_ACTIVE @@ -708,7 +708,8 @@ enum eSnapType { static enum eSnapType ui_event_to_snap(const wmEvent *event) { - return (event->ctrl) ? (event->shift) ? SNAP_ON_SMALL : SNAP_ON : SNAP_OFF; + return (event->modifier & KM_CTRL) ? (event->modifier & KM_SHIFT) ? SNAP_ON_SMALL : SNAP_ON : + SNAP_OFF; } static bool ui_event_is_snap(const wmEvent *event) @@ -1937,7 +1938,7 @@ static void ui_selectcontext_apply(bContext *C, /* could check for 'handle_layer_buttons' */ but->func) { wmWindow *win = CTX_wm_window(C); - if (!win->eventstate->shift) { + if ((win->eventstate->modifier & KM_SHIFT) == 0) { const int len = RNA_property_array_length(&but->rnapoin, prop); bool *tmparray = MEM_callocN(sizeof(bool) * len, __func__); @@ -3747,11 +3748,11 @@ static void ui_do_but_textedit( case EVT_XKEY: case EVT_CKEY: #if defined(__APPLE__) - if ((event->oskey && !IS_EVENT_MOD(event, shift, alt, ctrl)) || - (event->ctrl && !IS_EVENT_MOD(event, shift, alt, oskey))) { + if (ELEM(event->modifier, KM_OSKEY, KM_CTRL)) #else - if (event->ctrl && !IS_EVENT_MOD(event, shift, alt, oskey)) { + if (event->modifier == KM_CTRL) #endif + { if (event->type == EVT_VKEY) { changed = ui_textedit_copypaste(but, data, UI_TEXTEDIT_PASTE); } @@ -3769,16 +3770,16 @@ static void ui_do_but_textedit( ui_textedit_move(but, data, STRCUR_DIR_NEXT, - event->shift != 0, - event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + event->modifier & KM_SHIFT, + (event->modifier & KM_CTRL) ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; case EVT_LEFTARROWKEY: ui_textedit_move(but, data, STRCUR_DIR_PREV, - event->shift != 0, - event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + event->modifier & KM_SHIFT, + (event->modifier & KM_CTRL) ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; case WHEELDOWNMOUSE: @@ -3795,7 +3796,7 @@ static void ui_do_but_textedit( } ATTR_FALLTHROUGH; case EVT_ENDKEY: - ui_textedit_move(but, data, STRCUR_DIR_NEXT, event->shift != 0, STRCUR_JUMP_ALL); + ui_textedit_move(but, data, STRCUR_DIR_NEXT, event->modifier & KM_SHIFT, STRCUR_JUMP_ALL); retval = WM_UI_HANDLER_BREAK; break; case WHEELUPMOUSE: @@ -3812,7 +3813,7 @@ static void ui_do_but_textedit( } ATTR_FALLTHROUGH; case EVT_HOMEKEY: - ui_textedit_move(but, data, STRCUR_DIR_PREV, event->shift != 0, STRCUR_JUMP_ALL); + ui_textedit_move(but, data, STRCUR_DIR_PREV, event->modifier & KM_SHIFT, STRCUR_JUMP_ALL); retval = WM_UI_HANDLER_BREAK; break; case EVT_PADENTER: @@ -3822,13 +3823,13 @@ static void ui_do_but_textedit( break; case EVT_DELKEY: changed = ui_textedit_delete( - but, data, 1, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + but, data, 1, (event->modifier & KM_CTRL) ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; case EVT_BACKSPACEKEY: changed = ui_textedit_delete( - but, data, 0, event->ctrl ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); + but, data, 0, (event->modifier & KM_CTRL) ? STRCUR_JUMP_DELIM : STRCUR_JUMP_NONE); retval = WM_UI_HANDLER_BREAK; break; @@ -3837,10 +3838,9 @@ static void ui_do_but_textedit( /* Ctrl-A: Select all. */ #if defined(__APPLE__) /* OSX uses Command-A system-wide, so add it. */ - if ((event->oskey && !IS_EVENT_MOD(event, shift, alt, ctrl)) || - (event->ctrl && !IS_EVENT_MOD(event, shift, alt, oskey))) + if (ELEM(event->modifier, KM_OSKEY, KM_CTRL)) #else - if (event->ctrl && !IS_EVENT_MOD(event, shift, alt, oskey)) + if (event->modifier == KM_CTRL) #endif { ui_textedit_move(but, data, STRCUR_DIR_PREV, false, STRCUR_JUMP_ALL); @@ -3859,9 +3859,9 @@ static void ui_do_but_textedit( button_activate_state(C, but, BUTTON_STATE_EXIT); } } - else if (!IS_EVENT_MOD(event, ctrl, alt, oskey)) { + else if ((event->modifier & (KM_CTRL | KM_ALT | KM_OSKEY)) == 0) { /* Use standard keys for cycling through buttons Tab, Shift-Tab to reverse. */ - if (event->shift) { + if (event->modifier & KM_SHIFT) { ui_textedit_prev_but(block, but, data); } else { @@ -3874,12 +3874,12 @@ static void ui_do_but_textedit( case EVT_ZKEY: { /* Ctrl-Z or Ctrl-Shift-Z: Undo/Redo (allowing for OS-Key on Apple). */ - const bool is_redo = (event->shift != 0); + const bool is_redo = (event->modifier & KM_SHIFT); if ( #if defined(__APPLE__) - (event->oskey && !IS_EVENT_MOD(event, alt, ctrl)) || + ((event->modifier & KM_OSKEY) && ((event->modifier & (KM_ALT | KM_CTRL)) == 0)) || #endif - (event->ctrl && !IS_EVENT_MOD(event, alt, oskey))) { + ((event->modifier & KM_CTRL) && ((event->modifier & (KM_ALT | KM_OSKEY)) == 0))) { int undo_pos; const char *undo_str = ui_textedit_undo( data->undo_stack_text, is_redo ? 1 : -1, &undo_pos); @@ -4542,19 +4542,7 @@ static int ui_do_but_HOTKEYEVT(bContext *C, } /* always set */ - but->modifier_key = 0; - if (event->shift) { - but->modifier_key |= KM_SHIFT; - } - if (event->alt) { - but->modifier_key |= KM_ALT; - } - if (event->ctrl) { - but->modifier_key |= KM_CTRL; - } - if (event->oskey) { - but->modifier_key |= KM_OSKEY; - } + but->modifier_key = event->modifier; ui_but_update(but); ED_region_tag_redraw(data->region); @@ -4633,7 +4621,8 @@ static int ui_do_but_TAB( const int rna_type = but->rnaprop ? RNA_property_type(but->rnaprop) : 0; if (is_property && ELEM(rna_type, PROP_POINTER, PROP_STRING) && (but->custom_data != NULL) && - (event->type == LEFTMOUSE) && ((event->val == KM_DBL_CLICK) || event->ctrl)) { + (event->type == LEFTMOUSE) && + ((event->val == KM_DBL_CLICK) || (event->modifier & KM_CTRL))) { button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); return WM_UI_HANDLER_BREAK; } @@ -4666,7 +4655,8 @@ static int ui_do_but_TEX( if (ELEM(event->type, EVT_PADENTER, EVT_RETKEY) && (!UI_but_is_utf8(but))) { /* pass - allow filesel, enter to execute */ } - else if (ELEM(but->emboss, UI_EMBOSS_NONE, UI_EMBOSS_NONE_OR_STATUS) && !event->ctrl) { + else if (ELEM(but->emboss, UI_EMBOSS_NONE, UI_EMBOSS_NONE_OR_STATUS) && + ((event->modifier & KM_CTRL) == 0)) { /* pass */ } else { @@ -4735,7 +4725,7 @@ static int ui_do_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data, cons button_activate_state(C, but, BUTTON_STATE_EXIT); return WM_UI_HANDLER_BREAK; } - if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->ctrl) { + if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && (event->modifier & KM_CTRL)) { /* Support Ctrl-Wheel to cycle values on expanded enum rows. */ if (but->type == UI_BTYPE_ROW) { int type = event->type; @@ -5325,24 +5315,24 @@ static int ui_do_but_NUM( } /* XXX hardcoded keymap check.... */ - if (type == MOUSEPAN && event->ctrl) { + if (type == MOUSEPAN && (event->modifier & KM_CTRL)) { /* allow accumulating values, otherwise scrolling gets preference */ retval = WM_UI_HANDLER_BREAK; } - else if (type == WHEELDOWNMOUSE && event->ctrl) { + else if (type == WHEELDOWNMOUSE && (event->modifier & KM_CTRL)) { mx = but->rect.xmin; but->drawflag &= ~UI_BUT_ACTIVE_RIGHT; but->drawflag |= UI_BUT_ACTIVE_LEFT; click = 1; } - else if (type == WHEELUPMOUSE && event->ctrl) { + else if ((type == WHEELUPMOUSE) && (event->modifier & KM_CTRL)) { mx = but->rect.xmax; but->drawflag &= ~UI_BUT_ACTIVE_LEFT; but->drawflag |= UI_BUT_ACTIVE_RIGHT; click = 1; } else if (event->val == KM_PRESS) { - if (ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && event->ctrl) { + if (ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && (event->modifier & KM_CTRL)) { button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); retval = WM_UI_HANDLER_BREAK; } @@ -5402,7 +5392,7 @@ static int ui_do_but_NUM( #endif fac = 1.0f; - if (event->shift) { + if (event->modifier & KM_SHIFT) { fac /= 10.0f; } @@ -5668,27 +5658,27 @@ static int ui_do_but_SLI( } /* XXX hardcoded keymap check.... */ - if (type == MOUSEPAN && event->ctrl) { + if ((type == MOUSEPAN) && (event->modifier & KM_CTRL)) { /* allow accumulating values, otherwise scrolling gets preference */ retval = WM_UI_HANDLER_BREAK; } - else if (type == WHEELDOWNMOUSE && event->ctrl) { + else if ((type == WHEELDOWNMOUSE) && (event->modifier & KM_CTRL)) { mx = but->rect.xmin; click = 2; } - else if (type == WHEELUPMOUSE && event->ctrl) { + else if ((type == WHEELUPMOUSE) && (event->modifier & KM_CTRL)) { mx = but->rect.xmax; click = 2; } else if (event->val == KM_PRESS) { - if (ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && event->ctrl) { + if (ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && (event->modifier & KM_CTRL)) { button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); retval = WM_UI_HANDLER_BREAK; } #ifndef USE_ALLSELECT /* alt-click on sides to get "arrows" like in UI_BTYPE_NUM buttons, * and match wheel usage above */ - else if (event->type == LEFTMOUSE && event->alt) { + else if ((event->type == LEFTMOUSE) && (event->modifier & KM_ALT)) { int halfpos = BLI_rctf_cent_x(&but->rect); click = 2; if (mx < halfpos) { @@ -5754,8 +5744,13 @@ static int ui_do_but_SLI( data->multi_data.drag_dir[0] += abs(data->draglastx - mx); data->multi_data.drag_dir[1] += abs(data->draglasty - my); #endif - if (ui_numedit_but_SLI( - but, data, mx, true, is_motion, event->ctrl != 0, event->shift != 0)) { + if (ui_numedit_but_SLI(but, + data, + mx, + true, + is_motion, + event->modifier & KM_CTRL, + event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } @@ -5981,8 +5976,8 @@ static int ui_do_but_LISTROW(bContext *C, /* hack to pass on ctrl+click and double click to overlapping text * editing field for editing list item names */ - if ((ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && event->val == KM_PRESS && - event->ctrl) || + if ((ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && (event->val == KM_PRESS) && + (event->modifier & KM_CTRL)) || (event->type == LEFTMOUSE && event->val == KM_DBL_CLICK)) { uiBut *labelbut = ui_but_list_row_text_activate( C, but, data, event, BUTTON_ACTIVATE_TEXT_EDITING); @@ -6023,7 +6018,8 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, co return WM_UI_HANDLER_BREAK; } if (ui_but_supports_cycling(but)) { - if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->ctrl) { + if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && + (event->modifier & KM_CTRL)) { int type = event->type; int val = event->val; @@ -6210,7 +6206,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); return WM_UI_HANDLER_BREAK; } - if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->ctrl) { + if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && (event->modifier & KM_CTRL)) { ColorPicker *cpicker = but->custom_data; float hsv_static[3] = {0.0f}; float *hsv = cpicker ? cpicker->hsv_perceptual : hsv_static; @@ -6269,7 +6265,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { if (color_but->is_pallete_color) { - if (!event->ctrl) { + if ((event->modifier & KM_CTRL) == 0) { float color[3]; Paint *paint = BKE_paint_get_active_from_context(C); Brush *brush = BKE_paint_brush(paint); @@ -6639,7 +6635,7 @@ static int ui_do_but_HSVCUBE( button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); /* also do drag the first time */ - if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, event->shift != 0)) { + if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } @@ -6650,7 +6646,7 @@ static int ui_do_but_HSVCUBE( const wmNDOFMotionData *ndof = event->customdata; const enum eSnapType snap = ui_event_to_snap(event); - ui_ndofedit_but_HSVCUBE(hsv_but, data, ndof, snap, event->shift != 0); + ui_ndofedit_but_HSVCUBE(hsv_but, data, ndof, snap, event->modifier & KM_SHIFT); button_activate_state(C, but, BUTTON_STATE_EXIT); ui_apply_but(C, but->block, but, data, true); @@ -6702,7 +6698,7 @@ static int ui_do_but_HSVCUBE( if (mx != data->draglastx || my != data->draglasty || event->type != MOUSEMOVE) { const enum eSnapType snap = ui_event_to_snap(event); - if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, event->shift != 0)) { + if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } } @@ -6914,7 +6910,7 @@ static int ui_do_but_HSVCIRCLE( button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); /* also do drag the first time */ - if (ui_numedit_but_HSVCIRCLE(but, data, mx, my, snap, event->shift != 0)) { + if (ui_numedit_but_HSVCIRCLE(but, data, mx, my, snap, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } @@ -6925,7 +6921,7 @@ static int ui_do_but_HSVCIRCLE( const enum eSnapType snap = ui_event_to_snap(event); const wmNDOFMotionData *ndof = event->customdata; - ui_ndofedit_but_HSVCIRCLE(but, data, ndof, snap, event->shift != 0); + ui_ndofedit_but_HSVCIRCLE(but, data, ndof, snap, event->modifier & KM_SHIFT); button_activate_state(C, but, BUTTON_STATE_EXIT); ui_apply_but(C, but->block, but, data, true); @@ -6987,7 +6983,7 @@ static int ui_do_but_HSVCIRCLE( if (mx != data->draglastx || my != data->draglasty || event->type != MOUSEMOVE) { const enum eSnapType snap = ui_event_to_snap(event); - if (ui_numedit_but_HSVCIRCLE(but, data, mx, my, snap, event->shift != 0)) { + if (ui_numedit_but_HSVCIRCLE(but, data, mx, my, snap, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } } @@ -7037,7 +7033,7 @@ static int ui_do_but_COLORBAND( if (event->type == LEFTMOUSE && event->val == KM_PRESS) { ColorBand *coba = (ColorBand *)but->poin; - if (event->ctrl) { + if (event->modifier & KM_CTRL) { /* insert new key on mouse location */ const float pos = ((float)(mx - but->rect.xmin)) / BLI_rctf_size_x(&but->rect); BKE_colorband_element_add(coba, pos); @@ -7237,7 +7233,7 @@ static int ui_do_but_CURVE( float dist_min_sq = square_f(U.dpi_fac * 14.0f); /* 14 pixels radius */ int sel = -1; - if (event->ctrl) { + if (event->modifier & KM_CTRL) { float f_xy[2]; BLI_rctf_transform_pt_v(&cumap->curr, &but->rect, f_xy, m_xy); @@ -7301,7 +7297,7 @@ static int ui_do_but_CURVE( if (sel != -1) { /* ok, we move a point */ /* deselect all if this one is deselect. except if we hold shift */ - if (!event->shift) { + if ((event->modifier & KM_SHIFT) == 0) { for (int a = 0; a < cuma->totpoint; a++) { cmp[a].flag &= ~CUMA_SELECT; } @@ -7336,8 +7332,8 @@ static int ui_do_but_CURVE( data, event->xy[0], event->xy[1], - event->ctrl != 0, - event->shift != 0)) { + event->modifier & KM_CTRL, + event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } } @@ -7350,7 +7346,7 @@ static int ui_do_but_CURVE( if (data->dragchange == false) { /* deselect all, select one */ - if (!event->shift) { + if ((event->modifier & KM_SHIFT) == 0) { for (int a = 0; a < cuma->totpoint; a++) { cmp[a].flag &= ~CUMA_SELECT; } @@ -7539,7 +7535,7 @@ static int ui_do_but_CURVEPROFILE( if (event->type == LEFTMOUSE && event->val == KM_PRESS) { const float m_xy[2] = {mx, my}; - if (event->ctrl) { + if (event->modifier & KM_CTRL) { float f_xy[2]; BLI_rctf_transform_pt_v(&profile->view_rect, &but->rect, f_xy, m_xy); @@ -7616,7 +7612,7 @@ static int ui_do_but_CURVEPROFILE( /* Change the flag for the point(s) if one was selected or added. */ if (i_selected != -1) { /* Deselect all if this one is deselected, except if we hold shift. */ - if (event->shift) { + if (event->modifier & KM_SHIFT) { pts[i_selected].flag ^= selection_type; } else { @@ -7647,7 +7643,7 @@ static int ui_do_but_CURVEPROFILE( if (event->type == MOUSEMOVE) { if (mx != data->draglastx || my != data->draglasty) { if (ui_numedit_but_CURVEPROFILE( - block, but, data, mx, my, event->ctrl != 0, event->shift != 0)) { + block, but, data, mx, my, event->modifier & KM_CTRL, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } } @@ -7871,7 +7867,7 @@ static int ui_do_but_TRACKPREVIEW( button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); /* also do drag the first time */ - if (ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift != 0)) { + if (ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } @@ -7888,7 +7884,7 @@ static int ui_do_but_TRACKPREVIEW( } else if (event->type == MOUSEMOVE) { if (mx != data->draglastx || my != data->draglasty) { - if (ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->shift != 0)) { + if (ui_numedit_but_TRACKPREVIEW(C, but, data, mx, my, event->modifier & KM_SHIFT)) { ui_numedit_apply(C, block, but, data); } } @@ -7918,8 +7914,9 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * if (data->state == BUTTON_STATE_HIGHLIGHT) { /* handle copy and paste */ - bool is_press_ctrl_but_no_shift = event->val == KM_PRESS && IS_EVENT_MOD(event, ctrl, oskey) && - !event->shift; + bool is_press_ctrl_but_no_shift = (event->val == KM_PRESS) && + (event->modifier & (KM_CTRL | KM_OSKEY)) && + (event->modifier & KM_SHIFT) == 0; const bool do_copy = event->type == EVT_CKEY && is_press_ctrl_but_no_shift; const bool do_paste = event->type == EVT_VKEY && is_press_ctrl_but_no_shift; @@ -7934,12 +7931,14 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * /* do copy first, because it is the only allowed operator when disabled */ if (do_copy) { - ui_but_copy(C, but, event->alt); + ui_but_copy(C, but, event->modifier & KM_ALT); return WM_UI_HANDLER_BREAK; } /* handle menu */ - if ((event->type == RIGHTMOUSE) && !IS_EVENT_MOD(event, shift, ctrl, alt, oskey) && + + if ((event->type == RIGHTMOUSE) && + (event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) == 0 && (event->val == KM_PRESS)) { /* For some button types that are typically representing entire sets of data, right-clicking * to spawn the context menu should also activate the item. This makes it clear which item @@ -7960,7 +7959,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * } if (do_paste) { - ui_but_paste(C, but, data, event->alt); + ui_but_paste(C, but, data, event->modifier & KM_ALT); return WM_UI_HANDLER_BREAK; } @@ -8947,7 +8946,7 @@ static int ui_handle_button_over(bContext *C, const wmEvent *event, ARegion *reg if (but) { button_activate_init(C, region, but, BUTTON_ACTIVATE_OVER); - if (event->alt && but->active) { + if ((event->modifier & KM_ALT) && but->active) { /* Display tool-tips if holding Alt on mouse-over when tool-tips are disabled in the * preferences. */ but->active->tooltip_force = true; @@ -9555,9 +9554,9 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi } else if (val == KM_PRESS) { if ((ELEM(type, EVT_UPARROWKEY, EVT_DOWNARROWKEY, EVT_LEFTARROWKEY, EVT_RIGHTARROWKEY) && - !IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) || - ((ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && event->ctrl && - !IS_EVENT_MOD(event, shift, alt, oskey)))) { + (event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) == 0) || + ((ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && (event->modifier & KM_CTRL) && + (event->modifier & (KM_SHIFT | KM_ALT | KM_OSKEY)) == 0))) { const int value_orig = RNA_property_int_get(&listbox->rnapoin, listbox->rnaprop); int value, min, max; @@ -9614,7 +9613,7 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi } retval = WM_UI_HANDLER_BREAK; } - else if (ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && event->shift) { + else if (ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && (event->modifier & KM_SHIFT)) { /* We now have proper grip, but keep this anyway! */ if (ui_list->list_grip < (dyn_data->visual_height_min - UI_LIST_AUTO_SIZE_THRESHOLD)) { ui_list->list_grip = dyn_data->visual_height; @@ -10268,7 +10267,7 @@ static int ui_handle_menu_event(bContext *C, /* Smooth scrolling for popovers. */ case MOUSEPAN: { - if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { + if (event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) { /* pass */ } else if (!ui_block_is_menu(block)) { @@ -10290,7 +10289,7 @@ static int ui_handle_menu_event(bContext *C, } case WHEELUPMOUSE: case WHEELDOWNMOUSE: { - if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { + if (event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) { /* pass */ } else if (!ui_block_is_menu(block)) { @@ -10313,7 +10312,7 @@ static int ui_handle_menu_event(bContext *C, case EVT_HOMEKEY: case EVT_ENDKEY: /* Arrow-keys: only handle for block_loop blocks. */ - if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { + if (event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) { /* pass */ } else if (inside || (block->flag & UI_BLOCK_LOOP)) { @@ -10464,7 +10463,7 @@ static int ui_handle_menu_event(bContext *C, break; } - if (event->alt) { + if (event->modifier & KM_ALT) { act += 10; } @@ -10544,7 +10543,7 @@ static int ui_handle_menu_event(bContext *C, case EVT_YKEY: case EVT_ZKEY: { if (ELEM(event->val, KM_PRESS, KM_DBL_CLICK) && - !IS_EVENT_MOD(event, shift, ctrl, oskey) && + ((event->modifier & (KM_SHIFT | KM_CTRL | KM_OSKEY)) == 0) && /* Only respond to explicit press to avoid the event that opened the menu * activating an item when the key is held. */ !event->is_repeat) { @@ -11071,7 +11070,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle case EVT_YKEY: case EVT_ZKEY: { if ((ELEM(event->val, KM_PRESS, KM_DBL_CLICK)) && - !IS_EVENT_MOD(event, shift, ctrl, oskey)) { + ((event->modifier & (KM_SHIFT | KM_CTRL | KM_OSKEY)) == 0)) { LISTBASE_FOREACH (uiBut *, but, &block->buttons) { if (but->menu_key == event->type) { ui_but_pie_button_activate(C, but, menu); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 54a5b496048..bd55d2d9d81 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -492,7 +492,7 @@ static void ui_layer_but_cb(bContext *C, void *arg_but, void *arg_index) PointerRNA *ptr = &but->rnapoin; PropertyRNA *prop = but->rnaprop; const int index = POINTER_AS_INT(arg_index); - const int shift = win->eventstate->shift; + const bool shift = win->eventstate->modifier & KM_SHIFT; const int len = RNA_property_array_length(ptr, prop); if (!shift) { @@ -752,7 +752,7 @@ static void ui_item_enum_expand_handle(bContext *C, void *arg1, void *arg2) { wmWindow *win = CTX_wm_window(C); - if (!win->eventstate->shift) { + if ((win->eventstate->modifier & KM_SHIFT) == 0) { uiBut *but = (uiBut *)arg1; const int enum_value = POINTER_AS_INT(arg2); diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 2cb0f256b71..c7f2eb230cb 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -2061,8 +2061,8 @@ static void ui_handle_panel_header(const bContext *C, const uiBlock *block, const int mx, const int event_type, - const short ctrl, - const short shift) + const bool ctrl, + const bool shift) { Panel *panel = block->panel; ARegion *region = CTX_wm_region(C); @@ -2274,7 +2274,7 @@ static int ui_handle_panel_category_cycling(const wmEvent *event, (event->mval[0] > ((PanelCategoryDyn *)region->panels_category.first)->rect.xmin)); /* If mouse is inside non-tab region, ctrl key is required. */ - if (is_mousewheel && !event->ctrl && !inside_tabregion) { + if (is_mousewheel && (event->modifier & KM_CTRL) == 0 && !inside_tabregion) { return WM_UI_HANDLER_CONTINUE; } @@ -2291,7 +2291,7 @@ static int ui_handle_panel_category_cycling(const wmEvent *event, pc_dyn = (event->type == WHEELDOWNMOUSE) ? pc_dyn->next : pc_dyn->prev; } else { - const bool backwards = event->shift; + const bool backwards = event->modifier & KM_SHIFT; pc_dyn = backwards ? pc_dyn->prev : pc_dyn->next; if (!pc_dyn) { /* Proper cyclic behavior, back to first/last category (only used for ctrl+tab). */ @@ -2349,7 +2349,7 @@ int ui_handler_panel_region(bContext *C, retval = WM_UI_HANDLER_BREAK; } } - else if ((event->type == EVT_TABKEY && event->ctrl) || + else if (((event->type == EVT_TABKEY) && (event->modifier & KM_CTRL)) || ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE)) { /* Cycle tabs. */ retval = ui_handle_panel_category_cycling(event, region, active_but); @@ -2386,9 +2386,11 @@ int ui_handler_panel_region(bContext *C, /* The panel collapse / expand key "A" is special as it takes priority over * active button handling. */ - if (event->type == EVT_AKEY && !IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { + if (event->type == EVT_AKEY && + ((event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) == 0)) { retval = WM_UI_HANDLER_BREAK; - ui_handle_panel_header(C, block, mx, event->type, event->ctrl, event->shift); + ui_handle_panel_header( + C, block, mx, event->type, event->modifier & KM_CTRL, event->modifier & KM_SHIFT); break; } } @@ -2402,7 +2404,8 @@ int ui_handler_panel_region(bContext *C, /* All mouse clicks inside panel headers should return in break. */ if (ELEM(event->type, EVT_RETKEY, EVT_PADENTER, LEFTMOUSE)) { retval = WM_UI_HANDLER_BREAK; - ui_handle_panel_header(C, block, mx, event->type, event->ctrl, event->shift); + ui_handle_panel_header( + C, block, mx, event->type, event->modifier & KM_CTRL, event->modifier & KM_SHIFT); } else if (event->type == RIGHTMOUSE) { retval = WM_UI_HANDLER_BREAK; diff --git a/source/blender/editors/interface/interface_query.c b/source/blender/editors/interface/interface_query.c index 8a945c8c913..4703367671d 100644 --- a/source/blender/editors/interface/interface_query.c +++ b/source/blender/editors/interface/interface_query.c @@ -310,7 +310,7 @@ uiBut *ui_but_find_mouse_over_ex(const ARegion *region, uiBut *ui_but_find_mouse_over(const ARegion *region, const wmEvent *event) { - return ui_but_find_mouse_over_ex(region, event->xy, event->ctrl != 0, NULL, NULL); + return ui_but_find_mouse_over_ex(region, event->xy, event->modifier & KM_CTRL, NULL, NULL); } uiBut *ui_but_find_rect_over(const struct ARegion *region, const rcti *rect_px) diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index 09faf493ce7..29553ff65d1 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -701,7 +701,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is /* Keymap */ /* This is too handy not to expose somehow, let's be sneaky for now. */ - if ((is_label == false) && CTX_wm_window(C)->eventstate->shift) { + if ((is_label == false) && CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { const char *expr_imports[] = {"bpy", "bl_ui", NULL}; char expr[256]; SNPRINTF(expr, diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index f8fbc2d01a6..32b3bb5e926 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -609,7 +609,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event) RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr, NULL); RNA_property_update(C, &template_ui->ptr, template_ui->prop); - if (id && CTX_wm_window(C)->eventstate->shift) { + if (id && CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { /* only way to force-remove data (on save) */ id_us_clear_real(id); id_fake_user_clear(id); @@ -635,7 +635,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event) case UI_ID_LOCAL: if (id) { Main *bmain = CTX_data_main(C); - if (CTX_wm_window(C)->eventstate->shift) { + if (CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { if (ID_IS_OVERRIDABLE_LIBRARY(id)) { /* Only remap that specific ID usage to overriding local data-block. */ ID *override_id = BKE_lib_override_library_create_from_id(bmain, id, false); @@ -5539,7 +5539,7 @@ static void handle_layer_buttons(bContext *C, void *arg1, void *arg2) uiBut *but = arg1; const int cur = POINTER_AS_INT(arg2); wmWindow *win = CTX_wm_window(C); - const int shift = win->eventstate->shift; + const bool shift = win->eventstate->modifier & KM_SHIFT; if (!shift) { const int tot = RNA_property_array_length(&but->rnapoin, but->rnaprop); diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c index 429db50f321..e53dda1760e 100644 --- a/source/blender/editors/mesh/editmesh_bevel.c +++ b/source/blender/editors/mesh/editmesh_bevel.c @@ -546,7 +546,7 @@ static void edbm_bevel_mouse_set_value(wmOperator *op, const wmEvent *event) value = value_start[vmode] + value * opdata->scale[vmode]; /* Fake shift-transform... */ - if (event->shift) { + if (event->modifier & KM_SHIFT) { if (opdata->shift_value[vmode] < 0.0f) { opdata->shift_value[vmode] = (vmode == SEGMENTS_VALUE) ? opdata->segments : diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c index b2ed6780443..c9fc48c3568 100644 --- a/source/blender/editors/mesh/editmesh_loopcut.c +++ b/source/blender/editors/mesh/editmesh_loopcut.c @@ -581,7 +581,7 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event) handled = true; break; case MOUSEPAN: - if (event->alt == 0) { + if ((event->modifier & KM_ALT) == 0) { cuts += 0.02f * (event->xy[1] - event->prev_xy[1]); if (cuts < 1 && lcd->cuts >= 1) { cuts = 1; @@ -598,7 +598,7 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event) if (event->val == KM_RELEASE) { break; } - if (event->alt == 0) { + if ((event->modifier & KM_ALT) == 0) { cuts += 1; } else { @@ -612,7 +612,7 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event) if (event->val == KM_RELEASE) { break; } - if (event->alt == 0) { + if ((event->modifier & KM_ALT) == 0) { cuts = max_ff(cuts - 1, 1); } else { diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index fc1d60fc768..d8fc7a4f9d4 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -1367,10 +1367,10 @@ static int edbm_select_mode_invoke(bContext *C, wmOperator *op, const wmEvent *e /* detecting these options based on shift/ctrl here is weak, but it's done * to make this work when clicking buttons or menus */ if (!RNA_struct_property_is_set(op->ptr, "use_extend")) { - RNA_boolean_set(op->ptr, "use_extend", event->shift); + RNA_boolean_set(op->ptr, "use_extend", event->modifier & KM_SHIFT); } if (!RNA_struct_property_is_set(op->ptr, "use_expand")) { - RNA_boolean_set(op->ptr, "use_expand", event->ctrl); + RNA_boolean_set(op->ptr, "use_expand", event->modifier & KM_CTRL); } return edbm_select_mode_exec(C, op); diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 203e18f9621..4da278b7a31 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -340,10 +340,10 @@ static int object_hide_collection_exec(bContext *C, wmOperator *op) View3D *v3d = CTX_wm_view3d(C); int index = RNA_int_get(op->ptr, "collection_index"); - const bool extend = (win->eventstate->shift != 0); + const bool extend = (win->eventstate->modifier & KM_SHIFT) != 0; const bool toggle = RNA_boolean_get(op->ptr, "toggle"); - if (win->eventstate->alt != 0) { + if (win->eventstate->modifier & KM_ALT) { index += 10; } @@ -1427,7 +1427,7 @@ static int object_clear_paths_exec(bContext *C, wmOperator *op) /* operator callback/wrapper */ static int object_clear_paths_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - if ((event->shift) && !RNA_struct_property_is_set(op->ptr, "only_selected")) { + if ((event->modifier & KM_SHIFT) && !RNA_struct_property_is_set(op->ptr, "only_selected")) { RNA_boolean_set(op->ptr, "only_selected", true); } return object_clear_paths_exec(C, op); diff --git a/source/blender/editors/object/object_remesh.cc b/source/blender/editors/object/object_remesh.cc index 44e6fb10528..2e495ac6147 100644 --- a/source/blender/editors/object/object_remesh.cc +++ b/source/blender/editors/object/object_remesh.cc @@ -406,7 +406,7 @@ static int voxel_size_edit_modal(bContext *C, wmOperator *op, const wmEvent *eve d = cd->slow_mval[0] - mval[0]; } - if (event->ctrl) { + if (event->modifier & KM_CTRL) { /* Linear mode, enables jumping to any voxel size. */ d = d * 0.0005f; } diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 94aa7d59f9d..9e82abf4d07 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -1861,7 +1861,7 @@ static int object_transform_axis_target_modal(bContext *C, wmOperator *op, const view3d_operator_needs_opengl(C); - const bool is_translate = (event->ctrl != 0); + const bool is_translate = event->modifier & KM_CTRL; const bool is_translate_init = is_translate && (xfd->is_translate != is_translate); if (event->type == MOUSEMOVE || is_translate_init) { diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index af9496263e7..6307f6dc37f 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -4963,7 +4963,7 @@ static void brush_edit_apply_event(bContext *C, wmOperator *op, const wmEvent *e RNA_collection_add(op->ptr, "stroke", &itemptr); RNA_float_set_array(&itemptr, "mouse", mouse); - RNA_boolean_set(&itemptr, "pen_flip", event->shift != false); /* XXX hardcoded */ + RNA_boolean_set(&itemptr, "pen_flip", event->modifier & KM_SHIFT); /* XXX hardcoded */ /* apply */ brush_edit_apply(C, op, &itemptr); diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 7c4623dd4b0..ae7570d21a1 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -1496,7 +1496,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event, PaintS return OPERATOR_FINISHED; } else if (br->flag & BRUSH_LINE) { - if (event->alt) { + if (event->modifier & KM_ALT) { stroke->constrain_line = true; } else { diff --git a/source/blender/editors/sculpt_paint/sculpt_mask_expand.c b/source/blender/editors/sculpt_paint/sculpt_mask_expand.c index 72640893dea..8fc10061f83 100644 --- a/source/blender/editors/sculpt_paint/sculpt_mask_expand.c +++ b/source/blender/editors/sculpt_paint/sculpt_mask_expand.c @@ -245,7 +245,7 @@ static int sculpt_mask_expand_modal(bContext *C, wmOperator *op, const wmEvent * /* When pressing Ctrl, expand directly to the max number of iterations. This allows to flood fill * mask and face sets by connectivity directly. */ - if (event->ctrl) { + if (event->modifier & KM_CTRL) { mask_expand_update_it = ss->filter_cache->mask_update_last_it - 1; } diff --git a/source/blender/editors/space_action/action_data.c b/source/blender/editors/space_action/action_data.c index e383ada1331..8e8902c2ea7 100644 --- a/source/blender/editors/space_action/action_data.c +++ b/source/blender/editors/space_action/action_data.c @@ -659,7 +659,7 @@ static int action_unlink_invoke(bContext *C, wmOperator *op, const wmEvent *even { /* NOTE: this is hardcoded to match the behavior for the unlink button * (in interface_templates.c). */ - RNA_boolean_set(op->ptr, "force_delete", event->shift != 0); + RNA_boolean_set(op->ptr, "force_delete", event->modifier & KM_SHIFT); return action_unlink_exec(C, op); } diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index cad6d34af24..e215b7c7992 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -282,11 +282,11 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event) /* Useful yet irritating feature, Shift+Click to open the file * Alt+Click to browse a folder in the OS's browser. */ - if (event->shift || event->alt) { + if (event->modifier & (KM_SHIFT | KM_ALT)) { wmOperatorType *ot = WM_operatortype_find("WM_OT_path_open", true); PointerRNA props_ptr; - if (event->alt) { + if (event->modifier & KM_ALT) { char *lslash = (char *)BLI_path_slash_rfind(str); if (lslash) { *lslash = '\0'; diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index 3fba069879b..a24eae6a0ce 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -408,7 +408,7 @@ static int console_insert_invoke(bContext *C, wmOperator *op, const wmEvent *eve * (when input method are used for utf8 inputs, the user may assign key event * including alt/ctrl/super like ctrl+m to commit utf8 string. in such case, * the modifiers in the utf8 character event make no sense.) */ - if ((event->ctrl || event->oskey) && !event->utf8_buf[0]) { + if ((event->modifier & (KM_CTRL | KM_OSKEY)) && !event->utf8_buf[0]) { return OPERATOR_PASS_THROUGH; } diff --git a/source/blender/editors/space_nla/nla_channels.c b/source/blender/editors/space_nla/nla_channels.c index 4a507aa3bf2..8b059b33a9a 100644 --- a/source/blender/editors/space_nla/nla_channels.c +++ b/source/blender/editors/space_nla/nla_channels.c @@ -583,7 +583,7 @@ static int nla_action_unlink_invoke(bContext *C, wmOperator *op, const wmEvent * { /* NOTE: this is hardcoded to match the behavior for the unlink button * (in interface_templates.c) */ - RNA_boolean_set(op->ptr, "force_delete", event->shift != 0); + RNA_boolean_set(op->ptr, "force_delete", event->modifier & KM_SHIFT); return nla_action_unlink_exec(C, op); } diff --git a/source/blender/editors/space_outliner/outliner_collections.cc b/source/blender/editors/space_outliner/outliner_collections.cc index 765661aa9d5..f38f6c2855d 100644 --- a/source/blender/editors/space_outliner/outliner_collections.cc +++ b/source/blender/editors/space_outliner/outliner_collections.cc @@ -1071,7 +1071,7 @@ static int collection_isolate_exec(bContext *C, wmOperator *op) static int collection_isolate_invoke(bContext *C, wmOperator *op, const wmEvent *event) { PropertyRNA *prop = RNA_struct_find_property(op->ptr, "extend"); - if (!RNA_property_is_set(op->ptr, prop) && (event->shift)) { + if (!RNA_property_is_set(op->ptr, prop) && (event->modifier & KM_SHIFT)) { RNA_property_boolean_set(op->ptr, prop, true); } return collection_isolate_exec(C, op); diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.cc b/source/blender/editors/space_outliner/outliner_dragdrop.cc index 0d8ee76d2f0..edd2e5f304f 100644 --- a/source/blender/editors/space_outliner/outliner_dragdrop.cc +++ b/source/blender/editors/space_outliner/outliner_dragdrop.cc @@ -319,7 +319,7 @@ static bool parent_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) } if (!allow_parenting_without_modifier_key(space_outliner)) { - if (!event->shift) { + if ((event->modifier & KM_SHIFT) == 0) { return false; } } @@ -417,8 +417,12 @@ static int parent_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event) ListBase *lb = reinterpret_cast<ListBase *>(event->customdata); wmDrag *drag = reinterpret_cast<wmDrag *>(lb->first); - parent_drop_set_parents( - C, op->reports, reinterpret_cast<wmDragID *>(drag->ids.first), par, PAR_OBJECT, event->alt); + parent_drop_set_parents(C, + op->reports, + reinterpret_cast<wmDragID *>(drag->ids.first), + par, + PAR_OBJECT, + event->modifier & KM_ALT); return OPERATOR_FINISHED; } @@ -446,7 +450,7 @@ static bool parent_clear_poll(bContext *C, wmDrag *drag, const wmEvent *event) SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); if (!allow_parenting_without_modifier_key(space_outliner)) { - if (!event->shift) { + if ((event->modifier & KM_SHIFT) == 0) { return false; } } @@ -471,7 +475,7 @@ static bool parent_clear_poll(bContext *C, wmDrag *drag, const wmEvent *event) case ID_OB: return ELEM(tselem->type, TSE_MODIFIER_BASE, TSE_CONSTRAINT_BASE); case ID_GR: - return event->shift || ELEM(tselem->type, TSE_LIBRARY_OVERRIDE_BASE); + return (event->modifier & KM_SHIFT) || ELEM(tselem->type, TSE_LIBRARY_OVERRIDE_BASE); default: return true; } @@ -496,7 +500,8 @@ static int parent_clear_invoke(bContext *C, wmOperator *UNUSED(op), const wmEven if (GS(drag_id->id->name) == ID_OB) { Object *object = (Object *)drag_id->id; - ED_object_parent_clear(object, event->alt ? CLEAR_PARENT_KEEP_TRANSFORM : CLEAR_PARENT_ALL); + ED_object_parent_clear( + object, (event->modifier & KM_ALT) ? CLEAR_PARENT_KEEP_TRANSFORM : CLEAR_PARENT_ALL); } } @@ -1166,10 +1171,11 @@ static bool collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event &space_outliner->tree, TSE_HIGHLIGHTED_ANY | TSE_DRAG_ANY, false); CollectionDrop data; - if (!event->shift && collection_drop_init(C, drag, event->xy, event->ctrl, &data)) { + if (((event->modifier & KM_SHIFT) == 0) && + collection_drop_init(C, drag, event->xy, event->modifier & KM_CTRL, &data)) { TreeElement *te = data.te; TreeStoreElem *tselem = TREESTORE(te); - if (!data.from || event->ctrl) { + if (!data.from || event->modifier & KM_CTRL) { tselem->flag |= TSE_DRAG_INTO; changed = true; } @@ -1210,9 +1216,10 @@ static char *collection_drop_tooltip(bContext *C, const wmEvent *event = win ? win->eventstate : nullptr; CollectionDrop data; - if (event && !event->shift && collection_drop_init(C, drag, xy, event->ctrl, &data)) { + if (event && ((event->modifier & KM_SHIFT) == 0) && + collection_drop_init(C, drag, xy, event->modifier & KM_CTRL, &data)) { TreeElement *te = data.te; - if (!data.from || event->ctrl) { + if (!data.from || event->modifier & KM_CTRL) { return BLI_strdup(TIP_("Link inside Collection")); } switch (data.insert_type) { @@ -1263,7 +1270,7 @@ static int collection_drop_invoke(bContext *C, wmOperator *UNUSED(op), const wmE wmDrag *drag = reinterpret_cast<wmDrag *>(lb->first); CollectionDrop data; - if (!collection_drop_init(C, drag, event->xy, event->ctrl, &data)) { + if (!collection_drop_init(C, drag, event->xy, event->modifier & KM_CTRL, &data)) { return OPERATOR_CANCELLED; } @@ -1291,7 +1298,9 @@ static int collection_drop_invoke(bContext *C, wmOperator *UNUSED(op), const wmE LISTBASE_FOREACH (wmDragID *, drag_id, &drag->ids) { /* Ctrl enables linking, so we don't need a from collection then. */ - Collection *from = (event->ctrl) ? nullptr : collection_parent_from_ID(drag_id->from_parent); + Collection *from = (event->modifier & KM_CTRL) ? + nullptr : + collection_parent_from_ID(drag_id->from_parent); if (GS(drag_id->id->name) == ID_OB) { /* Move/link object into collection. */ diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc index bc58ad226ee..2da416c8671 100644 --- a/source/blender/editors/space_outliner/outliner_draw.cc +++ b/source/blender/editors/space_outliner/outliner_draw.cc @@ -166,7 +166,7 @@ static void restrictbutton_bone_visibility_fn(bContext *C, void *poin, void *UNU { Bone *bone = (Bone *)poin; - if (CTX_wm_window(C)->eventstate->shift) { + if (CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { restrictbutton_recursive_bone(bone, BONE_HIDDEN_P, (bone->flag & BONE_HIDDEN_P) != 0); } } @@ -178,7 +178,7 @@ static void restrictbutton_bone_select_fn(bContext *C, void *UNUSED(poin), void bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); } - if (CTX_wm_window(C)->eventstate->shift) { + if (CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { restrictbutton_recursive_bone(bone, BONE_UNSELECTABLE, (bone->flag & BONE_UNSELECTABLE) != 0); } @@ -194,7 +194,7 @@ static void restrictbutton_ebone_select_fn(bContext *C, void *poin, void *poin2) ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); } - if (CTX_wm_window(C)->eventstate->shift) { + if (CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { restrictbutton_recursive_ebone( arm, ebone, BONE_UNSELECTABLE, (ebone->flag & BONE_UNSELECTABLE) != 0); } @@ -210,7 +210,7 @@ static void restrictbutton_ebone_visibility_fn(bContext *C, void *poin, void *po ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); } - if (CTX_wm_window(C)->eventstate->shift) { + if (CTX_wm_window(C)->eventstate->modifier & KM_SHIFT) { restrictbutton_recursive_ebone(arm, ebone, BONE_HIDDEN_A, (ebone->flag & BONE_HIDDEN_A) != 0); } @@ -250,7 +250,7 @@ static void outliner_object_set_flag_recursive_fn(bContext *C, ViewLayer *view_layer = CTX_data_view_layer(C); PointerRNA ptr; - bool extend = (win->eventstate->shift != 0); + bool extend = (win->eventstate->modifier & KM_SHIFT); if (!extend) { return; @@ -571,8 +571,8 @@ static void outliner_collection_set_flag_recursive_fn(bContext *C, ViewLayer *view_layer = CTX_data_view_layer(C); PointerRNA ptr; - bool do_isolate = (win->eventstate->ctrl != 0); - bool extend = (win->eventstate->shift != 0); + bool do_isolate = (win->eventstate->modifier & KM_CTRL); + bool extend = (win->eventstate->modifier & KM_SHIFT); if (!ELEM(true, do_isolate, extend)) { return; @@ -2043,7 +2043,7 @@ static void outliner_mode_toggle_fn(bContext *C, void *tselem_poin, void *UNUSED const bool object_data_shared = (ob->data == tvc.obact->data); wmWindow *win = CTX_wm_window(C); - const bool do_extend = win->eventstate->ctrl != 0 && !object_data_shared; + const bool do_extend = (win->eventstate->modifier & KM_CTRL) && !object_data_shared; outliner_item_mode_toggle(C, &tvc, te, do_extend); } diff --git a/source/blender/editors/space_text/text_autocomplete.c b/source/blender/editors/space_text/text_autocomplete.c index 496f500ef04..55873740491 100644 --- a/source/blender/editors/space_text/text_autocomplete.c +++ b/source/blender/editors/space_text/text_autocomplete.c @@ -408,7 +408,7 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e case EVT_BACKSPACEKEY: if (event->val == KM_PRESS) { if (tools & TOOL_SUGG_LIST) { - if (event->ctrl) { + if (event->modifier & KM_CTRL) { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; draw = 1; @@ -445,7 +445,7 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e case EVT_RIGHTARROWKEY: if (event->val == KM_PRESS) { if (tools & TOOL_SUGG_LIST) { - if (event->ctrl) { + if (event->modifier & KM_CTRL) { texttool_suggest_clear(); retval = OPERATOR_CANCELLED; draw = 1; diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index ddba6803f61..3c29b32c2fa 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -3495,7 +3495,7 @@ static int text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event) * (when input method are used for utf8 inputs, the user may assign key event * including alt/ctrl/super like ctrl+m to commit utf8 string. in such case, * the modifiers in the utf8 character event make no sense.) */ - if ((event->ctrl || event->oskey) && !event->utf8_buf[0]) { + if ((event->modifier & (KM_CTRL | KM_OSKEY)) && !event->utf8_buf[0]) { return OPERATOR_PASS_THROUGH; } diff --git a/source/blender/editors/space_view3d/view3d_cursor_snap.c b/source/blender/editors/space_view3d/view3d_cursor_snap.c index 785c5ab28c8..53f7b3d5871 100644 --- a/source/blender/editors/space_view3d/view3d_cursor_snap.c +++ b/source/blender/editors/space_view3d/view3d_cursor_snap.c @@ -63,7 +63,7 @@ typedef struct SnapCursorDataIntern { int x; int y; #ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK - short shift, ctrl, alt, oskey; + uint8_t modifier; #endif } last_eventstate; @@ -478,10 +478,7 @@ static bool v3d_cursor_eventstate_has_changed(SnapCursorDataIntern *data_intern, } #ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK if (!(state && (state->flag & V3D_SNAPCURSOR_TOGGLE_ALWAYS_TRUE))) { - if ((event->ctrl != data_intern->last_eventstate.ctrl) || - (event->shift != data_intern->last_eventstate.shift) || - (event->alt != data_intern->last_eventstate.alt) || - (event->oskey != data_intern->last_eventstate.oskey)) { + if (event->modifier != data_intern->last_eventstate.modifier) { return true; } } @@ -507,19 +504,13 @@ static bool v3d_cursor_is_snap_invert(SnapCursorDataIntern *data_intern, const w } const wmEvent *event = wm->winactive->eventstate; - if ((event->ctrl == data_intern->last_eventstate.ctrl) && - (event->shift == data_intern->last_eventstate.shift) && - (event->alt == data_intern->last_eventstate.alt) && - (event->oskey == data_intern->last_eventstate.oskey)) { + if (event->modifier == data_intern->last_eventstate.modifier) { /* Nothing has changed. */ return data_intern->snap_data.is_snap_invert; } /* Save new eventstate. */ - data_intern->last_eventstate.ctrl = event->ctrl; - data_intern->last_eventstate.shift = event->shift; - data_intern->last_eventstate.alt = event->alt; - data_intern->last_eventstate.oskey = event->oskey; + data_intern->last_eventstate.modifier = event->modifier; const int snap_on = data_intern->snap_on; @@ -530,10 +521,10 @@ static bool v3d_cursor_is_snap_invert(SnapCursorDataIntern *data_intern, const w } if (kmi->propvalue == snap_on) { - 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)) { + if ((ELEM(kmi->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY) && (event->modifier & KM_CTRL)) || + (ELEM(kmi->type, EVT_LEFTSHIFTKEY, EVT_RIGHTSHIFTKEY) && (event->modifier & KM_SHIFT)) || + (ELEM(kmi->type, EVT_LEFTALTKEY, EVT_RIGHTALTKEY) && (event->modifier & KM_ALT)) || + ((kmi->type == EVT_OSKEY) && (event->modifier & KM_OSKEY))) { return true; } } diff --git a/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c b/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c index 6cc197c8a43..a0c010a6813 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c @@ -105,8 +105,8 @@ static int gizmo_preselect_elem_test_select(bContext *C, wmGizmo *gz, const int MeshElemGizmo3D *gz_ele = (MeshElemGizmo3D *)gz; /* Hack: Switch action mode based on key input */ - const bool is_ctrl_pressed = WM_event_modifier_flag(event) & KM_CTRL; - const bool is_shift_pressed = WM_event_modifier_flag(event) & KM_SHIFT; + const bool is_ctrl_pressed = (event->modifier & KM_CTRL) != 0; + const bool is_shift_pressed = (event->modifier & KM_SHIFT) != 0; EDBM_preselect_action_set(gz_ele->psel, PRESELECT_ACTION_TRANSFORM); if (is_ctrl_pressed && !is_shift_pressed) { EDBM_preselect_action_set(gz_ele->psel, PRESELECT_ACTION_CREATE); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 923084854e1..b006b13d217 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1153,7 +1153,7 @@ int transformEvent(TransInfo *t, const wmEvent *event) if (event->is_repeat) { break; } - if (event->alt) { + if (event->modifier & KM_ALT) { if (!(t->options & CTX_NO_PET)) { t->flag ^= T_PROP_CONNECTED; sort_trans_data_dist(t); @@ -1167,7 +1167,7 @@ int transformEvent(TransInfo *t, const wmEvent *event) if (event->is_repeat) { break; } - if (t->flag & T_PROP_EDIT && event->shift) { + if ((t->flag & T_PROP_EDIT) && (event->modifier & KM_SHIFT)) { t->prop_mode = (t->prop_mode + 1) % PROP_MODE_MAX; calculatePropRatio(t); t->redraw |= TREDRAW_HARD; @@ -1175,7 +1175,7 @@ int transformEvent(TransInfo *t, const wmEvent *event) } break; case EVT_PADPLUSKEY: - if (event->alt && t->flag & T_PROP_EDIT) { + if ((event->modifier & KM_ALT) && (t->flag & T_PROP_EDIT)) { t->prop_size *= (t->modifiers & MOD_PRECISION) ? 1.01f : 1.1f; if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO) { t->prop_size = min_ff(t->prop_size, ((View3D *)t->view)->clip_end); @@ -1186,7 +1186,7 @@ int transformEvent(TransInfo *t, const wmEvent *event) } break; case EVT_PADMINUS: - if (event->alt && t->flag & T_PROP_EDIT) { + if ((event->modifier & KM_ALT) && (t->flag & T_PROP_EDIT)) { t->prop_size /= (t->modifiers & MOD_PRECISION) ? 1.01f : 1.1f; calculatePropRatio(t); t->redraw = TREDRAW_HARD; @@ -1780,10 +1780,12 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve } 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)) { + if ((ELEM(kmi->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY) && + (event->modifier & KM_CTRL)) || + (ELEM(kmi->type, EVT_LEFTSHIFTKEY, EVT_RIGHTSHIFTKEY) && + (event->modifier & KM_SHIFT)) || + (ELEM(kmi->type, EVT_LEFTALTKEY, EVT_RIGHTALTKEY) && (event->modifier & KM_ALT)) || + ((kmi->type == EVT_OSKEY) && (event->modifier & KM_OSKEY))) { t->modifiers |= MOD_SNAP_INVERT; } break; diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index 329840e064b..f07fadb7fc1 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -1869,7 +1869,7 @@ static void WIDGETGROUP_gizmo_invoke_prepare(const bContext *C, if (axis != -1) { wmWindow *win = CTX_wm_window(C); /* Swap single axis for two-axis constraint. */ - bool flip = win->eventstate->shift; + bool flip = (win->eventstate->modifier & KM_SHIFT) != 0; BLI_assert(axis_idx != -1); const short axis_type = gizmo_get_axis_type(axis_idx); if (axis_type != MAN_AXES_ROTATE) { diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 37bc753517f..2f3c021ba38 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -308,7 +308,8 @@ eRedrawFlag handleSnapping(TransInfo *t, const wmEvent *event) eRedrawFlag status = TREDRAW_NOTHING; #if 0 /* XXX need a proper selector for all snap mode */ - if (BIF_snappingSupported(t->obedit) && event->type == TABKEY && event->shift) { + if (BIF_snappingSupported(t->obedit) && (event->type == EVT_TABKEY) && + (event->modifier & KM_SHIFT)) { /* toggle snap and reinit */ t->settings->snap_flag ^= SCE_SNAP; initSnapping(t, NULL); diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 15fe944be49..32d405df841 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -306,7 +306,7 @@ bool ED_editors_flush_edits(Main *bmain) /* ***** XXX: functions are using old blender names, cleanup later ***** */ void apply_keyb_grid( - int shift, int ctrl, float *val, float fac1, float fac2, float fac3, int invert) + bool shift, bool ctrl, float *val, float fac1, float fac2, float fac3, int invert) { /* fac1 is for 'nothing', fac2 for CTRL, fac3 for SHIFT */ if (invert) { diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c index 3bf226f6ba1..be6ac6e13e6 100644 --- a/source/blender/editors/util/numinput.c +++ b/source/blender/editors/util/numinput.c @@ -321,7 +321,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) if (U.flag & USER_FLAG_NUMINPUT_ADVANCED) #endif { - if ((event->ctrl == 0) && (event->alt == 0) && (event->ascii != '\0') && + if (((event->modifier & (KM_CTRL | KM_ALT)) == 0) && (event->ascii != '\0') && strchr("01234567890@%^&*-+/{}()[]<>.|", event->ascii)) { if (!(n->flag & NUM_EDIT_FULL)) { n->flag |= NUM_EDITED; @@ -339,7 +339,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) n->val_flag[idx] |= NUM_EDITED; return true; } - if (event->ctrl) { + if (event->modifier & KM_CTRL) { n->flag &= ~NUM_EDIT_FULL; return true; } @@ -375,7 +375,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) updated = true; break; } - else if (event->shift || !n->str[0]) { + else if ((event->modifier & KM_SHIFT) || !n->str[0]) { n->val[idx] = n->val_org[idx]; n->val_flag[idx] &= ~NUM_EDITED; n->str[0] = '\0'; @@ -390,7 +390,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) case EVT_DELKEY: if ((n->val_flag[idx] & NUM_EDITED) && n->str[0]) { int t_cur = cur = n->str_cur; - if (event->ctrl) { + if (event->modifier & KM_CTRL) { mode = STRCUR_JUMP_DELIM; } BLI_str_cursor_step_utf8(n->str, strlen(n->str), &t_cur, dir, mode, true); @@ -416,7 +416,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) ATTR_FALLTHROUGH; case EVT_RIGHTARROWKEY: cur = n->str_cur; - if (event->ctrl) { + if (event->modifier & KM_CTRL) { mode = STRCUR_JUMP_DELIM; } BLI_str_cursor_step_utf8(n->str, strlen(n->str), &cur, dir, mode, true); @@ -442,7 +442,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) n->val_flag[idx] &= ~(NUM_NEGATE | NUM_INVERSE); #endif - idx = (idx + idx_max + (event->ctrl ? 0 : 2)) % (idx_max + 1); + idx = (idx + idx_max + ((event->modifier & KM_CTRL) ? 0 : 2)) % (idx_max + 1); n->idx = idx; if (n->val_flag[idx] & NUM_EDITED) { value_to_editstr(n, idx); @@ -470,7 +470,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) n->val_flag[idx] |= NUM_EDITED; return true; } - else if (event->ctrl) { + else if (event->modifier & KM_CTRL) { n->flag &= ~NUM_EDIT_FULL; return true; } @@ -480,28 +480,28 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) #ifdef USE_FAKE_EDIT case EVT_PADMINUS: case EVT_MINUSKEY: - if (event->ctrl || !(n->flag & NUM_EDIT_FULL)) { + if ((event->modifier & KM_CTRL) || !(n->flag & NUM_EDIT_FULL)) { n->val_flag[idx] ^= NUM_NEGATE; updated = true; } break; case EVT_PADSLASHKEY: case EVT_SLASHKEY: - if (event->ctrl || !(n->flag & NUM_EDIT_FULL)) { + if ((event->modifier & KM_CTRL) || !(n->flag & NUM_EDIT_FULL)) { n->val_flag[idx] ^= NUM_INVERSE; updated = true; } break; #endif case EVT_CKEY: - if (event->ctrl) { + if (event->modifier & KM_CTRL) { /* Copy current `str` to the copy/paste buffer. */ WM_clipboard_text_set(n->str, 0); updated = true; } break; case EVT_VKEY: - if (event->ctrl) { + if (event->modifier & KM_CTRL) { /* extract the first line from the clipboard */ int pbuf_len; char *pbuf = WM_clipboard_text_get_firstline(false, &pbuf_len); @@ -531,7 +531,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) /* Up to this point, if we have a ctrl modifier, skip. * This allows to still access most of modals' shortcuts even in numinput mode. */ - if (!updated && event->ctrl) { + if (!updated && (event->modifier & KM_CTRL)) { return false; } diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c index 91b29049ecf..c0d0fe95c8c 100644 --- a/source/blender/editors/uvedit/uvedit_smart_stitch.c +++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c @@ -2598,7 +2598,7 @@ static int stitch_modal(bContext *C, wmOperator *op, const wmEvent *event) /* Increase limit */ case EVT_PADPLUSKEY: case WHEELUPMOUSE: - if (event->val == KM_PRESS && event->alt) { + if ((event->val == KM_PRESS) && (event->modifier & KM_ALT)) { ssc->limit_dist += 0.01f; if (!stitch_process_data(ssc, active_state, scene, false)) { stitch_cancel(C, op); @@ -2612,7 +2612,7 @@ static int stitch_modal(bContext *C, wmOperator *op, const wmEvent *event) /* Decrease limit */ case EVT_PADMINUS: case WHEELDOWNMOUSE: - if (event->val == KM_PRESS && event->alt) { + if ((event->val == KM_PRESS) && (event->modifier & KM_ALT)) { ssc->limit_dist -= 0.01f; ssc->limit_dist = MAX2(0.01f, ssc->limit_dist); if (!stitch_process_data(ssc, active_state, scene, false)) { @@ -2673,7 +2673,7 @@ static int stitch_modal(bContext *C, wmOperator *op, const wmEvent *event) /* Select geometry */ case RIGHTMOUSE: - if (!event->shift) { + if ((event->modifier & KM_SHIFT) == 0) { stitch_cancel(C, op); return OPERATOR_CANCELLED; } diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index b0021bd0f3d..16d1dc0e93f 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -2194,23 +2194,23 @@ static void rna_def_event(BlenderRNA *brna) /* modifiers */ prop = RNA_def_property(srna, "shift", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "shift", 1); + RNA_def_property_boolean_sdna(prop, NULL, "modifier", KM_SHIFT); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Shift", "True when the Shift key is held"); RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_WINDOWMANAGER); prop = RNA_def_property(srna, "ctrl", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "ctrl", 1); + RNA_def_property_boolean_sdna(prop, NULL, "modifier", KM_CTRL); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Ctrl", "True when the Ctrl key is held"); prop = RNA_def_property(srna, "alt", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "alt", 1); + RNA_def_property_boolean_sdna(prop, NULL, "modifier", KM_ALT); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Alt", "True when the Alt/Option key is held"); prop = RNA_def_property(srna, "oskey", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "oskey", 1); + RNA_def_property_boolean_sdna(prop, NULL, "modifier", KM_OSKEY); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "OS Key", "True when the Cmd key is held"); diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index 81cc72088a6..dc53b7a5e12 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -639,10 +639,19 @@ static wmEvent *rna_Window_event_add_simulate(wmWindow *win, e.xy[0] = x; e.xy[1] = y; - e.shift = shift; - e.ctrl = ctrl; - e.alt = alt; - e.oskey = oskey; + e.modifier = 0; + if (shift) { + e.modifier |= KM_SHIFT; + } + if (ctrl) { + e.modifier |= KM_CTRL; + } + if (alt) { + e.modifier |= KM_ALT; + } + if (oskey) { + e.modifier |= KM_OSKEY; + } e.ascii = '\0'; e.utf8_buf[0] = '\0'; diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index b00d441dd5d..ef8aed4c664 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -1427,8 +1427,6 @@ bool WM_window_modal_keymap_status_draw(struct bContext *C, */ void WM_event_print(const struct wmEvent *event); -int WM_event_modifier_flag(const struct wmEvent *event); - /** * For modal callbacks, check configuration for how to interpret exit with tweaks. */ diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index a95c2ee2bb2..2f431bcd208 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -635,9 +635,12 @@ typedef struct wmEvent { */ int prev_xy[2]; - /** Modifier states. */ - /** 'oskey' is apple or windows-key, value denotes order of pressed. */ - short shift, ctrl, alt, oskey; + /** + * Modifier states. + * #KM_SHIFT, #KM_CTRL, #KM_ALT & #KM_OSKEY is apple or windows-key. + */ + uint8_t modifier; + /** Raw-key modifier (allow using any key as a modifier). */ short keymodifier; diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c index ad902f0963e..f1ac19f4651 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c @@ -819,8 +819,6 @@ wmGizmo *wm_gizmomap_highlight_find(wmGizmoMap *gzmap, do_step[i] = WM_gizmo_context_check_drawstep(C, i); } - const int event_modifier = WM_event_modifier_flag(event); - LISTBASE_FOREACH (wmGizmoGroup *, gzgroup, &gzmap->groups) { /* If it were important we could initialize here, @@ -839,11 +837,11 @@ wmGizmo *wm_gizmomap_highlight_find(wmGizmoMap *gzmap, } if (step == WM_GIZMOMAP_DRAWSTEP_3D) { wm_gizmogroup_intersectable_gizmos_to_list( - wm, gzgroup, event_modifier, &visible_3d_gizmos); + wm, gzgroup, event->modifier, &visible_3d_gizmos); } else if (step == WM_GIZMOMAP_DRAWSTEP_2D) { if ((gz = wm_gizmogroup_find_intersected_gizmo( - wm, gzgroup, C, event_modifier, event->mval, r_part))) { + wm, gzgroup, C, event->modifier, event->mval, r_part))) { break; } } diff --git a/source/blender/windowmanager/intern/wm_event_query.c b/source/blender/windowmanager/intern/wm_event_query.c index 304d7f73eb1..751dcc61fa9 100644 --- a/source/blender/windowmanager/intern/wm_event_query.c +++ b/source/blender/windowmanager/intern/wm_event_query.c @@ -80,10 +80,10 @@ void WM_event_print(const wmEvent *event) prev_type_id, event->prev_val, prev_val_id, - event->shift, - event->ctrl, - event->alt, - event->oskey, + (event->modifier & KM_SHIFT) != 0, + (event->modifier & KM_CTRL) != 0, + (event->modifier & KM_ALT) != 0, + (event->modifier & KM_OSKEY) != 0, event->keymodifier, event->is_repeat, event->xy[0], @@ -129,24 +129,6 @@ void WM_event_print(const wmEvent *event) /** \name Event Modifier/Type Queries * \{ */ -int WM_event_modifier_flag(const wmEvent *event) -{ - int flag = 0; - if (event->ctrl) { - flag |= KM_CTRL; - } - if (event->alt) { - flag |= KM_ALT; - } - if (event->shift) { - flag |= KM_SHIFT; - } - if (event->oskey) { - flag |= KM_OSKEY; - } - return flag; -} - bool WM_event_type_mask_test(const int event_type, const enum eEventType_Mask mask) { /* Keyboard. */ @@ -491,8 +473,8 @@ int WM_event_absolute_delta_y(const struct wmEvent *event) */ bool WM_event_is_ime_switch(const struct wmEvent *event) { - return event->val == KM_PRESS && event->type == EVT_SPACEKEY && - (event->ctrl || event->oskey || event->alt); + return (event->val == KM_PRESS) && (event->type == EVT_SPACEKEY) && + (event->modifier & (KM_CTRL | KM_OSKEY | KM_ALT)); } #endif diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 8a19c99f59b..326b8c167b8 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2029,29 +2029,33 @@ static bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi) } } + const bool shift = (winevent->modifier & KM_SHIFT) != 0; + const bool ctrl = (winevent->modifier & KM_CTRL) != 0; + const bool alt = (winevent->modifier & KM_ALT) != 0; + const bool oskey = (winevent->modifier & KM_OSKEY) != 0; + /* Modifiers also check bits, so it allows modifier order. * Account for rare case of when these keys are used as the 'type' not as modifiers. */ if (kmi->shift != KM_ANY) { - if ((winevent->shift != kmi->shift) && !(winevent->shift & kmi->shift) && + if ((shift != kmi->shift) && !(shift & kmi->shift) && !ELEM(winevent->type, EVT_LEFTSHIFTKEY, EVT_RIGHTSHIFTKEY)) { return false; } } if (kmi->ctrl != KM_ANY) { - if (winevent->ctrl != kmi->ctrl && !(winevent->ctrl & kmi->ctrl) && + if (ctrl != kmi->ctrl && !(ctrl & kmi->ctrl) && !ELEM(winevent->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY)) { return false; } } if (kmi->alt != KM_ANY) { - if (winevent->alt != kmi->alt && !(winevent->alt & kmi->alt) && + if (alt != kmi->alt && !(alt & kmi->alt) && !ELEM(winevent->type, EVT_LEFTALTKEY, EVT_RIGHTALTKEY)) { return false; } } if (kmi->oskey != KM_ANY) { - if (winevent->oskey != kmi->oskey && !(winevent->oskey & kmi->oskey) && - (winevent->type != EVT_OSKEY)) { + if (oskey != kmi->oskey && !(oskey & kmi->oskey) && (winevent->type != EVT_OSKEY)) { return false; } } @@ -4487,19 +4491,18 @@ static void wm_eventemulation(wmEvent *event, bool test_only) if (U.flag & USER_TWOBUTTONMOUSE) { if (event->type == LEFTMOUSE) { - short *mod = ( + const uint8_t mod_test = ( #if !defined(WIN32) - (U.mouse_emulate_3_button_modifier == USER_EMU_MMB_MOD_OSKEY) ? &event->oskey : - &event->alt + (U.mouse_emulate_3_button_modifier == USER_EMU_MMB_MOD_OSKEY) ? KM_OSKEY : KM_ALT #else /* Disable for WIN32 for now because it accesses the start menu. */ - &event->alt + KM_ALT #endif ); if (event->val == KM_PRESS) { - if (*mod) { - *mod = 0; + if (event->modifier & mod_test) { + event->modifier &= ~mod_test; event->type = MIDDLEMOUSE; if (!test_only) { @@ -4511,7 +4514,7 @@ static void wm_eventemulation(wmEvent *event, bool test_only) /* Only send middle-mouse release if emulated. */ if (emulating_event == MIDDLEMOUSE) { event->type = MIDDLEMOUSE; - *mod = 0; + event->modifier &= ~mod_test; } if (!test_only) { @@ -4931,7 +4934,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void case GHOST_kEventKeyDown: case GHOST_kEventKeyUp: { GHOST_TEventKeyData *kd = customdata; - short keymodifier = KM_NOTHING; + bool keymodifier = 0; event.type = convert_key(kd->key); event.ascii = kd->ascii; /* Might be not NULL terminated. */ @@ -4981,29 +4984,57 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void case EVT_LEFTSHIFTKEY: case EVT_RIGHTSHIFTKEY: if (event.val == KM_PRESS) { - keymodifier = KM_MOD_HELD; + keymodifier = true; + } + if (keymodifier) { + event.modifier |= KM_SHIFT; + event_state->modifier |= KM_SHIFT; + } + else { + event.modifier &= ~KM_SHIFT; + event_state->modifier &= ~KM_SHIFT; } - event.shift = event_state->shift = keymodifier; break; case EVT_LEFTCTRLKEY: case EVT_RIGHTCTRLKEY: if (event.val == KM_PRESS) { - keymodifier = KM_MOD_HELD; + keymodifier = true; + } + if (keymodifier) { + event.modifier |= KM_CTRL; + event_state->modifier |= KM_CTRL; + } + else { + event.modifier &= ~KM_CTRL; + event_state->modifier &= ~KM_CTRL; } - event.ctrl = event_state->ctrl = keymodifier; break; case EVT_LEFTALTKEY: case EVT_RIGHTALTKEY: if (event.val == KM_PRESS) { - keymodifier = KM_MOD_HELD; + keymodifier = true; + } + if (keymodifier) { + event.modifier |= KM_ALT; + event_state->modifier |= KM_ALT; + } + else { + event.modifier &= ~KM_ALT; + event_state->modifier &= ~KM_ALT; } - event.alt = event_state->alt = keymodifier; break; case EVT_OSKEY: if (event.val == KM_PRESS) { - keymodifier = KM_MOD_HELD; + keymodifier = true; + } + if (keymodifier) { + event.modifier |= KM_OSKEY; + event_state->modifier |= KM_OSKEY; + } + else { + event.modifier &= ~KM_OSKEY; + event_state->modifier &= ~KM_OSKEY; } - event.oskey = event_state->oskey = keymodifier; break; default: if (event.val == KM_PRESS && event.keymodifier == 0) { @@ -5041,7 +5072,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void * XXX Keep global for now? */ if ((event.type == EVT_ESCKEY && event.val == KM_PRESS) && /* Check other modifiers because ms-windows uses these to bring up the task manager. */ - (event.shift == 0 && event.ctrl == 0 && event.alt == 0)) { + ((event.modifier & (KM_SHIFT | KM_CTRL | KM_ALT)) == 0)) { G.is_break = true; } @@ -5301,9 +5332,7 @@ wmKeyMapItem *WM_event_match_keymap_item_from_handlers( /** State storage to detect changes between calls to refresh the information. */ struct CursorKeymapInfo_State { - struct { - short shift, ctrl, alt, oskey; - } modifiers; + uint8_t modifier; short space_type; short region_type; /* Never use, just compare memory for changes. */ @@ -5326,10 +5355,7 @@ static void wm_event_cursor_store(struct CursorKeymapInfo_State *state, short region_type, const bToolRef *tref) { - state->modifiers.shift = event->shift; - state->modifiers.ctrl = event->ctrl; - state->modifiers.alt = event->alt; - state->modifiers.oskey = event->oskey; + state->modifier = event->modifier; state->space_type = space_type; state->region_type = region_type; state->tref = tref ? *tref : (bToolRef){0}; diff --git a/source/blender/windowmanager/intern/wm_operator_utils.c b/source/blender/windowmanager/intern/wm_operator_utils.c index 6f3f42bee53..5a817075cd5 100644 --- a/source/blender/windowmanager/intern/wm_operator_utils.c +++ b/source/blender/windowmanager/intern/wm_operator_utils.c @@ -115,11 +115,11 @@ static bool interactive_value_update(ValueInteraction *inter, (((float)(mval_curr - mval_init) / inter->context_vars.region->winx) * value_range)) * value_scale; - if (event->ctrl) { + if (event->modifier & KM_CTRL) { const double snap = 0.1; value_delta = (float)roundf((double)value_delta / snap) * snap; } - if (event->shift) { + if (event->modifier & KM_SHIFT) { value_delta *= 0.1f; } const float value_final = inter->init.prop_value + value_delta; @@ -133,8 +133,8 @@ static bool interactive_value_update(ValueInteraction *inter, } inter->prev.prop_value = value_final; - inter->prev.is_snap = event->ctrl; - inter->prev.is_precise = event->shift; + inter->prev.is_snap = (event->modifier & KM_CTRL) != 0; + inter->prev.is_precise = (event->modifier & KM_SHIFT) != 0; *r_value_final = value_final; return changed; diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index a476fb4fa13..6b8f7309d80 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -2822,7 +2822,7 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even float numValue; /* TODO: fix hardcoded events */ - bool snap = event->ctrl != 0; + bool snap = (event->modifier & KM_CTRL) != 0; /* Modal numinput active, try to handle numeric inputs first... */ if (event->val == KM_PRESS && has_numInput && handleNumInput(C, &rc->num_input, event)) { diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index a983150b504..cdfb6a81596 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -1104,10 +1104,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr win->active = 0; /* XXX */ /* clear modifiers for inactive windows */ - win->eventstate->alt = 0; - win->eventstate->ctrl = 0; - win->eventstate->shift = 0; - win->eventstate->oskey = 0; + win->eventstate->modifier = 0; win->eventstate->keymodifier = 0; break; @@ -1138,7 +1135,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr kdata.ascii = '\0'; kdata.utf8_buf[0] = '\0'; - if (win->eventstate->shift) { + if (win->eventstate->modifier & KM_SHIFT) { if ((keymodifier & KM_SHIFT) == 0) { kdata.key = GHOST_kKeyLeftShift; wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, &kdata); @@ -1147,11 +1144,11 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr #ifdef USE_WIN_ACTIVATE else { if (keymodifier & KM_SHIFT) { - win->eventstate->shift = KM_MOD_HELD; + win->eventstate->modifier |= KM_SHIFT; } } #endif - if (win->eventstate->ctrl) { + if (win->eventstate->modifier & KM_CTRL) { if ((keymodifier & KM_CTRL) == 0) { kdata.key = GHOST_kKeyLeftControl; wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, &kdata); @@ -1160,11 +1157,11 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr #ifdef USE_WIN_ACTIVATE else { if (keymodifier & KM_CTRL) { - win->eventstate->ctrl = KM_MOD_HELD; + win->eventstate->modifier |= KM_CTRL; } } #endif - if (win->eventstate->alt) { + if (win->eventstate->modifier & KM_ALT) { if ((keymodifier & KM_ALT) == 0) { kdata.key = GHOST_kKeyLeftAlt; wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, &kdata); @@ -1173,11 +1170,11 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr #ifdef USE_WIN_ACTIVATE else { if (keymodifier & KM_ALT) { - win->eventstate->alt = KM_MOD_HELD; + win->eventstate->modifier |= KM_ALT; } } #endif - if (win->eventstate->oskey) { + if (win->eventstate->modifier & KM_OSKEY) { if ((keymodifier & KM_OSKEY) == 0) { kdata.key = GHOST_kKeyOS; wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, &kdata); @@ -1186,7 +1183,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr #ifdef USE_WIN_ACTIVATE else { if (keymodifier & KM_OSKEY) { - win->eventstate->oskey = KM_MOD_HELD; + win->eventstate->modifier |= KM_OSKEY; } } #endif diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index 0ff181db9b1..c5764ad7a5e 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -408,15 +408,6 @@ enum { ((ISKEYBOARD(event_type) || ISMOUSE(event_type) || ISNDOF(event_type)) && \ (ISKEYMODIFIER(event_type) == false)) -/* Internal helpers. */ -#define _VA_IS_EVENT_MOD2(v, a) (CHECK_TYPE_INLINE(v, wmEvent *), ((v)->a)) -#define _VA_IS_EVENT_MOD3(v, a, b) (_VA_IS_EVENT_MOD2(v, a) || ((v)->b)) -#define _VA_IS_EVENT_MOD4(v, a, b, c) (_VA_IS_EVENT_MOD3(v, a, b) || ((v)->c)) -#define _VA_IS_EVENT_MOD5(v, a, b, c, d) (_VA_IS_EVENT_MOD4(v, a, b, c) || ((v)->d)) - -/** Reusable `IS_EVENT_MOD(event, shift, ctrl, alt, oskey)` macro. */ -#define IS_EVENT_MOD(...) VA_NARGS_CALL_OVERLOAD(_VA_IS_EVENT_MOD, __VA_ARGS__) - enum eEventType_Mask { /** #ISKEYMODIFIER */ EVT_TYPE_MASK_KEYBOARD_MODIFIER = (1 << 0), |