diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index 56b30ecb..6b00bf24 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -791,12 +791,19 @@ void wivrn_session::operator()(from_headset::session_state_changed && event) break; } scoped_lock lock(mnd_ipc_server->global_state.lock); + auto locked = session_loss.lock(); for (auto & t: mnd_ipc_server->threads) { - if (t.ics.server_thread_index < 0 or t.ics.xc == nullptr) + auto id = t.ics.client_state.id; + if (t.ics.server_thread_index < 0 or t.ics.xc == nullptr or locked->contains(id)) continue; bool current = t.ics.client_state.session_overlay or mnd_ipc_server->global_state.active_client_index == t.ics.server_thread_index; + U_LOG_D("Setting session state for app %s: visible=%s focused=%s current=%s", + t.ics.client_state.info.application_name, + visible ? "true" : "false", + focused ? "true" : "false", + current ? "true" : "false"); xrt_syscomp_set_state(system_compositor, t.ics.xc, visible and current, focused and current, os_monotonic_get_ns()); } } @@ -927,10 +934,18 @@ void wivrn_session::operator()(const from_headset::stop_application & req) { if (t.ics.client_state.id == req.id) { - U_LOG_I("Notify session loss pending for %s", t.ics.client_state.info.application_name); + if (!t.ics.xs) + { + U_LOG_W("Unable to stop app %s: no session!", t.ics.client_state.info.application_name); + break; + } + + U_LOG_I("Request exit for application %s", t.ics.client_state.info.application_name); + if (xrt_session_request_exit(t.ics.xs) != XRT_SUCCESS) + U_LOG_W("Failed to request exit for application %s", t.ics.client_state.info.application_name); + auto when = os_monotonic_get_ns() + 10l * U_TIME_1S_IN_NS; - xrt_syscomp_notify_loss_pending(system_compositor, t.ics.xc, when); - session_loss.lock()->emplace(when, req.id); + session_loss.lock()->emplace(req.id, when); break; } } @@ -1138,11 +1153,11 @@ void wivrn_session::poll_session_loss() return; auto it = locked->begin(); scoped_lock lock(mnd_ipc_server->global_state.lock); - while (it != locked->end() and it->first <= now) + while (it != locked->end() and it->second <= now) { for (auto & t: mnd_ipc_server->threads) { - if (t.ics.client_state.id == it->second) + if (t.ics.client_state.id == it->first) { U_LOG_I("Terminating %s", t.ics.client_state.info.application_name); xrt_syscomp_notify_lost(system_compositor, t.ics.xc); diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index 663f3acd..a5574cb1 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -142,8 +142,8 @@ class wivrn_session : public xrt_system_devices // run-time editable settings thread_safe settings; - // when sessions shall be destroyed, key is timestap, value is client id - thread_safe> session_loss; + // when sessions shall be destroyed, key is client id, value is timestamp + thread_safe> session_loss; std::jthread thread;