diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index f69198a92..eb916b341 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -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(), diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index 6c5eec301..0db55a111 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -906,7 +906,7 @@ impl Game<'_> { "streaming": self.streaming.stages().into_iter().map(|(k, v)| (k.to_string(), v.into())).collect::>(), "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(), diff --git a/crates/horizon-client/src/telemetry.rs b/crates/horizon-client/src/telemetry.rs index b8b7af0b4..afd2dbc94 100644 --- a/crates/horizon-client/src/telemetry.rs +++ b/crates/horizon-client/src/telemetry.rs @@ -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 { + 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 {