From f27c8c16cab43713a6bd5bdf77d094189afad131 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Fri, 10 May 2024 18:17:19 -0700 Subject: [PATCH] WIP `wl_fix` protocol to destroy `wl_registry` --- Cargo.toml | 11 +++ anvil/src/state.rs | 17 +++-- src/wayland/fixes.rs | 80 ++++++++++++++++++++ src/wayland/mod.rs | 1 + src/wayland/shell/xdg/handlers/positioner.rs | 6 +- 5 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 src/wayland/fixes.rs diff --git a/Cargo.toml b/Cargo.toml index 4f53f42f0c5f..0dda290f9c46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,6 +76,17 @@ criterion = { version = "0.5" } image = "0.25" tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } +[patch.crates-io] +wayland-egl = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" } +wayland-protocols = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" } +wayland-protocols-wlr = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" } +wayland-protocols-misc = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" } +wayland-server = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" } +wayland-client = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" } +wayland-sys = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" } +wayland-backend = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" } +wayland-scanner = { git = "https://github.com/ids1024/wayland-rs", branch = "wl-fixes" } + [build-dependencies] gl_generator = { version = "0.14", optional = true } pkg-config = { version = "0.3.17", optional = true } diff --git a/anvil/src/state.rs b/anvil/src/state.rs index 4fb3ea715514..24b5804a3943 100644 --- a/anvil/src/state.rs +++ b/anvil/src/state.rs @@ -13,12 +13,13 @@ use smithay::{ default_primary_scanout_output_compare, utils::select_dmabuf_feedback, RenderElementStates, }, }, - delegate_compositor, delegate_data_control, delegate_data_device, delegate_fractional_scale, - delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit, delegate_layer_shell, - delegate_output, delegate_pointer_constraints, delegate_pointer_gestures, delegate_presentation, - delegate_primary_selection, delegate_relative_pointer, delegate_seat, delegate_security_context, - delegate_shm, delegate_tablet_manager, delegate_text_input_manager, delegate_viewporter, - delegate_virtual_keyboard_manager, delegate_xdg_activation, delegate_xdg_decoration, delegate_xdg_shell, + delegate_compositor, delegate_data_control, delegate_data_device, delegate_fixes, + delegate_fractional_scale, delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit, + delegate_layer_shell, delegate_output, delegate_pointer_constraints, delegate_pointer_gestures, + delegate_presentation, delegate_primary_selection, delegate_relative_pointer, delegate_seat, + delegate_security_context, delegate_shm, delegate_tablet_manager, delegate_text_input_manager, + delegate_viewporter, delegate_virtual_keyboard_manager, delegate_xdg_activation, delegate_xdg_decoration, + delegate_xdg_shell, desktop::{ space::SpaceElement, utils::{ @@ -48,6 +49,7 @@ use smithay::{ wayland::{ compositor::{get_parent, with_states, CompositorClientState, CompositorState}, dmabuf::DmabufFeedback, + fixes::FixesState, fractional_scale::{with_fractional_scale, FractionalScaleHandler, FractionalScaleManagerState}, input_method::{InputMethodHandler, InputMethodManagerState, PopupSurface}, keyboard_shortcuts_inhibit::{ @@ -532,6 +534,8 @@ impl XdgForeignHandler for AnvilState { } smithay::delegate_xdg_foreign!(@ AnvilState); +delegate_fixes!(@ AnvilState); + impl AnvilState { pub fn init( display: Display>, @@ -610,6 +614,7 @@ impl AnvilState { .get_data::() .map_or(true, |client_state| client_state.security_context.is_none()) }); + FixesState::new::(&dh); // init input let seat_name = backend_data.seat_name(); diff --git a/src/wayland/fixes.rs b/src/wayland/fixes.rs new file mode 100644 index 000000000000..30620246294c --- /dev/null +++ b/src/wayland/fixes.rs @@ -0,0 +1,80 @@ +use wayland_server::{ + backend::GlobalId, protocol::wl_fixes, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, + Resource, +}; + +#[derive(Debug, Clone)] +pub struct FixesState { + global: GlobalId, +} + +impl FixesState { + pub fn new(display: &DisplayHandle) -> Self + where + D: GlobalDispatch, + D: Dispatch, + D: 'static, + { + let global = display.create_global::(1, ()); + Self { global } + } + + pub fn global(&self) -> GlobalId { + self.global.clone() + } +} + +impl GlobalDispatch for FixesState +where + D: GlobalDispatch, + D: Dispatch, + D: 'static, +{ + fn bind( + _state: &mut D, + _dh: &DisplayHandle, + _client: &Client, + resource: New, + _global_data: &(), + data_init: &mut DataInit<'_, D>, + ) { + data_init.init(resource, ()); + } +} + +impl Dispatch for FixesState +where + D: Dispatch, + D: 'static, +{ + fn request( + _state: &mut D, + _client: &Client, + _resource: &wl_fixes::WlFixes, + request: wl_fixes::Request, + _data: &(), + dh: &DisplayHandle, + _data_init: &mut DataInit<'_, D>, + ) { + match request { + wl_fixes::Request::DestroyRegistry { registry } => { + dh.backend_handle() + .destroy_object::(®istry.id()); + } + wl_fixes::Request::Destroy => {} + _ => unreachable!(), + } + } +} + +#[macro_export] +macro_rules! delegate_fixes { + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { + $crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ + $crate::reexports::wayland_server::protocol::wl_fixes::WlFixes: () + ] => $crate::wayland::fixes::FixesState); + $crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ + $crate::reexports::wayland_server::protocol::wl_fixes::WlFixes: () + ] => $crate::wayland::fixes::FixesState); + }; +} diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index 6ea2a51ba08e..79b988b47b46 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -52,6 +52,7 @@ pub mod cursor_shape; pub mod dmabuf; #[cfg(feature = "backend_drm")] pub mod drm_lease; +pub mod fixes; pub mod fractional_scale; pub mod idle_inhibit; pub mod idle_notify; diff --git a/src/wayland/shell/xdg/handlers/positioner.rs b/src/wayland/shell/xdg/handlers/positioner.rs index c054e377bf0c..c5698fcdb7d1 100644 --- a/src/wayland/shell/xdg/handlers/positioner.rs +++ b/src/wayland/shell/xdg/handlers/positioner.rs @@ -68,9 +68,9 @@ where xdg_positioner::Request::SetConstraintAdjustment { constraint_adjustment, } => { - let constraint_adjustment = - xdg_positioner::ConstraintAdjustment::from_bits_truncate(constraint_adjustment); - state.constraint_adjustment = constraint_adjustment; + if let WEnum::Value(constraint_adjustment) = constraint_adjustment { + state.constraint_adjustment = constraint_adjustment; + } } xdg_positioner::Request::SetOffset { x, y } => { state.offset = (x, y).into();