diff options
author | Campbell Barton <campbell@blender.org> | 2022-03-02 07:07:00 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-03-02 07:31:50 +0300 |
commit | 4986f718482b061082936f1f6aa13929741093a2 (patch) | |
tree | 21ea0b78e1182d35b44b4955ff308b8df1148b19 /release | |
parent | 426ff481a789017bd5810a2064ec06a298a6f2dc (diff) |
Event System: remove tweak events in favor of click-drag
Supporting two kinds of dragging is redundant, remove tweak events as
they only supported 3 mouse buttons and added complexity from using the
'value' to store directions.
Support only click-drag events (KM_CLICK_DRAG) which can be used with
any keyboard or mouse button.
Details:
- A "direction" member has been added to keymap items and events which
can be used when the event value is set to KM_CLICK_DRAG.
- Keymap items are version patched.
- Loading older key-maps are also updated.
- Currently the key-maps stored in ./release/scripts/presets/keyconfig/
still reference tweak events & need updating. For now they are updated
on load.
Note that in general this wont impact add-ons as modal operators don't
receive tweak events.
Reviewed By: brecht
Ref D14214
Diffstat (limited to 'release')
4 files changed, 51 insertions, 13 deletions
diff --git a/release/scripts/modules/bl_keymap_utils/io.py b/release/scripts/modules/bl_keymap_utils/io.py index f34002741c6..456a1fa5a83 100644 --- a/release/scripts/modules/bl_keymap_utils/io.py +++ b/release/scripts/modules/bl_keymap_utils/io.py @@ -52,6 +52,8 @@ def kmi_args_as_data(kmi): s.append(f"\"{attr:s}\": " + ("-1" if mod == -1 else "True")) if (mod := kmi.key_modifier) and (mod != 'NONE'): s.append(f"\"key_modifier\": '{mod:s}'") + if (direction := kmi.direction) and (direction != 'ANY'): + s.append(f"\"direction\": '{direction:s}'") if kmi.repeat: if ( @@ -247,6 +249,20 @@ def _init_properties_from_data(base_props, base_value): def keymap_init_from_data(km, km_items, is_modal=False): new_fn = getattr(km.keymap_items, "new_modal" if is_modal else "new") for (kmi_idname, kmi_args, kmi_data) in km_items: + + # TODO(@campbellbarton): Temporary workaround keep until our + # key-maps have been updated to remove tweak events. + if ty_new := { + 'EVT_TWEAK_L': 'LEFTMOUSE', + 'EVT_TWEAK_M': 'MIDDLEMOUSE', + 'EVT_TWEAK_R': 'RIGHTMOUSE', + }.get(kmi_args["type"]): + kmi_args["type"] = ty_new + if (value := kmi_args["value"]) != 'ANY': + kmi_args["direction"] = value + kmi_args["value"] = 'CLICK_DRAG' + # End workaround. + kmi = new_fn(kmi_idname, **kmi_args) if kmi_data is not None: if not kmi_data.get("active", True): diff --git a/release/scripts/modules/bl_keymap_utils/versioning.py b/release/scripts/modules/bl_keymap_utils/versioning.py index ee7cc5daceb..402c21f8ef1 100644 --- a/release/scripts/modules/bl_keymap_utils/versioning.py +++ b/release/scripts/modules/bl_keymap_utils/versioning.py @@ -30,4 +30,22 @@ def keyconfig_update(keyconfig_data, keyconfig_version): # Setting repeat true on other kinds of events is harmless. item_event["repeat"] = True + if keyconfig_version <= (3, 2, 5): + # Only copy once. + if not has_copy: + keyconfig_data = copy.deepcopy(keyconfig_data) + has_copy = True + + for _km_name, _km_parms, km_items_data in keyconfig_data: + for (_item_op, item_event, _item_prop) in km_items_data["items"]: + if ty_new := { + 'EVT_TWEAK_L': 'LEFTMOUSE', + 'EVT_TWEAK_M': 'MIDDLEMOUSE', + 'EVT_TWEAK_R': 'RIGHTMOUSE', + }.get(item_event.get("type")): + item_event["type"] = ty_new + if (value := item_event["value"]) != 'ANY': + item_event["direction"] = value + item_event["value"] = 'CLICK_DRAG' + return keyconfig_data diff --git a/release/scripts/modules/rna_keymap_ui.py b/release/scripts/modules/rna_keymap_ui.py index 2676c00c655..5da98cd783d 100644 --- a/release/scripts/modules/rna_keymap_ui.py +++ b/release/scripts/modules/rna_keymap_ui.py @@ -180,6 +180,10 @@ def draw_kmi(display_keymaps, kc, km, kmi, layout, level): subrow.prop(kmi, "type", text="") subrow.prop(kmi, "value", text="") + if map_type in {'KEYBOARD', 'MOUSE'} and kmi.value == 'CLICK_DRAG': + subrow = sub.row() + subrow.prop(kmi, "direction") + subrow = sub.row() subrow.scale_x = 0.75 subrow.prop(kmi, "any", toggle=True) diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py index 5fb0f052154..bf71b8aece8 100644 --- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -1426,28 +1426,28 @@ def km_view3d(params): ("view3d.view_axis", {"type": 'NUMPAD_7', "value": 'PRESS', "shift": True, "ctrl": True}, {"properties": [("type", 'BOTTOM'), ("align_active", True)]}), *(( - ("view3d.view_axis", {"type": 'EVT_TWEAK_M', "value": 'NORTH', "alt": True}, + ("view3d.view_axis", {"type": 'MIDDLEMOUSE', "value": 'CLICK_DRAG', "direction": 'NORTH', "alt": True}, {"properties": [("type", 'TOP'), ("relative", True)]}), - ("view3d.view_axis", {"type": 'EVT_TWEAK_M', "value": 'SOUTH', "alt": True}, + ("view3d.view_axis", {"type": 'MIDDLEMOUSE', "value": 'CLICK_DRAG', "direction": 'SOUTH', "alt": True}, {"properties": [("type", 'BOTTOM'), ("relative", True)]}), - ("view3d.view_axis", {"type": 'EVT_TWEAK_M', "value": 'EAST', "alt": True}, + ("view3d.view_axis", {"type": 'MIDDLEMOUSE', "value": 'CLICK_DRAG', "direction": 'EAST', "alt": True}, {"properties": [("type", 'RIGHT'), ("relative", True)]}), - ("view3d.view_axis", {"type": 'EVT_TWEAK_M', "value": 'WEST', "alt": True}, + ("view3d.view_axis", {"type": 'MIDDLEMOUSE', "value": 'CLICK_DRAG', "direction": 'WEST', "alt": True}, {"properties": [("type", 'LEFT'), ("relative", True)]}), ) if params.v3d_alt_mmb_drag_action == 'RELATIVE' else ( - ("view3d.view_axis", {"type": 'EVT_TWEAK_M', "value": 'NORTH', "alt": True}, + ("view3d.view_axis", {"type": 'MIDDLEMOUSE', "value": 'CLICK_DRAG', "direction": 'NORTH', "alt": True}, {"properties": [("type", 'TOP')]}), - ("view3d.view_axis", {"type": 'EVT_TWEAK_M', "value": 'SOUTH', "alt": True}, + ("view3d.view_axis", {"type": 'MIDDLEMOUSE', "value": 'CLICK_DRAG', "direction": 'SOUTH', "alt": True}, {"properties": [("type", 'BOTTOM')]}), - ("view3d.view_axis", {"type": 'EVT_TWEAK_M', "value": 'EAST', "alt": True}, + ("view3d.view_axis", {"type": 'MIDDLEMOUSE', "value": 'CLICK_DRAG', "direction": 'EAST', "alt": True}, {"properties": [("type", 'RIGHT')]}), - ("view3d.view_axis", {"type": 'EVT_TWEAK_M', "value": 'WEST', "alt": True}, + ("view3d.view_axis", {"type": 'MIDDLEMOUSE', "value": 'CLICK_DRAG', "direction": 'WEST', "alt": True}, {"properties": [("type", 'LEFT')]}), - # Match the pie menu. - ("view3d.view_axis", {"type": 'EVT_TWEAK_M', "value": 'NORTH_WEST', "alt": True}, + ("view3d.view_axis", {"type": 'MIDDLEMOUSE', "value": 'CLICK_DRAG', "direction": 'NORTH_WEST', "alt": True}, {"properties": [("type", 'FRONT')]}), - ("view3d.view_axis", {"type": 'EVT_TWEAK_M', "value": 'NORTH_EAST', "alt": True}, + ("view3d.view_axis", {"type": 'MIDDLEMOUSE', "value": 'CLICK_DRAG', "direction": 'NORTH_EAST', "alt": True}, {"properties": [("type", 'BACK')]}), + # Match the pie menu. )), ("view3d.view_center_pick", {"type": 'MIDDLEMOUSE', "value": 'CLICK', "alt": True}, None), ("view3d.ndof_orbit_zoom", {"type": 'NDOF_MOTION', "value": 'ANY'}, None), @@ -6600,10 +6600,10 @@ def km_3d_view_tool_shear(params): {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, {"items": [ ("transform.shear", - {"type": params.tool_tweak, "value": 'NORTH', **params.tool_modifier}, + {"type": params.tool_mouse, "value": 'CLICK_DRAG', "direction": 'NORTH', **params.tool_modifier}, {"properties": [("release_confirm", True), ("orient_axis_ortho", 'Y')]}), ("transform.shear", - {"type": params.tool_tweak, "value": 'SOUTH', **params.tool_modifier}, + {"type": params.tool_mouse, "value": 'CLICK_DRAG', "direction": 'SOUTH', **params.tool_modifier}, {"properties": [("release_confirm", True), ("orient_axis_ortho", 'Y')]}), # Use as fallback to catch diagonals too. |