[Bf-blender-cvs] [a90bfa17a9f] xr-actions-D9124: XR: Include action set name in XR event data

Peter Kim noreply at git.blender.org
Thu Oct 29 15:52:14 CET 2020


Commit: a90bfa17a9f4d355d371fbe208370ed6efc960fd
Author: Peter Kim
Date:   Thu Oct 29 21:01:49 2020 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rBa90bfa17a9f4d355d371fbe208370ed6efc960fd

XR: Include action set name in XR event data

Needed to match keymap items with XR events.

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

M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_event_query.c
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_keymap.c
M	source/blender/windowmanager/wm_event_system.h
M	source/blender/windowmanager/xr/intern/wm_xr_session.c

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

diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 66f0278a30b..0b104d1290f 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -689,11 +689,34 @@ static bool rna_Event_is_xr_get(PointerRNA *ptr)
   return WM_event_is_xr(event);
 }
 
+static void rna_Event_xr_action_set_get(PointerRNA *ptr, char *value)
+{
+  const wmEvent *event = ptr->data;
+  if (WM_event_is_xr(event)) {
+    WM_event_xr_data(event, &value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+  }
+  else {
+    value[0] = '\0';
+  }
+}
+
+static int rna_Event_xr_action_set_length(PointerRNA *ptr)
+{
+  const wmEvent *event = ptr->data;
+  if (WM_event_is_xr(event)) {
+    wmXrActionData *data = event->customdata;
+    return strlen(data->action_set) + 1;
+  }
+  else {
+    return 0;
+  }
+}
+
 static void rna_Event_xr_action_get(PointerRNA *ptr, char *value)
 {
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
-    WM_event_xr_data(event, &value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+    WM_event_xr_data(event, NULL, &value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
   }
   else {
     value[0] = '\0';
@@ -705,7 +728,7 @@ static int rna_Event_xr_action_length(PointerRNA *ptr)
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
     wmXrActionData *data = event->customdata;
-    return strlen(data->name) + 1;
+    return strlen(data->action) + 1;
   }
   else {
     return 0;
@@ -717,7 +740,8 @@ static int rna_Event_xr_type_get(PointerRNA *ptr)
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
     int type;
-    WM_event_xr_data(event, NULL, (char *)&type, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+    WM_event_xr_data(
+        event, NULL, NULL, (char *)&type, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
     return type;
   }
   else {
@@ -729,7 +753,7 @@ static void rna_Event_xr_state_get(PointerRNA *ptr, float *value)
 {
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
-    WM_event_xr_data(event, NULL, NULL, value, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+    WM_event_xr_data(event, NULL, NULL, NULL, value, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
   }
   else {
     memset(value, 0, sizeof(float[2]));
@@ -740,7 +764,7 @@ static void rna_Event_xr_controller_location_get(PointerRNA *ptr, float *value)
 {
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
-    WM_event_xr_data(event, NULL, NULL, NULL, value, NULL, NULL, NULL, NULL, NULL, NULL);
+    WM_event_xr_data(event, NULL, NULL, NULL, NULL, value, NULL, NULL, NULL, NULL, NULL, NULL);
   }
   else {
     memset(value, 0, sizeof(float[3]));
@@ -751,7 +775,7 @@ static void rna_Event_xr_controller_rotation_get(PointerRNA *ptr, float *value)
 {
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
-    WM_event_xr_data(event, NULL, NULL, NULL, NULL, value, NULL, NULL, NULL, NULL, NULL);
+    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, value, NULL, NULL, NULL, NULL, NULL);
   }
   else {
     value[0] = 1.0f;
@@ -764,7 +788,7 @@ static int rna_Event_xr_viewport_width_get(PointerRNA *ptr)
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
     int width;
-    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, &width, NULL, NULL, NULL, NULL);
+    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, NULL, &width, NULL, NULL, NULL, NULL);
     return width;
   }
   else {
@@ -777,7 +801,7 @@ static int rna_Event_xr_viewport_height_get(PointerRNA *ptr)
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
     int height;
-    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, NULL, &height, NULL, NULL, NULL);
+    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &height, NULL, NULL, NULL);
     return height;
   }
   else {
@@ -790,7 +814,8 @@ static float rna_Event_xr_focal_length_get(PointerRNA *ptr)
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
     float focal_len;
-    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &focal_len, NULL, NULL);
+    WM_event_xr_data(
+        event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &focal_len, NULL, NULL);
     return focal_len;
   }
   else {
@@ -803,7 +828,7 @@ static void rna_Event_xr_view_matrix_get(PointerRNA *ptr, float values[16])
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
     WM_event_xr_data(
-        event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, (float(*)[4])values, NULL);
+        event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, (float(*)[4])values, NULL);
   }
   else {
     memset(values, 0, sizeof(float[16]));
@@ -815,7 +840,7 @@ static void rna_Event_xr_projection_matrix_get(PointerRNA *ptr, float values[16]
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
     WM_event_xr_data(
-        event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, (float(*)[4])values);
+        event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, (float(*)[4])values);
   }
   else {
     memset(values, 0, sizeof(float[16]));
@@ -2431,6 +2456,12 @@ static void rna_def_event(BlenderRNA *brna)
   RNA_def_property_boolean_funcs(prop, "rna_Event_is_xr_get", NULL);
   RNA_def_property_ui_text(prop, "Is XR", "The event has XR data");
 
+  prop = RNA_def_property(srna, "xr_action_set", PROP_STRING, PROP_NONE);
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_string_funcs(
+      prop, "rna_Event_xr_action_set_get", "rna_Event_xr_action_set_length", NULL);
+  RNA_def_property_ui_text(prop, "XR Action Set", "XR action set name");
+
   prop = RNA_def_property(srna, "xr_action", PROP_STRING, PROP_NONE);
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
   RNA_def_property_string_funcs(
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index eba9259783a..9b7be1ed72e 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -870,7 +870,8 @@ float WM_event_tablet_data(const struct wmEvent *event, int *pen_flip, float til
 bool WM_event_is_tablet(const struct wmEvent *event);
 
 void WM_event_xr_data(const struct wmEvent *event,
-                      char **name,
+                      char **action_set,
+                      char **action,
                       char *type,
                       float state[2],
                       float controller_loc[3],
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index cd66e8f263c..1a940c9b364 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -648,8 +648,10 @@ typedef enum wmXrOpFlag {
 } wmXrOpFlag;
 
 typedef struct wmXrActionData {
-  /** Name. */
-  char name[64];
+  /** Action set name. */
+  char action_set[64];
+  /** Action name. */
+  char action[64];
   /** Type (GHOST_XrActionType). */
   char type;
   /** State. Set appropriately based on type. */
diff --git a/source/blender/windowmanager/intern/wm_event_query.c b/source/blender/windowmanager/intern/wm_event_query.c
index 7ca42115a87..ba50a639352 100644
--- a/source/blender/windowmanager/intern/wm_event_query.c
+++ b/source/blender/windowmanager/intern/wm_event_query.c
@@ -427,7 +427,8 @@ bool WM_event_is_tablet(const struct wmEvent *event)
  * \{ */
 
 void WM_event_xr_data(const wmEvent *event,
-                      char **name,
+                      char **action_set,
+                      char **action,
                       char *type,
                       float state[2],
                       float controller_loc[3],
@@ -440,8 +441,11 @@ void WM_event_xr_data(const wmEvent *event,
 {
   const wmXrActionData *data = event->customdata;
 
-  if (name) {
-    strcpy(*name, data->name);
+  if (action_set) {
+    strcpy(*action_set, data->action_set);
+  }
+  if (action) {
+    strcpy(*action, data->action);
   }
   if (type) {
     *type = data->type;
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index be4edc3de7c..9e816b78be2 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -1893,6 +1893,14 @@ static bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi)
     }
   }
 
+  if (ISXR(kmitype)) {
+    wmXrActionData *customdata = winevent->customdata;
+    if (!STREQ(kmi->xr_action_set, customdata->action_set) ||
+        !STREQ(kmi->xr_action, customdata->action)) {
+      return false;
+    }
+  }
+
   return true;
 }
 
@@ -4862,7 +4870,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
 }
 
 #ifdef WITH_XR_OPENXR
-void wm_event_add_xrevent(const wmXrAction *action,
+void wm_event_add_xrevent(const char *action_set_name,
+                          const wmXrAction *action,
                           const GHOST_XrPose *controller_pose,
                           const wmXrEyeData *eye_data,
                           wmSurface *surface,
@@ -4871,9 +4880,8 @@ void wm_event_add_xrevent(const wmXrAction *action,
                           short val,
                           bool press_start)
 {
-  if (!surface->is_xr || !surface->customdata || (val != KM_PRESS && val != KM_RELEASE)) {
-    return;
-  }
+  BLI_assert(surface->is_xr && surface->customdata);
+  BLI_assert(val == KM_PRESS || val == KM_RELEASE);
 
   wmXrSurfaceData *surface_data = surface->customdata;
   const bool add_win_event = (action->ot->modal &&
@@ -4886,7 +4894,8 @@ void wm_event_add_xrevent(const wmXrAction *action,
   event->is_repeat = false;
 
   wmXrActionData *data = MEM_callocN(sizeof(wmXrActionData), __func__);
-  strcpy(data->name, action->name);
+  strcpy(data->action_set, action_set_name);
+  strcpy(data->action, action->name);
   data->type = action->type;
 
   switch (action->type) {
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index d92e2c5c952..3f4170521cb 100644
--- a/source/bl

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list