Merge branch 'master' into blender2.8
[blender.git] / source / blender / windowmanager / intern / wm_keymap.c
index be147606c462aea765877396958c5e1766b842fa..85bfe8d281356f21195e08fbe01422813e6a4fb2 100644 (file)
@@ -38,6 +38,7 @@
 #include "DNA_space_types.h"
 #include "DNA_userdef_types.h"
 #include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
 
 #include "MEM_guardedalloc.h"
 #include "CLG_log.h"
@@ -51,6 +52,7 @@
 #include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_screen.h"
+#include "BKE_workspace.h"
 
 #include "BLT_translation.h"
 
@@ -164,7 +166,8 @@ static void wm_keyconfig_properties_update_ot(ListBase *km_lb)
 static bool wm_keymap_item_equals_result(wmKeyMapItem *a, wmKeyMapItem *b)
 {
        return (STREQ(a->idname, b->idname) &&
-               RNA_struct_equals(a->ptr, b->ptr, RNA_EQ_UNSET_MATCH_NONE) &&
+               /* We do not really care about which Main we pass here, tbh. */
+               RNA_struct_equals(G_MAIN, a->ptr, b->ptr, RNA_EQ_UNSET_MATCH_NONE) &&
                (a->flag & KMI_INACTIVE) == (b->flag & KMI_INACTIVE) &&
                a->propvalue == b->propvalue);
 }
@@ -343,6 +346,12 @@ static wmKeyMap *wm_keymap_new(const char *idname, int spaceid, int regionid)
        km->spaceid = spaceid;
        km->regionid = regionid;
 
+       {
+               const char *owner_id = RNA_struct_state_owner_get();
+               if (owner_id) {
+                       BLI_strncpy(km->owner_id, owner_id, sizeof(km->owner_id));
+               }
+       }
        return km;
 }
 
@@ -403,6 +412,14 @@ bool WM_keymap_remove(wmKeyConfig *keyconf, wmKeyMap *keymap)
 
 bool WM_keymap_poll(bContext *C, wmKeyMap *keymap)
 {
+       /* If we're tagged, only use compatible. */
+       if (keymap->owner_id[0] != '\0') {
+               const WorkSpace *workspace = CTX_wm_workspace(C);
+               if (BKE_workspace_owner_id_check(workspace, keymap->owner_id) == false) {
+                       return false;
+               }
+       }
+
        if (keymap->poll != NULL) {
                return keymap->poll(C);
        }
@@ -953,11 +970,7 @@ int WM_keymap_item_raw_to_string(
            alt == KM_ANY &&
            oskey == KM_ANY)
        {
-               /* make it implicit in case of compact result expected. */
-               if (!compact) {
-                       ADD_SEP;
-                       p += BLI_strcpy_rlen(p, IFACE_("Any"));
-               }
+               /* Don't show anything for any mapping. */
        }
        else {
                if (shift) {