Don't fake user presence, use focused instead

This commit is contained in:
Patrick Nicolas
2025-09-27 10:08:51 +02:00
parent 4e5eca204f
commit fcbdda9908
13 changed files with 518 additions and 96 deletions
+4 -19
View File
@@ -75,7 +75,7 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
.supported = {
.orientation_tracking = true,
.position_tracking = true,
.presence = true,
.presence = info.user_presence,
.battery_status = true,
},
.update_inputs = [](xrt_device *) { return XRT_SUCCESS; },
@@ -231,28 +231,13 @@ void wivrn_hmd::update_visibility_mask(const from_headset::visibility_mask_chang
m->at(mask.view_index) = mask.data;
}
bool wivrn_hmd::update_presence(bool new_presence, bool real)
bool wivrn_hmd::update_presence(bool new_presence)
{
// if this presence change comes from headset, always honor it,
// otherwise try to keep it in sync with the real presence,
// while still changing presence to false when session is not
// visible
if (real || new_presence == this->real_presence || !new_presence)
if (this->presence.exchange(new_presence) != new_presence)
{
if (real && this->real_presence != new_presence)
{
U_LOG_I("Updating real user presence: %s -> %s", real_presence ? "true" : "false", new_presence ? "true" : "false");
this->real_presence = new_presence;
}
if (this->presence == new_presence)
return false;
U_LOG_I("Updating user presence: %s -> %s", this->presence ? "true" : "false", new_presence ? "true" : "false");
this->presence = new_presence;
U_LOG_I("user presence changed to %s", new_presence ? "true" : "false");
return true;
}
return false;
}
} // namespace wivrn
+1 -6
View File
@@ -54,10 +54,6 @@ class wivrn_hmd : public xrt_device
from_headset::battery battery{};
std::atomic<bool> presence{true};
// last XR_EVENT_DATA_USER_PRESENCE_CHANGED_EXT from headset
// we must keep track of this to not go out of sync with headset when
// a session state change also triggers presence change
std::atomic<bool> real_presence{true};
thread_safe<std::array<std::optional<from_headset::visibility_mask_changed::masks>, 2>> visibility_mask;
wivrn::wivrn_session * cnx;
@@ -86,7 +82,6 @@ public:
void update_battery(const from_headset::battery &);
void update_tracking(const from_headset::tracking &, const clock_offset &);
void update_visibility_mask(const from_headset::visibility_mask_changed &);
// real if this update comes from a presence changed event
bool update_presence(bool new_presence, bool real);
bool update_presence(bool);
};
} // namespace wivrn
+18 -28
View File
@@ -25,6 +25,8 @@
#include "main/comp_compositor.h"
#include "main/comp_main_interface.h"
#include "main/comp_target.h"
#include "server/ipc_server.h"
#include "target_instance_wivrn.h"
#include "util/u_builders.h"
#include "util/u_logging.h"
#include "util/u_system.h"
@@ -139,7 +141,7 @@ bool wivrn::tracking_control_t::set_enabled(to_headset::tracking_control::id id,
return changed;
}
wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection, u_system & system) :
wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection, instance & inst, u_system & system) :
xrt_system_devices{
.get_roles = [](xrt_system_devices * self, xrt_system_roles * out_roles) { return ((wivrn_session *)self)->get_roles(out_roles); },
.feature_inc = [](xrt_system_devices * self, xrt_device_feature_type f) { return ((wivrn_session *)self)->feature_inc(f); },
@@ -147,6 +149,7 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
.destroy = [](xrt_system_devices * self) { delete ((wivrn_session *)self); },
},
connection(std::move(connection)),
inst(inst),
xrt_system(system),
hmd(this, get_info()),
left_controller(0, &hmd, this),
@@ -305,6 +308,7 @@ wivrn_session::~wivrn_session()
}
xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connection> connection,
instance & inst,
u_system & system,
xrt_system_devices ** out_xsysd,
xrt_space_overseer ** out_xspovrs,
@@ -313,7 +317,7 @@ xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connecti
std::unique_ptr<wivrn_session> self;
try
{
self.reset(new wivrn_session(std::move(connection), system));
self.reset(new wivrn_session(std::move(connection), inst, system));
}
catch (std::exception & e)
{
@@ -330,6 +334,7 @@ xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connecti
U_LOG_E("Failed to create system compositor");
return xret;
}
self->system_compositor = *out_xsysc;
u_builder_create_space_overseer_legacy(
&self->xrt_system.broadcast,
@@ -668,49 +673,34 @@ void wivrn_session::operator()(from_headset::session_state_changed && event)
{
U_LOG_I("Session state changed: %s", xr::to_string(event.state));
bool visible, focused;
bool changed = false;
switch (event.state)
{
case XR_SESSION_STATE_SYNCHRONIZED:
visible = false;
focused = false;
changed = hmd.update_presence(false, false);
break;
case XR_SESSION_STATE_VISIBLE:
visible = true;
focused = false;
changed = hmd.update_presence(true, false);
break;
case XR_SESSION_STATE_FOCUSED:
visible = true;
focused = true;
changed = hmd.update_presence(true, false);
break;
default:
return;
visible = false;
focused = false;
break;
}
if (changed)
scoped_lock lock(inst.server->global_state.lock);
for (auto & t: inst.server->threads)
{
xrt_session_event_user_presence_change event = {
.type = XRT_SESSION_EVENT_USER_PRESENCE_CHANGE,
};
hmd.get_presence(&event.is_user_present);
push_event({.presence_change = event});
if (t.ics.server_thread_index < 0 or t.ics.xc == nullptr)
continue;
bool current = t.ics.client_state.session_overlay or
inst.server->global_state.active_client_index == t.ics.server_thread_index;
xrt_syscomp_set_state(system_compositor, t.ics.xc, visible and current, focused and current);
}
push_event(
{
.state = {
.type = XRT_SESSION_EVENT_STATE_CHANGE,
.visible = visible,
.focused = focused,
},
});
}
void wivrn_session::operator()(from_headset::user_presence_changed && event)
{
if (hmd.update_presence(event.present, true))
if (hmd.update_presence(event.present))
push_event(
{
.presence_change = {
+5 -1
View File
@@ -43,6 +43,7 @@ union xrt_session_event;
namespace wivrn
{
class instance;
class wivrn_eye_tracker;
class wivrn_fb_face2_tracker;
class wivrn_htc_face_tracker;
@@ -92,10 +93,12 @@ class wivrn_session : public xrt_system_devices
{
friend wivrn_comp_target_factory;
std::unique_ptr<wivrn_connection> connection;
instance & inst;
pacing_app_factory app_pacers;
u_system & xrt_system;
xrt_space_overseer * space_overseer;
xrt_system_compositor * system_compositor;
std::mutex roles_mutex;
xrt_system_roles roles{
@@ -133,12 +136,13 @@ class wivrn_session : public xrt_system_devices
std::jthread thread;
wivrn_session(std::unique_ptr<wivrn_connection> connection, u_system &);
wivrn_session(std::unique_ptr<wivrn_connection> connection, instance &, u_system &);
public:
~wivrn_session();
static xrt_result_t create_session(std::unique_ptr<wivrn_connection> connection,
instance & instance,
u_system & system,
xrt_system_devices ** out_xsysd,
xrt_space_overseer ** out_xspovrs,