diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-11-13 23:01:32 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-11-13 23:02:40 +0300 |
commit | 520f71b43a4b24fb7c59d5798657cb7afb552ecf (patch) | |
tree | 2c974e2fb8a50d68604a13bdbc3ad9e9c0ea9cb6 | |
parent | f9145bded3d0049190a0a6af7ad661a1403e6ce2 (diff) |
Fix tool keymaps not working properly after recent changes.
Not sure this is the best fix, but this should be working. Regardless it seems
good to tag active tool keymaps as such.
4 files changed, 20 insertions, 7 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py index 8a84f2d7d3c..14090c0f11d 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_common.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py @@ -315,7 +315,7 @@ class ToolSelectPanelHelper: km_idname = f"{cls.keymap_prefix:s} {context_descr:s}, {text:s}" km = kc.keymaps.get(km_idname) if km is None: - km = kc.keymaps.new(km_idname, space_type=cls.bl_space_type, region_type='WINDOW') + km = kc.keymaps.new(km_idname, space_type=cls.bl_space_type, region_type='WINDOW', tool=True) keymap_fn[0](km) keymap_fn[0] = km @@ -770,7 +770,7 @@ def keymap_from_context(context, space_type): keyconf = wm.keyconfigs.active keymap = keyconf.keymaps.get(km_name) if keymap is None: - keymap = keyconf.keymaps.new(km_name, space_type='EMPTY', region_type='TEMPORARY') + keymap = keyconf.keymaps.new(km_name, space_type='EMPTY', region_type='TEMPORARY', tool=True) for kmi in keymap.keymap_items: keymap.keymap_items.remove(kmi) diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h index e13847f2473..e51933f5a22 100644 --- a/source/blender/makesdna/DNA_windowmanager_types.h +++ b/source/blender/makesdna/DNA_windowmanager_types.h @@ -345,6 +345,7 @@ enum { KEYMAP_DIFF = (1 << 4), /* diff keymap for user preferences */ KEYMAP_USER_MODIFIED = (1 << 5), /* keymap has user modifications */ KEYMAP_UPDATE = (1 << 6), + KEYMAP_TOOL = (1 << 7), /* keymap for active tool system */ }; typedef struct wmKeyConfig { diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index f8a9b00c724..84bb339b4c5 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -283,14 +283,22 @@ static void rna_KeyMap_item_remove(wmKeyMap *km, ReportList *reports, PointerRNA RNA_POINTER_INVALIDATE(kmi_ptr); } -static wmKeyMap *rna_keymap_new(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid, bool modal) +static wmKeyMap *rna_keymap_new(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid, bool modal, bool tool) { + wmKeyMap *keymap; + if (modal == 0) { - return WM_keymap_ensure(keyconf, idname, spaceid, regionid); + keymap = WM_keymap_ensure(keyconf, idname, spaceid, regionid); } else { - return WM_modalkeymap_add(keyconf, idname, NULL); /* items will be lazy init */ + keymap = WM_modalkeymap_add(keyconf, idname, NULL); /* items will be lazy init */ + } + + if (keymap && tool) { + keymap->flag |= KEYMAP_TOOL; } + + return keymap; } static wmKeyMap *rna_keymap_find(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid) @@ -871,7 +879,8 @@ void RNA_api_keymaps(StructRNA *srna) RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); RNA_def_enum(func, "space_type", rna_enum_space_type_items, SPACE_EMPTY, "Space Type", ""); RNA_def_enum(func, "region_type", rna_enum_region_type_items, RGN_TYPE_WINDOW, "Region Type", ""); - RNA_def_boolean(func, "modal", 0, "Modal", ""); + RNA_def_boolean(func, "modal", 0, "Modal", "Keymap for modal operators"); + RNA_def_boolean(func, "tool", 0, "Tool", "Keymap for active tools"); parm = RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Added key map"); RNA_def_function_return(func, parm); diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index 4032f47eec2..2685a1bfafd 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -267,7 +267,10 @@ wmKeyConfig *WM_keyconfig_new(wmWindowManager *wm, const char *idname, bool user /* For default configuration, we need to keep keymap * modal items and poll functions intact. */ for (wmKeyMap *km = keyconf->keymaps.first; km; km = km->next) { - WM_keymap_clear(km); + /* Tool system keymaps are not part of preset, so don't clear. */ + if (!(km->flag & KEYMAP_TOOL)) { + WM_keymap_clear(km); + } } } else { |