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.
This commit is contained in:
Brecht Van Lommel 2018-11-13 21:01:32 +01:00
parent f9145bded3
commit 520f71b43a
4 changed files with 20 additions and 7 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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);

View File

@ -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 {