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
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/windowmanager/intern')
-rw-r--r--source/blender/windowmanager/intern/wm.c122
-rw-r--r--source/blender/windowmanager/intern/wm_event_query.c69
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c120
-rw-r--r--source/blender/windowmanager/intern/wm_files.c12
-rw-r--r--source/blender/windowmanager/intern/wm_gesture_ops.c138
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c88
-rw-r--r--source/blender/windowmanager/intern/wm_window.c2
7 files changed, 463 insertions, 88 deletions
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index 0b7d5e5f1f4..27fe0d1c7b5 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -106,6 +106,32 @@ static void window_manager_foreach_id(ID *id, LibraryForeachIDData *data)
static void write_wm_xr_data(BlendWriter *writer, wmXrData *xr_data)
{
BKE_screen_view3d_shading_blend_write(writer, &xr_data->session_settings.shading);
+
+ LISTBASE_FOREACH (XrActionConfig *, ac, &xr_data->session_settings.actionconfigs) {
+ BLO_write_struct(writer, XrActionConfig, ac);
+
+ /* Only write actionmaps for user configs. */
+ if ((ac->flag & XR_ACTIONCONF_USER) != 0) {
+ LISTBASE_FOREACH (XrActionMap *, am, &ac->actionmaps) {
+ BLO_write_struct(writer, XrActionMap, am);
+
+ LISTBASE_FOREACH (XrActionMapItem *, ami, &am->items) {
+ BLO_write_struct(writer, XrActionMapItem, ami);
+ if (ami->op[0] && ami->op_properties) {
+ IDP_BlendWrite(writer, ami->op_properties);
+ }
+
+ LISTBASE_FOREACH (XrActionMapBinding *, amb, &ami->bindings) {
+ BLO_write_struct(writer, XrActionMapBinding, amb);
+ }
+ }
+ }
+ }
+ }
+
+ LISTBASE_FOREACH (XrMotionCaptureObject *, mocap_ob, &xr_data->session_settings.mocap_objects) {
+ BLO_write_struct(writer, XrMotionCaptureObject, mocap_ob);
+ }
}
static void window_manager_blend_write(BlendWriter *writer, ID *id, const void *id_address)
@@ -134,6 +160,39 @@ static void window_manager_blend_write(BlendWriter *writer, ID *id, const void *
static void direct_link_wm_xr_data(BlendDataReader *reader, wmXrData *xr_data)
{
BKE_screen_view3d_shading_blend_read_data(reader, &xr_data->session_settings.shading);
+
+ BLO_read_list(reader, &xr_data->session_settings.actionconfigs);
+
+ LISTBASE_FOREACH (XrActionConfig *, ac, &xr_data->session_settings.actionconfigs) {
+ BLO_read_list(reader, &ac->actionmaps);
+
+ LISTBASE_FOREACH (XrActionMap *, am, &ac->actionmaps) {
+ BLO_read_list(reader, &am->items);
+
+ LISTBASE_FOREACH (XrActionMapItem *, ami, &am->items) {
+ if (ami->op[0] && ami->op_properties) {
+ BLO_read_data_address(reader, &ami->op_properties);
+ IDP_BlendDataRead(reader, &ami->op_properties);
+
+ ami->op_properties_ptr = MEM_callocN(sizeof(PointerRNA), "wmOpItemPtr");
+ WM_operator_properties_create(ami->op_properties_ptr, ami->op);
+ ami->op_properties_ptr->data = ami->op_properties;
+ }
+ else {
+ ami->op_properties = NULL;
+ ami->op_properties_ptr = NULL;
+ }
+
+ BLO_read_list(reader, &ami->bindings);
+ }
+ }
+ }
+
+ BLO_read_data_address(reader, &xr_data->session_settings.defaultconf);
+ BLO_read_data_address(reader, &xr_data->session_settings.addonconf);
+ BLO_read_data_address(reader, &xr_data->session_settings.userconf);
+
+ BLO_read_list(reader, &xr_data->session_settings.mocap_objects);
}
static void window_manager_blend_read_data(BlendDataReader *reader, ID *id)
@@ -227,6 +286,10 @@ static void window_manager_blend_read_data(BlendDataReader *reader, ID *id)
static void lib_link_wm_xr_data(BlendLibReader *reader, ID *parent_id, wmXrData *xr_data)
{
BLO_read_id_address(reader, parent_id->lib, &xr_data->session_settings.base_pose_object);
+
+ LISTBASE_FOREACH (XrMotionCaptureObject *, mocap_ob, &xr_data->session_settings.mocap_objects) {
+ BLO_read_id_address(reader, parent_id->lib, &mocap_ob->ob);
+ }
}
static void lib_link_workspace_instance_hook(BlendLibReader *reader,
@@ -433,6 +496,55 @@ void WM_operator_handlers_clear(wmWindowManager *wm, wmOperatorType *ot)
}
}
+void WM_xr_actionmap_item_bindings_clear(XrActionMapItem *ami)
+{
+ BLI_freelistN(&ami->bindings);
+
+ ami->selbinding = 0;
+}
+
+void WM_xr_actionmap_item_properties_free(XrActionMapItem *ami)
+{
+ if (ami->op_properties_ptr) {
+ WM_operator_properties_free(ami->op_properties_ptr);
+ MEM_freeN(ami->op_properties_ptr);
+ ami->op_properties_ptr = NULL;
+ ami->op_properties = NULL;
+ }
+ else {
+ BLI_assert(ami->op_properties == NULL);
+ }
+}
+
+void WM_xr_actionmap_clear(XrActionMap *actionmap)
+{
+ LISTBASE_FOREACH (XrActionMapItem *, ami, &actionmap->items) {
+ WM_xr_actionmap_item_bindings_clear(ami);
+ WM_xr_actionmap_item_properties_free(ami);
+ }
+
+ BLI_freelistN(&actionmap->items);
+
+ actionmap->selitem = 0;
+}
+
+void WM_xr_actionconfig_clear(XrActionConfig *actionconf)
+{
+ LISTBASE_FOREACH (XrActionMap *, am, &actionconf->actionmaps) {
+ WM_xr_actionmap_clear(am);
+ }
+
+ BLI_freelistN(&actionconf->actionmaps);
+
+ actionconf->selactionmap = actionconf->actactionmap = 0;
+}
+
+void WM_xr_actionconfig_free(XrActionConfig *actionconf)
+{
+ WM_xr_actionconfig_clear(actionconf);
+ MEM_freeN(actionconf);
+}
+
/* ****************************************** */
void WM_keyconfig_reload(bContext *C)
@@ -507,6 +619,9 @@ void WM_check(bContext *C)
/* Case: fileread. */
if ((wm->initialized & WM_WINDOW_IS_INIT) == 0) {
WM_keyconfig_init(C);
+#ifdef WITH_XR_OPENXR
+ WM_xr_actionconfig_init(C);
+#endif
WM_autosave_init(wm);
}
@@ -595,6 +710,13 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm)
WM_keyconfig_free(keyconf);
}
+ XrActionConfig *actionconf;
+ while ((actionconf = BLI_pophead(&wm->xr.session_settings.actionconfigs))) {
+ WM_xr_actionconfig_free(actionconf);
+ }
+
+ BLI_freelistN(&wm->xr.session_settings.mocap_objects);
+
BLI_freelistN(&wm->notifier_queue);
if (wm->message_bus != NULL) {
diff --git a/source/blender/windowmanager/intern/wm_event_query.c b/source/blender/windowmanager/intern/wm_event_query.c
index 7b5691b99a0..364aab9482a 100644
--- a/source/blender/windowmanager/intern/wm_event_query.c
+++ b/source/blender/windowmanager/intern/wm_event_query.c
@@ -486,6 +486,75 @@ int WM_event_absolute_delta_y(const struct wmEvent *event)
/** \} */
/* -------------------------------------------------------------------- */
+/** \name XR Input Access
+ * \{ */
+
+void WM_event_xr_data(const wmEvent *event,
+ char **action_set,
+ char **action,
+ char *type,
+ float state[2],
+ float state_other[2],
+ float *float_threshold,
+ float controller_loc[3],
+ float controller_rot[4],
+ float controller_loc_other[3],
+ float controller_rot_other[4],
+ float *eye_lens,
+ float eye_viewmat[4][4],
+ bool *bimanual)
+{
+ const wmXrActionData *data = event->customdata;
+
+ if (action_set) {
+ strcpy(*action_set, data->action_set);
+ }
+ if (action) {
+ strcpy(*action, data->action);
+ }
+ if (type) {
+ *type = data->type;
+ }
+ if (state) {
+ copy_v2_v2(state, data->state);
+ }
+ if (state_other) {
+ copy_v2_v2(state_other, data->state_other);
+ }
+ if (float_threshold) {
+ *float_threshold = data->float_threshold;
+ }
+ if (controller_loc) {
+ copy_v3_v3(controller_loc, data->controller_loc);
+ }
+ if (controller_rot) {
+ copy_v4_v4(controller_rot, data->controller_rot);
+ }
+ if (controller_loc_other) {
+ copy_v3_v3(controller_loc_other, data->controller_loc_other);
+ }
+ if (controller_rot_other) {
+ copy_v4_v4(controller_rot_other, data->controller_rot_other);
+ }
+ if (eye_lens) {
+ *eye_lens = data->eye_lens;
+ }
+ if (eye_viewmat) {
+ copy_m4_m4(eye_viewmat, data->eye_viewmat);
+ }
+ if (bimanual) {
+ *bimanual = data->bimanual;
+ }
+}
+
+bool WM_event_is_xr(const struct wmEvent *event)
+{
+ return (event->custom == EVT_DATA_XR);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Event IME Input Access
* \{ */
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 537d5264ba9..f025fd43b49 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -83,6 +83,7 @@
#include "wm.h"
#include "wm_event_system.h"
#include "wm_event_types.h"
+#include "wm_surface.h"
#include "wm_window.h"
#include "DEG_depsgraph.h"
@@ -1341,7 +1342,19 @@ static int wm_operator_invoke(bContext *C,
ot->idname);
}
- if (op->type->invoke && event) {
+ if (op->type->invoke_3d && event && (event->type == EVT_XR_ACTION)) {
+ if (op->type->flag & OPTYPE_UNDO) {
+ wm->op_undo_depth++;
+ }
+
+ retval = op->type->invoke_3d(C, op, event);
+ OPERATOR_RETVAL_CHECK(retval);
+
+ if (op->type->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm) {
+ wm->op_undo_depth--;
+ }
+ }
+ else if (op->type->invoke && event) {
wm_region_mouse_co(C, event);
if (op->type->flag & OPTYPE_UNDO) {
@@ -2227,7 +2240,7 @@ static int wm_handler_operator_call(bContext *C,
* nothing to do in this case.
*/
}
- else if (ot->modal) {
+ else if (ot->modal || ot->modal_3d) {
/* We set context to where modal handler came from. */
wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win = CTX_wm_window(C);
@@ -2245,7 +2258,15 @@ static int wm_handler_operator_call(bContext *C,
}
/* Warning, after this call all context data and 'event' may be freed. see check below. */
- retval = ot->modal(C, op, event);
+ if (ot->modal_3d && event->type == EVT_XR_ACTION) {
+ retval = ot->modal_3d(C, op, event);
+ }
+ else if (ot->modal) {
+ retval = ot->modal(C, op, event);
+ }
+ else {
+ /* Pass through. An "XR operator" (only modal_3d) received a non-XR event.*/
+ }
OPERATOR_RETVAL_CHECK(retval);
if (ot->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm) {
@@ -3434,6 +3455,71 @@ static void wm_event_free_and_remove_from_queue_if_valid(wmEvent *event)
* Handle events for all windows, run from the #WM_main event loop.
* \{ */
+#ifdef WITH_XR_OPENXR
+static void wm_event_handle_xrevent(
+ bContext *C, wmWindowManager *wm, wmWindow *win, bScreen *screen, wmEvent *event)
+{
+ int action = 0;
+
+ /* Find a valid region for XR operator execution and modal handling. */
+ ED_screen_areas_iter (win, screen, area) {
+ CTX_wm_area_set(C, area);
+ if (!CTX_wm_view3d(C)) {
+ continue;
+ }
+
+ LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
+ if (!WM_region_use_viewport(area, region)) {
+ continue;
+ }
+ CTX_wm_region_set(C, region);
+
+ action |= wm_handlers_do(C, event, &win->modalhandlers);
+
+ if ((action & WM_HANDLER_BREAK) == 0) {
+ wmXrActionData *actiondata = event->customdata;
+ if ((actiondata->ot->modal || actiondata->ot->modal_3d) && event->val == KM_RELEASE) {
+ /* Don't execute modal operators on release. */
+ }
+ else {
+ PointerRNA properties = {.type = actiondata->ot->srna,
+ .data = actiondata->op_properties};
+ if (actiondata->ot->invoke || actiondata->ot->invoke_3d) {
+ /* Invoke operator, either executing operator or transferring responsibility to window
+ * modal handlers. */
+ wm_operator_invoke(C,
+ actiondata->ot,
+ event,
+ actiondata->op_properties ? &properties : NULL,
+ NULL,
+ false,
+ false);
+ }
+ else {
+ /* Execute operator. */
+ wmOperator *op = wm_operator_create(
+ wm, actiondata->ot, actiondata->op_properties ? &properties : NULL, NULL);
+ if ((WM_operator_call(C, op) & OPERATOR_HANDLED) == 0) {
+ WM_operator_free(op);
+ }
+ }
+ }
+ action |= WM_HANDLER_BREAK;
+ }
+
+ CTX_wm_region_set(C, NULL);
+ break;
+ }
+
+ if (action & WM_HANDLER_BREAK) {
+ break;
+ }
+ }
+
+ CTX_wm_area_set(C, NULL);
+}
+#endif /* WITH_XR_OPENXR */
+
/* Called in main loop. */
/* Goes over entire hierarchy: events -> window -> screen -> area -> region. */
void wm_event_do_handlers(bContext *C)
@@ -3531,6 +3617,16 @@ void wm_event_do_handlers(bContext *C)
CTX_wm_window_set(C, win);
+#ifdef WITH_XR_OPENXR
+ if (event->type == EVT_XR_ACTION) {
+ wm_event_handle_xrevent(C, wm, win, screen, event);
+ BLI_remlink(&win->event_queue, event);
+ wm_event_free(event);
+ /* Skip mouse event handling below, which is unnecessary for XR events. */
+ continue;
+ }
+#endif
+
/* Clear tool-tip on mouse move. */
if (screen->tool_tip && screen->tool_tip->exit_on_event) {
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
@@ -5083,6 +5179,24 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
#endif
}
+#ifdef WITH_XR_OPENXR
+void wm_event_add_xrevent(wmWindow *win, wmXrActionData *actiondata, short val)
+{
+ BLI_assert(val == KM_PRESS || val == KM_RELEASE);
+
+ wmEvent event = {
+ .type = EVT_XR_ACTION,
+ .val = val,
+ .is_repeat = false,
+ .custom = EVT_DATA_XR,
+ .customdata = actiondata,
+ .customdatafree = 1,
+ };
+
+ wm_event_add(win, &event);
+}
+#endif /* WITH_XR_OPENXR */
+
/** \} */
/* -------------------------------------------------------------------- */
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index a5ebf988edd..24a3b58fc26 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -204,6 +204,18 @@ static void wm_window_match_init(bContext *C, ListBase *wmlist)
WM_event_remove_handlers(C, &win->modalhandlers);
ED_screen_exit(C, win, WM_window_get_active_screen(win));
}
+
+ /* Free XR actionconfigs and motion capture objects. */
+ XrSessionSettings *xrsettings = &wm->xr.session_settings;
+ XrActionConfig *actionconf;
+ while ((actionconf = BLI_pophead(&xrsettings->actionconfigs))) {
+ WM_xr_actionconfig_free(actionconf);
+ }
+ xrsettings->defaultconf = NULL;
+ xrsettings->addonconf = NULL;
+ xrsettings->userconf = NULL;
+
+ BLI_freelistN(&xrsettings->mocap_objects);
}
/* reset active window */
diff --git a/source/blender/windowmanager/intern/wm_gesture_ops.c b/source/blender/windowmanager/intern/wm_gesture_ops.c
index 578699dda60..b087bd9d668 100644
--- a/source/blender/windowmanager/intern/wm_gesture_ops.c
+++ b/source/blender/windowmanager/intern/wm_gesture_ops.c
@@ -36,6 +36,8 @@
#include "BKE_context.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -45,6 +47,9 @@
#include "ED_screen.h"
#include "ED_select_utils.h"
+#include "ED_view3d.h"
+
+#include "../editors/space_view3d/view3d_intern.h"
#include "UI_interface.h"
@@ -202,6 +207,60 @@ int WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_RUNNING_MODAL;
}
+int WM_gesture_box_invoke_3d(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ BLI_assert(event->type == EVT_XR_ACTION);
+ BLI_assert(event->custom == EVT_DATA_XR);
+ BLI_assert(event->customdata);
+
+ const wmXrActionData *actiondata = event->customdata;
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+ Scene *scene = CTX_data_scene(C);
+ View3D *v3d = CTX_wm_view3d(C);
+ ARegion *region = CTX_wm_region(C);
+ RegionView3D *rv3d = region->regiondata;
+ wmWindowManager *wm = CTX_wm_manager(C);
+ wmXrData *xr = &wm->xr;
+ float lens_prev;
+ float clip_start_prev, clip_end_prev;
+ int mval[2];
+ int retval;
+
+ wmEvent event_mut;
+ memcpy(&event_mut, event, sizeof(wmEvent));
+
+ /* Replace window view parameters with XR surface counterparts. */
+ ED_view3d_view_params_get(v3d, rv3d, &lens_prev, &clip_start_prev, &clip_end_prev, NULL);
+ ED_view3d_view_params_set(depsgraph,
+ scene,
+ v3d,
+ region,
+ actiondata->eye_lens,
+ xr->session_settings.clip_start,
+ xr->session_settings.clip_end,
+ NULL);
+
+ map_to_pixel(mval,
+ actiondata->controller_loc,
+ actiondata->eye_viewmat,
+ rv3d->winmat,
+ region->winx,
+ region->winy);
+
+ event_mut.x = region->winrct.xmin + mval[0];
+ event_mut.y = region->winrct.ymin + mval[1];
+
+ RNA_boolean_set(op->ptr, "wait_for_input", false);
+
+ retval = WM_gesture_box_invoke(C, op, &event_mut);
+
+ /* Restore window view. */
+ ED_view3d_view_params_set(
+ depsgraph, scene, v3d, region, lens_prev, clip_start_prev, clip_end_prev, NULL);
+
+ return retval;
+}
+
int WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
@@ -280,6 +339,85 @@ int WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_RUNNING_MODAL;
}
+int WM_gesture_box_modal_3d(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ BLI_assert(event->type == EVT_XR_ACTION);
+ BLI_assert(event->custom == EVT_DATA_XR);
+ BLI_assert(event->customdata);
+
+ const bool release = (event->val == KM_RELEASE);
+
+ const wmXrActionData *actiondata = event->customdata;
+ Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+ Scene *scene = CTX_data_scene(C);
+ View3D *v3d = CTX_wm_view3d(C);
+ ARegion *region = CTX_wm_region(C);
+ RegionView3D *rv3d = region->regiondata;
+ wmWindowManager *wm = CTX_wm_manager(C);
+ wmXrData *xr = &wm->xr;
+ float lens_prev;
+ float clip_start_prev, clip_end_prev;
+ float viewmat_prev[4][4];
+ int mval[2];
+ int retval;
+
+ wmEvent event_mut;
+ memcpy(&event_mut, event, sizeof(wmEvent));
+
+ /* Since this function is called in a window context, we need to replace the
+ * window view parameters with the XR surface counterparts to get a correct
+ * result for some operators (e.g. GPU select). */
+ ED_view3d_view_params_get(
+ v3d, rv3d, &lens_prev, &clip_start_prev, &clip_end_prev, release ? viewmat_prev : NULL);
+ ED_view3d_view_params_set(depsgraph,
+ scene,
+ v3d,
+ region,
+ actiondata->eye_lens,
+ xr->session_settings.clip_start,
+ xr->session_settings.clip_end,
+ release ? actiondata->eye_viewmat : NULL);
+
+ map_to_pixel(mval,
+ actiondata->controller_loc,
+ actiondata->eye_viewmat,
+ rv3d->winmat,
+ region->winx,
+ region->winy);
+
+ if (event->val == KM_PRESS) {
+ event_mut.type = MOUSEMOVE;
+ {
+ wmGesture *gesture = op->customdata;
+ gesture->is_active = true;
+ }
+ event_mut.x = region->winrct.xmin + mval[0];
+ event_mut.y = region->winrct.ymin + mval[1];
+ }
+ else if (event->val == KM_RELEASE) {
+ event_mut.type = EVT_MODAL_MAP;
+ event_mut.val = GESTURE_MODAL_SELECT;
+ }
+ else {
+ /* XR events currently only support press and release. */
+ BLI_assert(false);
+ }
+
+ retval = WM_gesture_box_modal(C, op, &event_mut);
+
+ /* Restore window view. */
+ ED_view3d_view_params_set(depsgraph,
+ scene,
+ v3d,
+ region,
+ lens_prev,
+ clip_start_prev,
+ clip_end_prev,
+ release ? viewmat_prev : NULL);
+
+ return retval;
+}
+
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
{
gesture_modal_end(C, op);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 81dcc5ccea0..79368fa9eef 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -3760,87 +3760,6 @@ static void WM_OT_stereo3d_set(wmOperatorType *ot)
/** \} */
-#ifdef WITH_XR_OPENXR
-
-static void wm_xr_session_update_screen(Main *bmain, const wmXrData *xr_data)
-{
- const bool session_exists = WM_xr_session_exists(xr_data);
-
- for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
- LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
- LISTBASE_FOREACH (SpaceLink *, slink, &area->spacedata) {
- if (slink->spacetype == SPACE_VIEW3D) {
- View3D *v3d = (View3D *)slink;
-
- if (v3d->flag & V3D_XR_SESSION_MIRROR) {
- ED_view3d_xr_mirror_update(area, v3d, session_exists);
- }
-
- if (session_exists) {
- wmWindowManager *wm = bmain->wm.first;
- const Scene *scene = WM_windows_scene_get_from_screen(wm, screen);
-
- ED_view3d_xr_shading_update(wm, v3d, scene);
- }
- /* Ensure no 3D View is tagged as session root. */
- else {
- v3d->runtime.flag &= ~V3D_RUNTIME_XR_SESSION_ROOT;
- }
- }
- }
- }
- }
-
- WM_main_add_notifier(NC_WM | ND_XR_DATA_CHANGED, NULL);
-}
-
-static void wm_xr_session_update_screen_on_exit_cb(const wmXrData *xr_data)
-{
- /* Just use G_MAIN here, storing main isn't reliable enough on file read or exit. */
- wm_xr_session_update_screen(G_MAIN, xr_data);
-}
-
-static int wm_xr_session_toggle_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Main *bmain = CTX_data_main(C);
- wmWindowManager *wm = CTX_wm_manager(C);
- wmWindow *win = CTX_wm_window(C);
- View3D *v3d = CTX_wm_view3d(C);
-
- /* Lazy-create xr context - tries to dynlink to the runtime, reading active_runtime.json. */
- if (wm_xr_init(wm) == false) {
- return OPERATOR_CANCELLED;
- }
-
- v3d->runtime.flag |= V3D_RUNTIME_XR_SESSION_ROOT;
- wm_xr_session_toggle(wm, win, wm_xr_session_update_screen_on_exit_cb);
- wm_xr_session_update_screen(bmain, &wm->xr);
-
- WM_event_add_notifier(C, NC_WM | ND_XR_DATA_CHANGED, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-static void WM_OT_xr_session_toggle(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Toggle VR Session";
- ot->idname = "WM_OT_xr_session_toggle";
- ot->description =
- "Open a view for use with virtual reality headsets, or close it if already "
- "opened";
-
- /* callbacks */
- ot->exec = wm_xr_session_toggle_exec;
- ot->poll = ED_operator_view3d_active;
-
- /* XXX INTERNAL just to hide it from the search menu by default, an Add-on will expose it in the
- * UI instead. Not meant as a permanent solution. */
- ot->flag = OPTYPE_INTERNAL;
-}
-
-#endif /* WITH_XR_OPENXR */
-
/* -------------------------------------------------------------------- */
/** \name Operator Registration & Keymaps
* \{ */
@@ -3882,9 +3801,6 @@ void wm_operatortypes_register(void)
WM_operatortype_append(WM_OT_call_panel);
WM_operatortype_append(WM_OT_radial_control);
WM_operatortype_append(WM_OT_stereo3d_set);
-#ifdef WITH_XR_OPENXR
- WM_operatortype_append(WM_OT_xr_session_toggle);
-#endif
#if defined(WIN32)
WM_operatortype_append(WM_OT_console_toggle);
#endif
@@ -3895,6 +3811,10 @@ void wm_operatortypes_register(void)
/* gizmos */
WM_operatortype_append(GIZMOGROUP_OT_gizmo_select);
WM_operatortype_append(GIZMOGROUP_OT_gizmo_tweak);
+
+#ifdef WITH_XR_OPENXR
+ wm_xr_operatortypes_register();
+#endif
}
/* circleselect-like modal operators */
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index 8baf4a0e013..55b0d267cec 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -1561,7 +1561,7 @@ void wm_window_process_events(const bContext *C)
#ifdef WITH_XR_OPENXR
/* XR events don't use the regular window queues. So here we don't only trigger
* processing/dispatching but also handling. */
- has_event |= wm_xr_events_handle(CTX_wm_manager(C));
+ has_event |= wm_xr_events_handle(C);
#endif
/* When there is no event, sleep 5 milliseconds not to use too much CPU when idle.