diff --git a/src/wayland/core/compositor.rs b/src/wayland/core/compositor.rs index 7948b55..cd145f6 100644 --- a/src/wayland/core/compositor.rs +++ b/src/wayland/core/compositor.rs @@ -21,7 +21,7 @@ impl WlCompositor for Compositor { ) -> Result<()> { let surface = client.insert(id, Surface::new(client, id)); if let Some(output) = client.display().output.get() { - surface.enter(client, id, output.0).await?; + surface.enter(client, id, output.id).await?; } WL_SURFACE_REGISTRY.add_raw(&surface); diff --git a/src/wayland/core/output.rs b/src/wayland/core/output.rs index a9164ca..acd8e52 100644 --- a/src/wayland/core/output.rs +++ b/src/wayland/core/output.rs @@ -6,12 +6,15 @@ use waynest::{ pub use waynest::server::protocol::core::wayland::wl_output::*; #[derive(Debug, Dispatcher)] -pub struct Output(pub ObjectId); +pub struct Output { + pub id: ObjectId, + pub version: u32, +} impl Output { pub async fn advertise_outputs(&self, client: &mut Client) -> Result<()> { self.geometry( client, - self.0, + self.id, 2048, 2048, 0, @@ -23,10 +26,13 @@ impl Output { ) .await?; - self.mode(client, self.0, Mode::Current, 2048, 2048, i32::MAX) + self.mode(client, self.id, Mode::Current, 2048, 2048, i32::MAX) .await?; - self.done(client, self.0).await + if self.version >= 2 { + self.done(client, self.id).await?; + } + Ok(()) } } impl WlOutput for Output { diff --git a/src/wayland/core/pointer.rs b/src/wayland/core/pointer.rs index ad34c1e..f19434a 100644 --- a/src/wayland/core/pointer.rs +++ b/src/wayland/core/pointer.rs @@ -13,12 +13,14 @@ use waynest::{ #[derive(Dispatcher)] pub struct Pointer { pub id: ObjectId, + version: u32, focused_surface: Mutex>, } impl Pointer { - pub fn new(id: ObjectId) -> Self { + pub fn new(id: ObjectId, version: u32) -> Self { Self { id, + version, focused_surface: Mutex::new(Weak::new()), } } @@ -77,7 +79,9 @@ impl Pointer { fixed_from_f32(position.y), ) .await?; - self.frame(client, self.id).await?; + if self.version >= 5 { + self.frame(client, self.id).await?; + } Ok(()) } @@ -141,13 +145,16 @@ impl Pointer { ) .await?; } - if let Some(steps) = scroll_steps { - self.axis_discrete(client, self.id, Axis::HorizontalScroll, steps.x as i32) - .await?; - self.axis_discrete(client, self.id, Axis::VerticalScroll, steps.y as i32) - .await?; + if self.version >= 5 { + if let Some(steps) = scroll_steps { + self.axis_discrete(client, self.id, Axis::HorizontalScroll, steps.x as i32) + .await?; + self.axis_discrete(client, self.id, Axis::VerticalScroll, steps.y as i32) + .await?; + } + self.frame(client, self.id).await?; } - self.frame(client, self.id).await + Ok(()) } pub async fn reset(&self, client: &mut Client) -> Result<()> { diff --git a/src/wayland/core/seat.rs b/src/wayland/core/seat.rs index 5783187..81cd1d9 100644 --- a/src/wayland/core/seat.rs +++ b/src/wayland/core/seat.rs @@ -49,22 +49,31 @@ pub fn fixed_from_f32(f: f32) -> Fixed { #[derive(Default, Dispatcher)] pub struct Seat { + version: u32, pointer: OnceLock>, keyboard: OnceLock>, touch: OnceLock>, } impl Seat { - pub fn new() -> Self { - Self::default() - } + pub async fn new(client: &mut Client, id: ObjectId, version: u32) -> Result { + let seat = Self { + version, + pointer: OnceLock::new(), + keyboard: OnceLock::new(), + touch: OnceLock::new(), + }; + + if version >= 2 { + seat.name(client, id, "theonlyseat".into()).await?; + } - pub async fn advertise_capabilities(&self, client: &mut Client, id: ObjectId) -> Result<()> { tracing::debug!("Advertising seat capabilities with id {}", id); let capabilities = Capability::Pointer | Capability::Keyboard | Capability::Touch; - WlSeat::capabilities(self, client, id, capabilities).await?; + WlSeat::capabilities(&seat, client, id, capabilities).await?; tracing::debug!("Capabilities advertised: {:?}", capabilities); - Ok(()) + + Ok(seat) } pub async fn handle_message(&self, client: &mut Client, message: SeatMessage) -> Result<()> { @@ -154,7 +163,7 @@ impl WlSeat for Seat { _sender_id: ObjectId, id: ObjectId, ) -> Result<()> { - let pointer = client.insert(id, Pointer::new(id)); + let pointer = client.insert(id, Pointer::new(id, self.version)); let _ = self.pointer.set(pointer); Ok(()) } diff --git a/src/wayland/core/surface.rs b/src/wayland/core/surface.rs index 095910d..07836b9 100644 --- a/src/wayland/core/surface.rs +++ b/src/wayland/core/surface.rs @@ -253,7 +253,11 @@ impl Surface { .collect::>(); for feedback in feedbacks { feedback - .sync_output(client, feedback.0, client.display().output.get().unwrap().0) + .sync_output( + client, + feedback.0, + client.display().output.get().unwrap().id, + ) .await?; let cycle_lo = refresh_cycle as u32; let cycle_hi = (refresh_cycle >> 32) as u32; diff --git a/src/wayland/registry.rs b/src/wayland/registry.rs index 45200e4..1541d55 100644 --- a/src/wayland/registry.rs +++ b/src/wayland/registry.rs @@ -5,15 +5,24 @@ use crate::wayland::{ output::{Output, WlOutput}, seat::{Seat, WlSeat}, shm::{Shm, WlShm}, - }, dmabuf::Dmabuf, mesa_drm::MesaDrm, presentation::Presentation, util::ClientExt, xdg::wm_base::{WmBase, XdgWmBase} + }, + dmabuf::Dmabuf, + mesa_drm::MesaDrm, + presentation::Presentation, + util::ClientExt, + xdg::wm_base::{WmBase, XdgWmBase}, }; use waynest::{ server::{ + Client, Dispatcher, Error, Result, protocol::{ core::wayland::{wl_data_device_manager::WlDataDeviceManager, wl_registry::*}, external::drm::wl_drm::WlDrm, - stable::{linux_dmabuf_v1::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1, presentation_time::wp_presentation::WpPresentation}, - }, Client, Dispatcher, Error, Result + stable::{ + linux_dmabuf_v1::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1, + presentation_time::wp_presentation::WpPresentation, + }, + }, }, wire::{NewId, ObjectId}, }; @@ -145,12 +154,10 @@ impl WlRegistry for Registry { } RegistryGlobals::SEAT => { tracing::info!("Binding seat with id {}", new_id.object_id); - let seat = client.insert(new_id.object_id, Seat::new()); + let seat = Seat::new(client, new_id.object_id, new_id.version).await?; + let seat = client.insert(new_id.object_id, seat); let _ = client.display().seat.set(seat.clone()); - seat.name(client, new_id.object_id, "theonlyseat".into()) - .await?; - seat.advertise_capabilities(client, new_id.object_id) - .await?; + tracing::info!("Seat capabilities advertised"); } RegistryGlobals::DATA_DEVICE_MANAGER => { @@ -159,7 +166,13 @@ impl WlRegistry for Registry { } RegistryGlobals::OUTPUT => { tracing::info!("Binding output"); - let output = client.insert(new_id.object_id, Output(new_id.object_id)); + let output = client.insert( + new_id.object_id, + Output { + id: new_id.object_id, + version: new_id.version, + }, + ); let _ = client.display().output.set(output.clone()); output.advertise_outputs(client).await?; }