[Bf-blender-cvs] [62c5f71da1a] xr-actions-D9124: XR: Add XR identifiers to key config I/O

Peter Kim noreply at git.blender.org
Tue Oct 27 17:06:32 CET 2020


Commit: 62c5f71da1ae1f2db392173d95b682144fb74196
Author: Peter Kim
Date:   Wed Oct 28 01:04:01 2020 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rB62c5f71da1ae1f2db392173d95b682144fb74196

XR: Add XR identifiers to key config I/O

Allows XR action properties to be shared with others.

===================================================================

M	release/scripts/modules/bl_keymap_utils/io.py
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/release/scripts/modules/bl_keymap_utils/io.py b/release/scripts/modules/bl_keymap_utils/io.py
index e850661d6c6..6b9cd98d0a6 100644
--- a/release/scripts/modules/bl_keymap_utils/io.py
+++ b/release/scripts/modules/bl_keymap_utils/io.py
@@ -78,6 +78,12 @@ def kmi_args_as_data(kmi):
             if kmi.value in {'PRESS', 'ANY'}:
                 s.append("\"repeat\": True")
 
+    if kmi.map_type == 'XR':
+        if kmi.xr_action_set:
+            s.append(f"\"xr_action_set\": '{kmi.xr_action_set}'")
+        if kmi.xr_action:
+            s.append(f"\"xr_action\": '{kmi.xr_action}'")
+
     return "{" + ", ".join(s) + "}"
 
 
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index 5bb7e42823f..354269c0ba5 100644
--- a/source/blender/makesrna/intern/rna_wm_api.c
+++ b/source/blender/makesrna/intern/rna_wm_api.c
@@ -221,9 +221,9 @@ static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km,
                                          bool alt,
                                          bool oskey,
                                          int keymodifier,
+                                         bool repeat,
                                          const char *xr_action_set,
                                          const char *xr_action,
-                                         bool repeat,
                                          bool head)
 {
   /*  wmWindowManager *wm = CTX_wm_manager(C); */
@@ -259,15 +259,15 @@ static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km,
   /* create keymap item */
   kmi = WM_keymap_add_item(km, idname_bl, type, value, modifier, keymodifier);
 
+  if (!repeat) {
+    kmi->flag |= KMI_REPEAT_IGNORE;
+  }
+
   if (xr_action_set) {
-    strcpy(kmi->xr_action_set, xr_action_set);
+    BLI_strncpy(kmi->xr_action_set, xr_action_set, sizeof(kmi->xr_action_set));
   }
   if (xr_action) {
-    strcpy(kmi->xr_action, xr_action);
-  }
-
-  if (!repeat) {
-    kmi->flag |= KMI_REPEAT_IGNORE;
+    BLI_strncpy(kmi->xr_action, xr_action, sizeof(kmi->xr_action));
   }
 
   /* T32437 allow scripts to define hotkeys that get added to start of keymap
@@ -1144,9 +1144,9 @@ void RNA_api_keymapitems(StructRNA *srna)
   RNA_def_boolean(func, "alt", 0, "Alt", "");
   RNA_def_boolean(func, "oskey", 0, "OS Key", "");
   RNA_def_enum(func, "key_modifier", rna_enum_event_type_items, 0, "Key Modifier", "");
+  RNA_def_boolean(func, "repeat", false, "Repeat", "When set, accept key-repeat events");
   RNA_def_string(func, "xr_action_set", NULL, 0, "XR Action Set", "");
   RNA_def_string(func, "xr_action", NULL, 0, "XR Action", "");
-  RNA_def_boolean(func, "repeat", false, "Repeat", "When set, accept key-repeat events");
   RNA_def_boolean(func,
                   "head",
                   0,
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 438ad2d55de..be4edc3de7c 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -4883,6 +4883,7 @@ void wm_event_add_xrevent(const wmXrAction *action,
   wmEvent *event = add_win_event ? &_event : MEM_callocN(sizeof(wmEvent), __func__);
   event->type = EVT_XR_ACTION;
   event->val = val;
+  event->is_repeat = false;
 
   wmXrActionData *data = MEM_callocN(sizeof(wmXrActionData), __func__);
   strcpy(data->name, action->name);
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index 92dd1813787..d92e2c5c952 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -176,9 +176,10 @@ static bool wm_keymap_item_equals(wmKeyMapItem *a, wmKeyMapItem *b)
   return (wm_keymap_item_equals_result(a, b) && a->type == b->type && a->val == b->val &&
           a->shift == b->shift && a->ctrl == b->ctrl && a->alt == b->alt && a->oskey == b->oskey &&
           a->keymodifier == b->keymodifier && a->maptype == b->maptype &&
-          STREQ(a->xr_action_set, b->xr_action_set) && STREQ(a->xr_action, b->xr_action) &&
           ((ISKEYBOARD(a->type) == 0) ||
-           (a->flag & KMI_REPEAT_IGNORE) == (b->flag & KMI_REPEAT_IGNORE)));
+           (a->flag & KMI_REPEAT_IGNORE) == (b->flag & KMI_REPEAT_IGNORE)) &&
+          ((ISXR(a->type) == 0) ||
+           (STREQ(a->xr_action_set, b->xr_action_set) && STREQ(a->xr_action, b->xr_action))));
 }
 
 /* properties can be NULL, otherwise the arg passed is used and ownership is given to the kmi */
@@ -2015,6 +2016,9 @@ void WM_keymap_item_restore_to_default(wmWindowManager *wm, wmKeyMap *keymap, wm
     kmi->maptype = orig->maptype;
     kmi->flag = (kmi->flag & ~KMI_REPEAT_IGNORE) | (orig->flag & KMI_REPEAT_IGNORE);
 
+    BLI_strncpy(kmi->xr_action_set, orig->xr_action_set, sizeof(kmi->xr_action_set));
+    BLI_strncpy(kmi->xr_action, orig->xr_action, sizeof(kmi->xr_action));
+
     WM_keyconfig_update_tag(keymap, kmi);
   }



More information about the Bf-blender-cvs mailing list