Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-11-27 09:33:52 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-11-27 09:52:15 +0300
commit1f8360171cd80c0c1918486703926709cb5db7aa (patch)
tree25ce56039ec95d156c4eaddc4134d639f3b900c3 /source
parenta58f0eea4f1e9b04e519e123eb656009cf718f9e (diff)
Keymap: share annotation tool keymaps between spaces
Not sharing caused duplication in the keymap and required a factory class generator. Simplify tool & keymap definitions by sharing them. It's highly unlikely we will ever want these to use different keys once they're set as the active tool.
Diffstat (limited to 'source')
-rw-r--r--source/blender/windowmanager/WM_keymap.h2
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c3
-rw-r--r--source/blender/windowmanager/intern/wm_keymap.c19
3 files changed, 23 insertions, 1 deletions
diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h
index 0e8a468192c..7f7612cea35 100644
--- a/source/blender/windowmanager/WM_keymap.h
+++ b/source/blender/windowmanager/WM_keymap.h
@@ -74,8 +74,10 @@ bool WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *
int WM_keymap_item_to_string(wmKeyMapItem *kmi, const bool compact, char *result, const int result_len);
wmKeyMap *WM_keymap_list_find(ListBase *lb, const char *idname, int spaceid, int regionid);
+wmKeyMap *WM_keymap_list_find_spaceid_or_empty(ListBase *lb, const char *idname, int spaceid, int regionid);
wmKeyMap *WM_keymap_ensure(struct wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid);
wmKeyMap *WM_keymap_find_all(const struct bContext *C, const char *idname, int spaceid, int regionid);
+wmKeyMap *WM_keymap_find_all_spaceid_or_empty(const struct bContext *C, const char *idname, int spaceid, int regionid);
wmKeyMap *WM_keymap_active(struct wmWindowManager *wm, struct wmKeyMap *keymap);
bool WM_keymap_remove(struct wmKeyConfig *keyconfig, struct wmKeyMap *keymap);
bool WM_keymap_poll(struct bContext *C, struct wmKeyMap *keymap);
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index f760b95a1f2..23c149b46b5 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -2860,8 +2860,9 @@ static void wm_event_temp_tool_handler_apply(
if (ar->regiontype == RGN_TYPE_WINDOW) {
bToolRef_Runtime *tref_rt = sa->runtime.tool ? sa->runtime.tool->runtime : NULL;
if (tref_rt && tref_rt->keymap[0]) {
- wmKeyMap *km = WM_keymap_find_all(
+ wmKeyMap *km = WM_keymap_find_all_spaceid_or_empty(
C, tref_rt->keymap, sa->spacetype, RGN_TYPE_WINDOW);
+ /* We shouldn't use keymaps from unrelated spaces. */
if (km != NULL) {
// printf("Keymap: '%s' -> '%s'\n", tref_rt->keymap, sa->runtime.tool->idname);
sneaky_handler->keymap = km;
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index 27c816a4d7d..4c00b99e13e 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -806,6 +806,18 @@ wmKeyMap *WM_keymap_list_find(ListBase *lb, const char *idname, int spaceid, int
return NULL;
}
+wmKeyMap *WM_keymap_list_find_spaceid_or_empty(ListBase *lb, const char *idname, int spaceid, int regionid)
+{
+ wmKeyMap *km;
+
+ for (km = lb->first; km; km = km->next)
+ if (ELEM(km->spaceid, spaceid, SPACE_EMPTY) && km->regionid == regionid)
+ if (STREQLEN(idname, km->idname, KMAP_MAX_NAME))
+ return km;
+
+ return NULL;
+}
+
wmKeyMap *WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
{
wmKeyMap *km = WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid);
@@ -827,6 +839,13 @@ wmKeyMap *WM_keymap_find_all(const bContext *C, const char *idname, int spaceid,
return WM_keymap_list_find(&wm->userconf->keymaps, idname, spaceid, regionid);
}
+wmKeyMap *WM_keymap_find_all_spaceid_or_empty(const bContext *C, const char *idname, int spaceid, int regionid)
+{
+ wmWindowManager *wm = CTX_wm_manager(C);
+
+ return WM_keymap_list_find_spaceid_or_empty(&wm->userconf->keymaps, idname, spaceid, regionid);
+}
+
/* ****************** modal keymaps ************ */
/* modal maps get linked to a running operator, and filter the keys before sending to modal() callback */