From b31f6bc983cde7834d8f2227dc2268ac84c88326 Mon Sep 17 00:00:00 2001 From: Schmarni Date: Thu, 7 Aug 2025 03:33:18 +0200 Subject: [PATCH] fix(wayland): use an actual timestamp for the frame callback Signed-off-by: Schmarni --- Cargo.lock | 1 + Cargo.toml | 1 + src/nodes/drawable/lines.rs | 1 + src/wayland/mod.rs | 11 ++++++----- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 35f9e36..f6eb461 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5475,6 +5475,7 @@ dependencies = [ "parking_lot 0.12.4", "rand", "rustc-hash 2.1.1", + "rustix 1.0.8", "serde", "serde_repr", "slotmap", diff --git a/Cargo.toml b/Cargo.toml index 09dc92d..85db8a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -151,6 +151,7 @@ memfd = { version = "0.6.4", optional = true } vulkano = { git = "https://github.com/Schmarni-Dev/vulkano", branch = "0_35_dmabuf_fixes", optional = true } wgpu-hal = { version = "24", optional = true, features = ["vulkan"] } ash = { version = "0.38.0", optional = true, default-features = false } +rustix = { version = "1.0.8", features = ["time"] } [dependencies.stardust-xr] workspace = true diff --git a/src/nodes/drawable/lines.rs b/src/nodes/drawable/lines.rs index 09c5d39..1bff47d 100644 --- a/src/nodes/drawable/lines.rs +++ b/src/nodes/drawable/lines.rs @@ -181,6 +181,7 @@ fn build_line_mesh( MeshMaterial3d(materials.add(BevyMaterial { base_color: Color::WHITE, perceptual_roughness: 1.0, + // TODO: this should be Blend alpha_mode: AlphaMode::Opaque, ..default() })), diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index 91daa90..3a8cb1f 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -32,6 +32,7 @@ use core::{buffer::Buffer, callback::Callback, surface::WL_SURFACE_REGISTRY}; use display::Display; use mint::Vector2; use std::fs::File; +use std::time::Duration; use std::{ fs::{self, OpenOptions}, io::{self, ErrorKind}, @@ -169,15 +170,13 @@ impl WaylandClient { } Err(e) => { // wayland clients really aren't nice when disconnecting properly, are they? :p - if let server::Error::Decode(DecodeError::IoError(e)) = &e { - if e.kind() == io::ErrorKind::ConnectionReset { + if let server::Error::Decode(DecodeError::IoError(e)) = &e && e.kind() == io::ErrorKind::ConnectionReset { if let Some(pid) = client.get::(ObjectId::DISPLAY).and_then(|d| d.pid) { tracing::info!("Wayland: Client with pid: {pid} disconnected from server"); } else { tracing::info!("Wayland: Unknown client disconnected from server"); } break; - } } tracing::error!("Wayland: Error reading message: {:?}", e); break; @@ -205,8 +204,10 @@ impl WaylandClient { match message { Message::Disconnect => return Ok(true), Message::Frame(callback) => { - let serial = client.next_event_serial(); - callback.done(client, callback.0, serial).await?; + let now = rustix::time::clock_gettime(rustix::time::ClockId::Monotonic); + let now = Duration::new(now.tv_sec as u64, now.tv_nsec as u32); + let ms = (now.as_millis() % (u32::MAX as u128)) as u32; + callback.done(client, callback.0, ms).await?; client .get::(ObjectId::DISPLAY) .unwrap()