Preference: option to use OS-Key to emulate MMB
authorCampbell Barton <ideasman42@gmail.com>
Wed, 2 Oct 2019 14:20:58 +0000 (00:20 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 2 Oct 2019 14:25:06 +0000 (00:25 +1000)
Alt-LMB is used in quite a few areas now, see T69323
using OS-Key allows these conflicts to be avoided.

Currently disabled for WIN32, since it conflicts with the start menu.

release/scripts/presets/keyconfig/blender.py
release/scripts/presets/keyconfig/blender_27x.py
release/scripts/startup/bl_ui/space_userpref.py
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/intern/rna_userdef.c
source/blender/windowmanager/intern/wm_event_system.c

index 8a7689d6d60d8cc3ba7ada4ea5dcb07406760ecd..596b17d734f3e27c2edc5cf379e13f930031047b 100644 (file)
@@ -169,7 +169,10 @@ def load():
     keyconfig_data = blender_default.generate_keymaps(
         blender_default.Params(
             select_mouse=kc_prefs.select_mouse,
-            use_mouse_emulate_3_button=prefs.inputs.use_mouse_emulate_3_button,
+            use_mouse_emulate_3_button=(
+                prefs.inputs.use_mouse_emulate_3_button and
+                prefs.inputs.mouse_emulate_3_button_modifier == 'ALT'
+            ),
             spacebar_action=kc_prefs.spacebar_action,
             v3d_tilde_action=kc_prefs.v3d_tilde_action,
             use_select_all_toggle=kc_prefs.use_select_all_toggle,
index 4ce77f46213dbfeea877eb072d96da1371aff4de..8d50d449494409a5f97ffb94f0579afb71811823 100644 (file)
@@ -53,7 +53,10 @@ def load():
     keyconfig_data = blender_default.generate_keymaps(
         blender_default.Params(
             select_mouse=kc_prefs.select_mouse,
-            use_mouse_emulate_3_button=prefs.inputs.use_mouse_emulate_3_button,
+            use_mouse_emulate_3_button=(
+                prefs.inputs.use_mouse_emulate_3_button and
+                prefs.inputs.mouse_emulate_3_button_modifier == 'ALT'
+            ),
             spacebar_action='SEARCH',
             use_select_all_toggle=True,
             use_gizmo_drag=False,
index be41fb5211806401d4595fdb31bb394aba316457..8ccd8b573570408df0a90438991d2c54b309602f 100644 (file)
@@ -1479,12 +1479,17 @@ class USERPREF_PT_input_mouse(PreferencePanel, Panel):
         return (prefs.active_section == 'INPUT')
 
     def draw_props(self, context, layout):
+        import sys
         prefs = context.preferences
         inputs = prefs.inputs
 
         flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=False)
 
         flow.prop(inputs, "use_mouse_emulate_3_button")
+        if sys.platform[:3] != "win":
+            rowsub = flow.row()
+            rowsub.active = inputs.use_mouse_emulate_3_button
+            rowsub.prop(inputs, "mouse_emulate_3_button_modifier")
         flow.prop(inputs, "use_mouse_continuous")
         flow.prop(inputs, "use_drag_immediately")
         flow.prop(inputs, "mouse_double_click_time", text="Double Click Speed")
index 126b4638ca1081c1df92edf605192e8cdb20b519..f36802d33b357fca11a24bbd011573012279815e 100644 (file)
@@ -606,7 +606,8 @@ typedef struct UserDef {
   /** #eUserPref_PrefFlag preferences for the preferences. */
   char pref_flag;
   char savetime;
-  char _pad4[4];
+  char mouse_emulate_3_button_modifier;
+  char _pad4[3];
   /** FILE_MAXDIR length. */
   char tempdir[768];
   char fontdir[768];
@@ -1240,6 +1241,11 @@ typedef enum eUserpref_TempSpaceDisplayType {
   USER_TEMP_SPACE_DISPLAY_WINDOW,
 } eUserpref_TempSpaceDisplayType;
 
+typedef enum eUserpref_EmulateMMBMod {
+  USER_EMU_MMB_MOD_ALT = 0,
+  USER_EMU_MMB_MOD_OSKEY = 1,
+} eUserpref_EmulateMMBMod;
+
 #ifdef __cplusplus
 }
 #endif
index c9b6f46ab04cf57e718e88a95119169a97529d15..078af30e36cd6d36cd12196de35160c50c03059e 100644 (file)
@@ -424,6 +424,17 @@ static void rna_userdef_timecode_style_set(PointerRNA *ptr, int value)
   }
 }
 
+static int rna_UserDef_mouse_emulate_3_button_modifier_get(PointerRNA *ptr)
+{
+#  if !defined(WIN32)
+  UserDef *userdef = ptr->data;
+  return userdef->mouse_emulate_3_button_modifier;
+#  else
+  UNUSED_VARS(ptr);
+  return USER_EMU_MMB_MOD_ALT;
+#  endif
+}
+
 static PointerRNA rna_UserDef_view_get(PointerRNA *ptr)
 {
   return rna_pointer_inherit_refine(ptr, &RNA_PreferencesView, ptr->data);
@@ -5487,6 +5498,21 @@ static void rna_def_userdef_input(BlenderRNA *brna)
   RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
   RNA_def_property_update(prop, 0, "rna_userdef_keyconfig_reload_update");
 
+  static const EnumPropertyItem mouse_emulate_3_button_modifier[] = {
+      {USER_EMU_MMB_MOD_ALT, "ALT", 0, "Alt", ""},
+      {USER_EMU_MMB_MOD_OSKEY, "OSKEY", 0, "OS-Key", ""},
+      {0, NULL, 0, NULL, NULL},
+  };
+
+  prop = RNA_def_property(srna, "mouse_emulate_3_button_modifier", PROP_ENUM, PROP_NONE);
+  /* Only needed because of WIN32 inability to support the option. */
+  RNA_def_property_enum_funcs(prop, "rna_UserDef_mouse_emulate_3_button_modifier_get", NULL, NULL);
+  RNA_def_property_enum_items(prop, mouse_emulate_3_button_modifier);
+  RNA_def_property_ui_text(
+      prop, "Emulate 3 Button Modifier", "Hold this modifier to emulate the middle mouse button");
+  RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+  RNA_def_property_update(prop, 0, "rna_userdef_keyconfig_reload_update");
+
   prop = RNA_def_property(srna, "use_emulate_numpad", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "flag", USER_NONUMPAD);
   RNA_def_property_ui_text(
index 6b4327d5f44c56f15d06543c01c7a3980f5fbfba..6991dd2f9a6383d72968b713fef5a15a6d5e1987 100644 (file)
@@ -4210,19 +4210,31 @@ static void wm_eventemulation(wmEvent *event, bool test_only)
   if (U.flag & USER_TWOBUTTONMOUSE) {
 
     if (event->type == LEFTMOUSE) {
-      if (event->val == KM_PRESS && event->alt) {
-        event->type = MIDDLEMOUSE;
-        event->alt = 0;
+      short *mod = (
+#if !defined(WIN32)
+          (U.mouse_emulate_3_button_modifier == USER_EMU_MMB_MOD_OSKEY) ? &event->oskey :
+                                                                          &event->alt
+#else
+          /* Disable for WIN32 for now because it accesses the start menu. */
+          &event->alt
+#endif
+      );
 
-        if (!test_only) {
-          emulating_event = MIDDLEMOUSE;
+      if (event->val == KM_PRESS) {
+        if (*mod) {
+          *mod = 0;
+          event->type = MIDDLEMOUSE;
+
+          if (!test_only) {
+            emulating_event = MIDDLEMOUSE;
+          }
         }
       }
       else if (event->val == KM_RELEASE) {
         /* only send middle-mouse release if emulated */
         if (emulating_event == MIDDLEMOUSE) {
           event->type = MIDDLEMOUSE;
-          event->alt = 0;
+          *mod = 0;
         }
 
         if (!test_only) {