[Bf-blender-cvs] [e8dd96516c6] master: Keymap: disallow modal key-maps in add-ons keyconfig
Campbell Barton
noreply at git.blender.org
Thu Mar 26 09:13:46 CET 2020
Commit: e8dd96516c60c4c43c8eb217f2c2cc61761cd0a0
Author: Campbell Barton
Date: Thu Mar 26 19:02:15 2020 +1100
Branches: master
https://developer.blender.org/rBe8dd96516c60c4c43c8eb217f2c2cc61761cd0a0
Keymap: disallow modal key-maps in add-ons keyconfig
Disable functionality reported in T60766 & only partially worked.
This could be used if the key-map was added after Blender started
as a way to customize modal key-maps, however it didn't work with
the add-on enabled on startup.
Add-on key-maps are intended to extend existing key-maps
so they can call the add-on, not as a way to change modal key-maps
for Blender's built-in functionality.
Disable this since it's not needed as add-ons
can't yet define modal key-maps.
===================================================================
M source/blender/makesrna/intern/rna_wm_api.c
M source/blender/windowmanager/intern/wm_event_system.c
M source/blender/windowmanager/intern/wm_keymap.c
===================================================================
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index df6abecd365..f1e3a999935 100644
--- a/source/blender/makesrna/intern/rna_wm_api.c
+++ b/source/blender/makesrna/intern/rna_wm_api.c
@@ -392,9 +392,27 @@ static PointerRNA rna_KeyMap_item_match_event(ID *id, wmKeyMap *km, bContext *C,
return kmi_ptr;
}
-static wmKeyMap *rna_keymap_new(
- wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid, bool modal, bool tool)
+static wmKeyMap *rna_keymap_new(wmKeyConfig *keyconf,
+ ReportList *reports,
+ const char *idname,
+ int spaceid,
+ int regionid,
+ bool modal,
+ bool tool)
{
+ if (modal) {
+ /* Sanity check: Don't allow add-ons to override internal modal key-maps
+ * because this isn't supported, the restriction can be removed when
+ * add-ons can define modal key-maps.
+ * Currently this is only useful for add-ons to override built-in modal keymaps
+ * which is not the intended use for add-on keymaps. */
+ wmWindowManager *wm = G_MAIN->wm.first;
+ if (keyconf == wm->addonconf) {
+ BKE_reportf(reports, RPT_ERROR, "Modal key-maps not supported for add-on key-config");
+ return NULL;
+ }
+ }
+
wmKeyMap *keymap;
if (modal == 0) {
@@ -1180,6 +1198,7 @@ void RNA_api_keymaps(StructRNA *srna)
PropertyRNA *parm;
func = RNA_def_function(srna, "new", "rna_keymap_new"); /* add_keymap */
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
parm = RNA_def_string(func, "name", NULL, 0, "Name", "");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
RNA_def_enum(func, "space_type", rna_enum_space_type_items, SPACE_EMPTY, "Space Type", "");
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 6f133e063f7..b61759e6d97 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -1864,6 +1864,8 @@ static wmKeyMapItem *wm_eventmatch_modal_keymap_items(const wmKeyMap *keymap,
const wmEvent *event)
{
for (wmKeyMapItem *kmi = keymap->items.first; kmi; kmi = kmi->next) {
+ /* Should already be handled by #wm_user_modal_keymap_set_items. */
+ BLI_assert(kmi->propvalue_str[0] == '\0');
if (wm_eventmatch(event, kmi)) {
if ((keymap->poll_modal_item == NULL) || (keymap->poll_modal_item(op, kmi->propvalue))) {
return kmi;
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index c1a4595ec6b..ab4888d4d31 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -1900,6 +1900,8 @@ void WM_keyconfig_update(wmWindowManager *wm)
addonmap = WM_keymap_list_find(&wm->addonconf->keymaps, km->idname, km->spaceid, km->regionid);
usermap = WM_keymap_list_find(&U.user_keymaps, km->idname, km->spaceid, km->regionid);
+ /* For now only the default map defines modal key-maps,
+ * if we support modal keymaps for 'addonmap', these will need to be enabled too. */
wm_user_modal_keymap_set_items(wm, defaultmap);
/* add */
More information about the Bf-blender-cvs
mailing list