diff options
-rw-r--r-- | source/blender/makesrna/intern/rna_wm_api.c | 23 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_keymap.c | 2 |
3 files changed, 25 insertions, 2 deletions
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 */ |