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.
This commit is contained in:
Campbell Barton 2020-03-26 19:02:15 +11:00
parent 03b2fc1a61
commit e8dd96516c
Notes: blender-bot 2023-02-14 03:59:44 +01:00
Referenced by issue #60766, Modal keymap customization from an addon is not restored properly
3 changed files with 25 additions and 2 deletions

View File

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

View File

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

View File

@ -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 */