Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Vindicus999
2025-07-05 17:13:10 +00:00
6 changed files with 90 additions and 12 deletions
+23 -4
View File
@@ -76,7 +76,7 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
.supported = {
.orientation_tracking = true,
.position_tracking = true,
.presence = info.presence,
.presence = true,
.battery_status = true,
},
.update_inputs = [](xrt_device *) { return XRT_SUCCESS; },
@@ -232,9 +232,28 @@ void wivrn_hmd::update_visibility_mask(const from_headset::visibility_mask_chang
m->at(mask.view_index) = mask.data;
}
void wivrn_hmd::update_presence(bool presence)
bool wivrn_hmd::update_presence(bool new_presence, bool real)
{
U_LOG_I("Updating user presence to %s", presence ? "true" : "false");
this->presence = 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 (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;
return true;
}
return false;
}
} // namespace wivrn
+6 -1
View File
@@ -47,6 +47,10 @@ 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;
@@ -84,6 +88,7 @@ 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 &);
void update_presence(bool presence);
// real if this update comes from a presence changed event
bool update_presence(bool new_presence, bool real);
};
} // namespace wivrn
+50 -5
View File
@@ -39,6 +39,7 @@
#include "wivrn_ipc.h"
#include "wivrn_packets.h"
#include "xr/to_string.h"
#include "xrt/xrt_device.h"
#include "xrt/xrt_session.h"
#include <algorithm>
@@ -578,17 +579,61 @@ void wivrn_session::operator()(from_headset::visibility_mask_changed && mask)
auto result = xrt_session_event_sink_push(&xrt_system.broadcast, &event);
}
void wivrn_session::operator()(from_headset::user_presence_changed && event)
void wivrn_session::operator()(from_headset::session_state_changed && event)
{
hmd.update_presence(event.present);
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;
}
if (changed)
{
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});
}
push_event(
{
.presence_change = {
.type = XRT_SESSION_EVENT_USER_PRESENCE_CHANGE,
.is_user_present = event.present,
.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))
push_event(
{
.presence_change = {
.type = XRT_SESSION_EVENT_USER_PRESENCE_CHANGE,
.is_user_present = event.present,
},
});
}
void wivrn_session::operator()(from_headset::refresh_rate_changed && event)
{
+1
View File
@@ -179,6 +179,7 @@ public:
void operator()(from_headset::feedback &&);
void operator()(from_headset::battery &&);
void operator()(from_headset::visibility_mask_changed &&);
void operator()(from_headset::session_state_changed &&);
void operator()(from_headset::user_presence_changed &&);
void operator()(from_headset::refresh_rate_changed &&);
void operator()(audio_data &&);