From 7f9da3686075403ef997ffaee465dcc89be1af98 Mon Sep 17 00:00:00 2001 From: Thomas Colliers Date: Sat, 16 Aug 2025 17:58:19 +0200 Subject: [PATCH] feat(wayland): WIP implementation of wp_importer --- src/wayland/mod.rs | 1 + src/wayland/registry.rs | 18 +++++++++- src/wayland/viewporter.rs | 70 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/wayland/viewporter.rs diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index d33b0d4..5608568 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -6,6 +6,7 @@ mod presentation; mod registry; mod util; mod vulkano_data; +mod viewporter; mod xdg; use crate::core::registry::OwnedRegistry; diff --git a/src/wayland/registry.rs b/src/wayland/registry.rs index 571314e..ed2af75 100644 --- a/src/wayland/registry.rs +++ b/src/wayland/registry.rs @@ -9,6 +9,7 @@ use crate::wayland::{ dmabuf::Dmabuf, mesa_drm::MesaDrm, presentation::Presentation, + viewporter::Viewporter, util::ClientExt, xdg::wm_base::{WmBase, XdgWmBase}, }; @@ -20,7 +21,7 @@ use waynest::{ external::drm::wl_drm::WlDrm, stable::{ linux_dmabuf_v1::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1, - presentation_time::wp_presentation::WpPresentation, + presentation_time::wp_presentation::WpPresentation, viewporter::wp_viewporter::WpViewporter, }, }, }, @@ -38,6 +39,7 @@ impl RegistryGlobals { pub const DMABUF: u32 = 6; pub const WL_DRM: u32 = 7; pub const PRESENTATION: u32 = 8; + pub const VIEWPORTER: u32 = 9; } #[derive(Debug, Dispatcher, Default)] @@ -126,6 +128,15 @@ impl Registry { ) .await?; + self.global( + client, + sender_id, + RegistryGlobals::VIEWPORTER, + Viewporter::INTERFACE.to_string(), + Viewporter::VERSION, + ) + .await?; + Ok(()) } } @@ -198,6 +209,11 @@ impl WlRegistry for Registry { client.insert(new_id.object_id, Presentation); } + RegistryGlobals::VIEWPORTER => { + tracing::info!("Binding wp_viewporter"); + + client.insert(new_id.object_id, Viewporter::default()); + } id => { tracing::error!(id, "Wayland: failed to bind to registry global"); return Err(Error::MissingObject(unsafe { ObjectId::from_raw(name) })); diff --git a/src/wayland/viewporter.rs b/src/wayland/viewporter.rs new file mode 100644 index 0000000..9ba051f --- /dev/null +++ b/src/wayland/viewporter.rs @@ -0,0 +1,70 @@ +use waynest::{ + server::{Client, Dispatcher, Result}, + wire::{ObjectId, Fixed}, +}; + +pub use waynest::server::protocol::stable::viewporter::wp_viewport::*; +pub use waynest::server::protocol::stable::viewporter::wp_viewporter::*; + +// This is a barebones/stub no-op implementation of wp_viewporter to make xwayland apps work + +#[derive(Debug, Dispatcher, Default)] +pub struct Viewporter; + +impl WpViewporter for Viewporter { + async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> { + Ok(()) + } + + async fn get_viewport( + &self, + client: &mut Client, + _sender_id: ObjectId, + id: ObjectId, + surface_id: ObjectId, + ) -> Result<()> { + let viewport = Viewport::new(id, surface_id); + client.insert(id, viewport); + Ok(()) + } +} + +#[derive(Debug, Dispatcher)] +pub struct Viewport { + id: ObjectId, + surface_id: ObjectId, +} + +impl Viewport { + pub fn new(id: ObjectId, surface_id: ObjectId) -> Self { + Self { id, surface_id } + } +} + +impl WpViewport for Viewport { + async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> { + Ok(()) + } + + async fn set_source( + &self, + _client: &mut Client, + _sender_id: ObjectId, + _x: Fixed, + _y: Fixed, + _width: Fixed, + _height: Fixed, + ) -> Result<()> { + Ok(()) + } + + async fn set_destination( + &self, + _client: &mut Client, + _sender_id: ObjectId, + _width: i32, + _height: i32, + ) -> Result<()> { + Ok(()) + } +} \ No newline at end of file -- 2.49.1