Merge branch 'master' into soc-2019-openxr
[blender.git] / source / blender / windowmanager / intern / wm_operators.c
index 367a5a810984f83a225f1ee5607c36cb163c4aac..aded1994c188bd8662225e628241c2d76fc60699 100644 (file)
@@ -75,6 +75,7 @@
 #include "BKE_report.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h" /* BKE_ST_MAXNAME */
+#include "BKE_workspace.h"
 #include "BKE_unit.h"
 
 #include "BKE_idcode.h"
@@ -3509,6 +3510,35 @@ static void WM_OT_stereo3d_set(wmOperatorType *ot)
   RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
+#ifdef WITH_OPENXR
+static int wm_xr_session_toggle_exec(bContext *C, wmOperator *UNUSED(op))
+{
+  wmWindowManager *wm = CTX_wm_manager(C);
+
+  /* Lazy-create xr context - tries to dynlink to the runtime, reading active_runtime.json. */
+  if (wm_xr_context_ensure(C, wm) == false) {
+    return OPERATOR_CANCELLED;
+  }
+
+  wm_xr_session_toggle(C, wm->xr_context);
+
+  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 =
+      "Attempt to open a view for use with virtual reality headsets, or close it if already "
+      "opened";
+
+  /* callbacks */
+  ot->exec = wm_xr_session_toggle_exec;
+}
+#endif /* WITH_OPENXR */
+
 void wm_operatortypes_register(void)
 {
   WM_operatortype_append(WM_OT_window_close);
@@ -3546,6 +3576,9 @@ 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_OPENXR
+  WM_operatortype_append(WM_OT_xr_session_toggle);
+#endif
 #if defined(WIN32)
   WM_operatortype_append(WM_OT_console_toggle);
 #endif