Keymap: automate using OSKey for Ctrl on macos
Replace hard coded use of oskey with a function. Add checks to avoid conflicting bindings with the OS.
This commit is contained in:
parent
6e33729462
commit
630e94791f
55
release/scripts/modules/bl_keymap_utils/platform_helpers.py
Normal file
55
release/scripts/modules/bl_keymap_utils/platform_helpers.py
Normal file
@ -0,0 +1,55 @@
|
||||
# ##### BEGIN GPL LICENSE BLOCK #####
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
|
||||
def keyconfig_data_oskey_from_ctrl(keyconfig_data_src, filter_fn=None):
|
||||
keyconfig_data_dst = []
|
||||
for km_name, km_parms, km_items_data_src in keyconfig_data_src:
|
||||
km_items_data_dst = km_items_data_src.copy()
|
||||
items_dst = []
|
||||
km_items_data_dst["items"] = items_dst
|
||||
for item_src in km_items_data_src["items"]:
|
||||
item_op, item_event, item_prop = item_src
|
||||
if "ctrl" in item_event:
|
||||
if filter_fn is None or filter_fn(item_event):
|
||||
item_event = item_event.copy()
|
||||
item_event["oskey"] = item_event["ctrl"]
|
||||
del item_event["ctrl"]
|
||||
items_dst.append((item_op, item_event, item_prop))
|
||||
items_dst.append(item_src)
|
||||
keyconfig_data_dst.append((km_name, km_parms, km_items_data_dst))
|
||||
return keyconfig_data_dst
|
||||
|
||||
|
||||
def keyconfig_data_oskey_from_ctrl_for_macos(keyconfig_data_src):
|
||||
"""Use for apple since Cmd is typically used in-place of Ctrl."""
|
||||
def filter_fn(item_event):
|
||||
if (item_event["type"] in {
|
||||
'H',
|
||||
'M',
|
||||
'SPACE',
|
||||
'W',
|
||||
}) and (
|
||||
item_event.get("ctrl") and
|
||||
(not item_event.get("alt")) and
|
||||
(not item_event.get("shift"))
|
||||
):
|
||||
return False
|
||||
return True
|
||||
|
||||
return keyconfig_data_oskey_from_ctrl(keyconfig_data_src, filter_fn)
|
@ -120,6 +120,7 @@ blender_default = bpy.utils.execfile(os.path.join(dirname, "keymap_data", "blend
|
||||
|
||||
|
||||
def load():
|
||||
from sys import platform
|
||||
from bpy import context
|
||||
from bl_keymap_utils.io import keyconfig_init_from_data
|
||||
|
||||
@ -138,6 +139,11 @@ def load():
|
||||
use_pie_click_drag=kc_prefs.use_pie_click_drag,
|
||||
),
|
||||
)
|
||||
|
||||
if platform == 'darwin':
|
||||
from bl_keymap_utils.platform_helpers import keyconfig_data_oskey_from_ctrl_for_macos
|
||||
keyconfig_data = keyconfig_data_oskey_from_ctrl_for_macos(keyconfig_data)
|
||||
|
||||
keyconfig_init_from_data(kc, keyconfig_data)
|
||||
|
||||
|
||||
|
@ -42,6 +42,7 @@ class Prefs(bpy.types.KeyConfigPreferences):
|
||||
blender_default = bpy.utils.execfile(os.path.join(dirname, "keymap_data", "blender_default.py"))
|
||||
|
||||
def load():
|
||||
from sys import platform
|
||||
from bpy import context
|
||||
from bl_keymap_utils.io import keyconfig_init_from_data
|
||||
|
||||
@ -58,6 +59,12 @@ def load():
|
||||
legacy=True,
|
||||
),
|
||||
)
|
||||
|
||||
if platform == 'darwin':
|
||||
from bl_keymap_utils.platform_helpers import keyconfig_data_oskey_from_ctrl_for_macos
|
||||
keyconfig_data = keyconfig_data_oskey_from_ctrl_for_macos(keyconfig_data)
|
||||
|
||||
|
||||
keyconfig_init_from_data(kc, keyconfig_data)
|
||||
|
||||
|
||||
|
@ -46,25 +46,6 @@ def update_fn(_self, _context):
|
||||
load()
|
||||
|
||||
|
||||
def keyconfig_data_oskey_from_ctrl(keyconfig_data_src):
|
||||
# TODO, make into more generic event transforming function.
|
||||
keyconfig_data_dst = []
|
||||
for km_name, km_parms, km_items_data_src in keyconfig_data_src:
|
||||
km_items_data_dst = km_items_data_src.copy()
|
||||
items_dst = []
|
||||
km_items_data_dst["items"] = items_dst
|
||||
for item_src in km_items_data_src["items"]:
|
||||
item_op, item_event, item_prop = item_src
|
||||
if "ctrl" in item_event:
|
||||
item_event = item_event.copy()
|
||||
item_event["oskey"] = item_event["ctrl"]
|
||||
del item_event["ctrl"]
|
||||
items_dst.append((item_op, item_event, item_prop))
|
||||
items_dst.append(item_src)
|
||||
keyconfig_data_dst.append((km_name, km_parms, km_items_data_dst))
|
||||
return keyconfig_data_dst
|
||||
|
||||
|
||||
industry_compatible = bpy.utils.execfile(os.path.join(dirname, "keymap_data", "industry_compatible_data.py"))
|
||||
|
||||
|
||||
@ -79,7 +60,8 @@ def load():
|
||||
keyconfig_data = industry_compatible.generate_keymaps(params)
|
||||
|
||||
if platform == 'darwin':
|
||||
keyconfig_data = keyconfig_data_oskey_from_ctrl(keyconfig_data)
|
||||
from bl_keymap_utils.platform_helpers import keyconfig_data_oskey_from_ctrl_for_macos
|
||||
keyconfig_data = keyconfig_data_oskey_from_ctrl_for_macos(keyconfig_data)
|
||||
|
||||
keyconfig_init_from_data(kc, keyconfig_data)
|
||||
|
||||
|
@ -323,18 +323,6 @@ def km_window(params):
|
||||
{"items": items},
|
||||
)
|
||||
|
||||
if params.apple:
|
||||
# Apple standard shortcuts. Cmd+F for search since F-keys are not easy to use.
|
||||
items.extend([
|
||||
op_menu("TOPBAR_MT_file_new", {"type": 'N', "value": 'PRESS', "oskey": True}),
|
||||
op_menu("TOPBAR_MT_file_open_recent", {"type": 'O', "value": 'PRESS', "shift": True, "oskey": True}),
|
||||
("wm.open_mainfile", {"type": 'O', "value": 'PRESS', "oskey": True}, None),
|
||||
("wm.save_mainfile", {"type": 'S', "value": 'PRESS', "oskey": True}, None),
|
||||
("wm.save_as_mainfile", {"type": 'S', "value": 'PRESS', "shift": True, "oskey": True}, None),
|
||||
("wm.quit_blender", {"type": 'Q', "value": 'PRESS', "oskey": True}, None),
|
||||
("wm.search_menu", {"type": 'F', "value": 'PRESS', "oskey": True}, None),
|
||||
])
|
||||
|
||||
if params.legacy:
|
||||
# Old shorctus
|
||||
items.extend([
|
||||
@ -495,9 +483,6 @@ def km_screen(params):
|
||||
if params.apple:
|
||||
# Apple undo and user prefs
|
||||
items.extend([
|
||||
("ed.undo", {"type": 'Z', "value": 'PRESS', "oskey": True}, None),
|
||||
("ed.redo", {"type": 'Z', "value": 'PRESS', "shift": True, "oskey": True}, None),
|
||||
("ed.undo_history", {"type": 'Z', "value": 'PRESS', "alt": True, "oskey": True}, None),
|
||||
("screen.userpref_show", {"type": 'COMMA', "value": 'PRESS', "oskey": True}, None),
|
||||
])
|
||||
|
||||
@ -761,12 +746,6 @@ def km_outliner(params):
|
||||
("outliner.id_paste", {"type": 'V', "value": 'PRESS', "ctrl": True}, None),
|
||||
])
|
||||
|
||||
if params.apple:
|
||||
items.extend([
|
||||
("outliner.id_copy", {"type": 'C', "value": 'PRESS', "oskey": True}, None),
|
||||
("outliner.id_paste", {"type": 'V', "value": 'PRESS', "oskey": True}, None),
|
||||
])
|
||||
|
||||
return keymap
|
||||
|
||||
|
||||
@ -1102,12 +1081,6 @@ def km_view3d(params):
|
||||
("transform.skin_resize", {"type": 'A', "value": 'PRESS', "ctrl": True}, None),
|
||||
])
|
||||
|
||||
if params.apple:
|
||||
items.extend([
|
||||
("view3d.copybuffer", {"type": 'C', "value": 'PRESS', "oskey": True}, None),
|
||||
("view3d.pastebuffer", {"type": 'V', "value": 'PRESS', "oskey": True}, None),
|
||||
])
|
||||
|
||||
if not params.legacy:
|
||||
# New pie menus.
|
||||
items.extend([
|
||||
@ -1481,14 +1454,6 @@ def km_graph_editor(params):
|
||||
("graph.cursor_set", {"type": params.action_mouse, "value": 'PRESS'}, None),
|
||||
])
|
||||
|
||||
if params.apple:
|
||||
items.extend([
|
||||
("graph.copy", {"type": 'C', "value": 'PRESS', "oskey": True}, None),
|
||||
("graph.paste", {"type": 'V', "value": 'PRESS', "oskey": True}, None),
|
||||
("graph.paste", {"type": 'V', "value": 'PRESS', "shift": True, "oskey": True},
|
||||
{"properties": [("flipped", True)]}),
|
||||
])
|
||||
|
||||
return keymap
|
||||
|
||||
|
||||
@ -1733,12 +1698,6 @@ def km_node_editor(params):
|
||||
{"properties": [("data_path", 'tool_settings.snap_node_element')]}),
|
||||
])
|
||||
|
||||
if params.apple:
|
||||
items.extend([
|
||||
("node.clipboard_copy", {"type": 'C', "value": 'PRESS', "oskey": True}, None),
|
||||
("node.clipboard_paste", {"type": 'V', "value": 'PRESS', "oskey": True}, None),
|
||||
])
|
||||
|
||||
return keymap
|
||||
|
||||
|
||||
@ -1764,11 +1723,6 @@ def km_info(params):
|
||||
("info.report_copy", {"type": 'C', "value": 'PRESS', "ctrl": True}, None),
|
||||
])
|
||||
|
||||
if params.apple:
|
||||
items.extend([
|
||||
("info.report_copy", {"type": 'C', "value": 'PRESS', "oskey": True}, None),
|
||||
])
|
||||
|
||||
return keymap
|
||||
|
||||
|
||||
@ -2019,14 +1973,6 @@ def km_dopesheet(params):
|
||||
("anim.end_frame_set", {"type": 'END', "value": 'PRESS', "ctrl": True}, None),
|
||||
])
|
||||
|
||||
if params.apple:
|
||||
items.extend([
|
||||
("action.copy", {"type": 'C', "value": 'PRESS', "oskey": True}, None),
|
||||
("action.paste", {"type": 'V', "value": 'PRESS', "oskey": True}, None),
|
||||
("action.paste", {"type": 'V', "value": 'PRESS', "shift": True, "oskey": True},
|
||||
{"properties": [("flipped", True)]}),
|
||||
])
|
||||
|
||||
return keymap
|
||||
|
||||
|
||||
@ -2171,11 +2117,6 @@ def km_text_generic(params):
|
||||
("text.replace", {"type": 'H', "value": 'PRESS', "ctrl": True}, None),
|
||||
])
|
||||
|
||||
if params.apple:
|
||||
items.extend([
|
||||
("text.start_find", {"type": 'F', "value": 'PRESS', "oskey": True}, None),
|
||||
])
|
||||
|
||||
return keymap
|
||||
|
||||
|
||||
@ -2187,40 +2128,6 @@ def km_text(params):
|
||||
{"items": items},
|
||||
)
|
||||
|
||||
if params.apple:
|
||||
items.extend([
|
||||
("text.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "oskey": True},
|
||||
{"properties": [("type", 'LINE_BEGIN')]}),
|
||||
("text.move", {"type": 'RIGHT_ARROW', "value": 'PRESS', "oskey": True},
|
||||
{"properties": [("type", 'LINE_END')]}),
|
||||
("text.move", {"type": 'UP_ARROW', "value": 'PRESS', "oskey": True},
|
||||
{"properties": [("type", 'FILE_TOP')]}),
|
||||
("text.move", {"type": 'DOWN_ARROW', "value": 'PRESS', "oskey": True},
|
||||
{"properties": [("type", 'FILE_BOTTOM')]}),
|
||||
("text.move_select", {"type": 'LEFT_ARROW', "value": 'PRESS', "shift": True, "oskey": True},
|
||||
{"properties": [("type", 'LINE_BEGIN')]}),
|
||||
("text.move_select", {"type": 'RIGHT_ARROW', "value": 'PRESS', "shift": True, "oskey": True},
|
||||
{"properties": [("type", 'LINE_END')]}),
|
||||
("text.move_select", {"type": 'LEFT_ARROW', "value": 'PRESS', "shift": True, "alt": True},
|
||||
{"properties": [("type", 'PREVIOUS_WORD')]}),
|
||||
("text.move_select", {"type": 'RIGHT_ARROW', "value": 'PRESS', "shift": True, "alt": True},
|
||||
{"properties": [("type", 'NEXT_WORD')]}),
|
||||
("text.move_select", {"type": 'UP_ARROW', "value": 'PRESS', "shift": True, "oskey": True},
|
||||
{"properties": [("type", 'FILE_TOP')]}),
|
||||
("text.move_select", {"type": 'DOWN_ARROW', "value": 'PRESS', "shift": True, "oskey": True},
|
||||
{"properties": [("type", 'FILE_BOTTOM')]}),
|
||||
("text.delete", {"type": 'BACK_SPACE', "value": 'PRESS', "alt": True},
|
||||
{"properties": [("type", 'PREVIOUS_WORD')]}),
|
||||
("text.save", {"type": 'S', "value": 'PRESS', "alt": True, "oskey": True}, None),
|
||||
("text.save_as", {"type": 'S', "value": 'PRESS', "shift": True, "alt": True, "oskey": True}, None),
|
||||
("text.cut", {"type": 'X', "value": 'PRESS', "oskey": True}, None),
|
||||
("text.copy", {"type": 'C', "value": 'PRESS', "oskey": True}, None),
|
||||
("text.paste", {"type": 'V', "value": 'PRESS', "oskey": True}, None),
|
||||
("text.find_set_selected", {"type": 'E', "value": 'PRESS', "oskey": True}, None),
|
||||
("text.select_all", {"type": 'A', "value": 'PRESS', "oskey": True}, None),
|
||||
("text.select_line", {"type": 'A', "value": 'PRESS', "shift": True, "oskey": True}, None),
|
||||
])
|
||||
|
||||
items.extend([
|
||||
("text.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "alt": True},
|
||||
{"properties": [("type", 'PREVIOUS_WORD')]}),
|
||||
@ -2484,12 +2391,6 @@ def km_sequencer(params):
|
||||
("marker.rename", {"type": 'M', "value": 'PRESS', "ctrl": True}, None),
|
||||
])
|
||||
|
||||
if params.apple:
|
||||
items.extend([
|
||||
("sequencer.copy", {"type": 'C', "value": 'PRESS', "oskey": True}, None),
|
||||
("sequencer.paste", {"type": 'V', "value": 'PRESS', "oskey": True}, None),
|
||||
])
|
||||
|
||||
return keymap
|
||||
|
||||
|
||||
@ -2521,16 +2422,6 @@ def km_console(params):
|
||||
{"items": items},
|
||||
)
|
||||
|
||||
if params.apple:
|
||||
items.extend([
|
||||
("console.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "oskey": True},
|
||||
{"properties": [("type", 'LINE_BEGIN')]}),
|
||||
("console.move", {"type": 'RIGHT_ARROW', "value": 'PRESS', "oskey": True},
|
||||
{"properties": [("type", 'LINE_END')]}),
|
||||
("console.copy", {"type": 'C', "value": 'PRESS', "oskey": True}, None),
|
||||
("console.paste", {"type": 'V', "value": 'PRESS', "oskey": True}, None),
|
||||
])
|
||||
|
||||
items.extend([
|
||||
("console.move", {"type": 'LEFT_ARROW', "value": 'PRESS', "ctrl": True},
|
||||
{"properties": [("type", 'PREVIOUS_WORD')]}),
|
||||
@ -3145,13 +3036,6 @@ def km_grease_pencil_stroke_edit_mode(params):
|
||||
{"properties": [("mode", 2)]}),
|
||||
])
|
||||
|
||||
if params.apple:
|
||||
# Apple copy + paste
|
||||
items.extend([
|
||||
("gpencil.copy", {"type": 'C', "value": 'PRESS', "oskey": True}, None),
|
||||
("gpencil.paste", {"type": 'V', "value": 'PRESS', "oskey": True}, None),
|
||||
])
|
||||
|
||||
if params.legacy:
|
||||
items.extend([
|
||||
# Convert to geometry
|
||||
@ -3474,15 +3358,6 @@ def km_pose(params):
|
||||
),
|
||||
])
|
||||
|
||||
if params.apple:
|
||||
items.extend([
|
||||
("pose.copy", {"type": 'C', "value": 'PRESS', "oskey": True}, None),
|
||||
("pose.paste", {"type": 'V', "value": 'PRESS', "oskey": True},
|
||||
{"properties": [("flipped", False)]}),
|
||||
("pose.paste", {"type": 'V', "value": 'PRESS', "shift": True, "oskey": True},
|
||||
{"properties": [("flipped", True)]}),
|
||||
])
|
||||
|
||||
return keymap
|
||||
|
||||
|
||||
@ -4334,14 +4209,6 @@ def km_font(params):
|
||||
op_menu("VIEW3D_MT_edit_text_context_menu", params.context_menu_event),
|
||||
])
|
||||
|
||||
if params.apple:
|
||||
items.extend([
|
||||
("font.select_all", {"type": 'A', "value": 'PRESS', "oskey": True}, None),
|
||||
("font.text_copy", {"type": 'C', "value": 'PRESS', "oskey": True}, None),
|
||||
("font.text_cut", {"type": 'X', "value": 'PRESS', "oskey": True}, None),
|
||||
("font.text_paste", {"type": 'V', "value": 'PRESS', "oskey": True}, None),
|
||||
])
|
||||
|
||||
return keymap
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user