Telemetry: the screen also when Wayland names it late

Right after a window is made, Wayland doesn't say which screen it is on, so
current_monitor() is None and display was missing (seen end to end in a headless
sway). Fall back to the primary, else the only, monitor, and read it again when a
session ends; agent control's status (the benchmark report's display) uses the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-23 02:55:38 +02:00
parent a57efd4fa0
commit 75d818fad6
3 changed files with 32 additions and 17 deletions
+6 -16
View File
@@ -7703,6 +7703,10 @@ impl Game<'_> {
fullscreen: s.fullscreen,
graphics: s.graphics_preset.clone(),
};
// Again now: on Wayland the window is on a screen only once it has been shown.
if let Some(window) = &self.window {
horizon_client::telemetry::note_display(window);
}
self.perf
.finish(&horizon_client::logging::game_home(), settings);
}
@@ -10501,14 +10505,7 @@ impl ApplicationHandler for Game<'_> {
return;
}
};
if let Some(m) = window.current_monitor() {
horizon_client::telemetry::set_display(
m.size().width,
m.size().height,
m.refresh_rate_millihertz().map_or(0, |r| r.div_ceil(1000)),
m.scale_factor(),
);
}
horizon_client::telemetry::note_display(&window);
match self.new_renderer(window.clone()) {
Ok(r) => {
self.renderer = Some(r);
@@ -12600,14 +12597,7 @@ impl Loading {
return;
}
};
if let Some(m) = window.current_monitor() {
horizon_client::telemetry::set_display(
m.size().width,
m.size().height,
m.refresh_rate_millihertz().map_or(0, |r| r.div_ceil(1000)),
m.scale_factor(),
);
}
horizon_client::telemetry::note_display(&window);
let offscreen = self.options.as_ref().is_some_and(|o| o.offscreen);
match loading_renderer(
window.clone(),
+1 -1
View File
@@ -906,7 +906,7 @@ impl Game<'_> {
"streaming": self.streaming.stages().into_iter().map(|(k, v)| (k.to_string(), v.into())).collect::<serde_json::Map<_, _>>(),
"dirty_light": self.world.dirty_light.len(),
"renderer": renderer,
"display": self.window.as_ref().and_then(|w| w.current_monitor()).map(|m| json!({
"display": self.window.as_deref().and_then(horizon_client::telemetry::monitor).map(|m| json!({
"width": m.size().width,
"height": m.size().height,
"scale": m.scale_factor(),
+25
View File
@@ -88,6 +88,31 @@ pub fn set_display(width: u32, height: u32, refresh_hz: u32, scale: f64) {
});
}
/// The screen `window` is on, else the primary one, else the only one: right after the window
/// is made, Wayland doesn't say yet which screen it is on.
pub fn monitor(window: &winit::window::Window) -> Option<winit::monitor::MonitorHandle> {
let only = || {
let mut all = window.available_monitors();
all.next().filter(|_| all.next().is_none())
};
window
.current_monitor()
.or_else(|| window.primary_monitor())
.or_else(only)
}
/// Keeps [`monitor`]'s size, refresh rate and scale for the items' `system.display`.
pub fn note_display(window: &winit::window::Window) {
if let Some(m) = monitor(window) {
set_display(
m.size().width,
m.size().height,
m.refresh_rate_millihertz().map_or(0, |r| r.div_ceil(1000)),
m.scale_factor(),
);
}
}
/// wgpu's device type in the words items use.
pub fn gpu_kind(device_type: &str) -> &'static str {
match device_type {