From a40e718d8195f3e9daab52970c2063d57cffab08 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 12 Sep 2024 11:37:49 +0200 Subject: [PATCH] Set focused/unfocused when session state changes --- client/application.cpp | 9 +++++---- client/scene.cpp | 11 +++++++++++ client/scene.h | 7 +++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/client/application.cpp b/client/application.cpp index 7bce061b..23a3b96c 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -1076,26 +1076,27 @@ void application::loop() { poll_events(); + auto scene = current_scene(); if (!is_session_running()) { + if (scene) + scene->set_focused(false); // Throttle loop since xrWaitFrame won't be called. std::this_thread::sleep_for(250ms); } else { - auto scene = current_scene(); if (scene) { poll_actions(); if (auto tmp = last_scene.lock(); scene != tmp) { if (tmp) - tmp->on_unfocused(); - - scene->on_focused(); + tmp->set_focused(false); last_scene = scene; } + scene->set_focused(true); XrFrameState framestate = xr_session.wait_frame(); diff --git a/client/scene.cpp b/client/scene.cpp index 30a8c028..011d76d0 100644 --- a/client/scene.cpp +++ b/client/scene.cpp @@ -43,6 +43,17 @@ scene::scene(key, const meta & current_meta) : current_meta(current_meta) { } +void scene::set_focused(bool status) +{ + if (status != focused) + { + focused = status; + if (focused) + on_focused(); + else + on_unfocused(); + } +} void scene::on_unfocused() {} void scene::on_focused() {} diff --git a/client/scene.h b/client/scene.h index 3b3afcbc..738f9447 100644 --- a/client/scene.h +++ b/client/scene.h @@ -76,6 +76,7 @@ protected: xr::space & world_space; xr::space & view_space; XrViewConfigurationType viewconfig; + bool focused = false; vk::raii::Instance & vk_instance; vk::raii::Device & device; @@ -96,14 +97,16 @@ protected: return current_meta.spaces_by_name.at(name); } + virtual void on_unfocused(); + virtual void on_focused(); + public: scene(key, const meta &); virtual ~scene(); + void set_focused(bool status); virtual void render(const XrFrameState &) = 0; - virtual void on_unfocused(); - virtual void on_focused(); virtual void on_interaction_profile_changed(); virtual void on_reference_space_changed(XrReferenceSpaceType space, XrTime); virtual void on_session_state_changed(XrSessionState state);