Skip to content

Commit

Permalink
WIP wl_fix protocol to destroy wl_registry
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed May 13, 2024
1 parent f7638e8 commit 357758a
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 9 deletions.
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
17 changes: 11 additions & 6 deletions anvil/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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::{
Expand Down Expand Up @@ -532,6 +534,8 @@ impl<BackendData: Backend> XdgForeignHandler for AnvilState<BackendData> {
}
smithay::delegate_xdg_foreign!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

delegate_fixes!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend + 'static> AnvilState<BackendData> {
pub fn init(
display: Display<AnvilState<BackendData>>,
Expand Down Expand Up @@ -610,6 +614,7 @@ impl<BackendData: Backend + 'static> AnvilState<BackendData> {
.get_data::<ClientState>()
.map_or(true, |client_state| client_state.security_context.is_none())
});
FixesState::new::<Self>(&dh);

// init input
let seat_name = backend_data.seat_name();
Expand Down
79 changes: 79 additions & 0 deletions src/wayland/fixes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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<D>(display: &DisplayHandle) -> Self
where
D: GlobalDispatch<wl_fixes::WlFixes, ()>,
D: Dispatch<wl_fixes::WlFixes, ()>,
D: 'static,
{
let global = display.create_global::<D, wl_fixes::WlFixes, _>(1, ());
Self { global }
}

pub fn global(&self) -> GlobalId {
self.global.clone()
}
}

impl<D> GlobalDispatch<wl_fixes::WlFixes, (), D> for FixesState
where
D: GlobalDispatch<wl_fixes::WlFixes, ()>,
D: Dispatch<wl_fixes::WlFixes, ()>,
D: 'static,
{
fn bind(
_state: &mut D,
_dh: &DisplayHandle,
_client: &Client,
resource: New<wl_fixes::WlFixes>,
_global_data: &(),
data_init: &mut DataInit<'_, D>,
) {
data_init.init(resource, ());
}
}

impl<D> Dispatch<wl_fixes::WlFixes, (), D> for FixesState
where
D: Dispatch<wl_fixes::WlFixes, ()>,
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::<D>(&registry.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);
};
}
1 change: 1 addition & 0 deletions src/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/wayland/shell/xdg/handlers/positioner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 357758a

Please sign in to comment.