Skip to content

Commit

Permalink
Port to delegated dispatches
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Feb 12, 2024
1 parent 203c91c commit b27cb8e
Show file tree
Hide file tree
Showing 83 changed files with 797 additions and 1,923 deletions.
43 changes: 0 additions & 43 deletions anvil/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ use smithay::{
backend::renderer::element::{
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,
desktop::{
space::SpaceElement,
utils::{
Expand Down Expand Up @@ -92,7 +86,6 @@ use crate::cursor::Cursor;
use crate::{focus::FocusTarget, shell::WindowElement};
#[cfg(feature = "xwayland")]
use smithay::{
delegate_xwayland_keyboard_grab,
utils::{Point, Size},
wayland::selection::{SelectionSource, SelectionTarget},
wayland::xwayland_keyboard_grab::{XWaylandKeyboardGrabHandler, XWaylandKeyboardGrabState},
Expand Down Expand Up @@ -168,8 +161,6 @@ pub struct AnvilState<BackendData: Backend + 'static> {
pub show_window_preview: bool,
}

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

impl<BackendData: Backend> DataDeviceHandler for AnvilState<BackendData> {
fn data_device_state(&self) -> &DataDeviceState {
&self.data_device_state
Expand All @@ -189,10 +180,8 @@ impl<BackendData: Backend> ServerDndGrabHandler for AnvilState<BackendData> {
unreachable!("Anvil doesn't do server-side grabs");
}
}
delegate_data_device!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend> OutputHandler for AnvilState<BackendData> {}
delegate_output!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend> SelectionHandler for AnvilState<BackendData> {
type SelectionUserData = ();
Expand Down Expand Up @@ -228,22 +217,18 @@ impl<BackendData: Backend> PrimarySelectionHandler for AnvilState<BackendData> {
&self.primary_selection_state
}
}
delegate_primary_selection!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend> DataControlHandler for AnvilState<BackendData> {
fn data_control_state(&self) -> &DataControlState {
&self.data_control_state
}
}

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

impl<BackendData: Backend> ShmHandler for AnvilState<BackendData> {
fn shm_state(&self) -> &ShmState {
&self.shm_state
}
}
delegate_shm!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend> SeatHandler for AnvilState<BackendData> {
type KeyboardFocus = FocusTarget;
Expand All @@ -270,11 +255,6 @@ impl<BackendData: Backend> SeatHandler for AnvilState<BackendData> {
self.backend_data.update_led_state(led_state)
}
}
delegate_seat!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

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

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

impl<BackendData: Backend> InputMethodHandler for AnvilState<BackendData> {
fn new_popup(&mut self, surface: PopupSurface) {
Expand All @@ -297,8 +277,6 @@ impl<BackendData: Backend> InputMethodHandler for AnvilState<BackendData> {
}
}

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

impl<BackendData: Backend> KeyboardShortcutsInhibitHandler for AnvilState<BackendData> {
fn keyboard_shortcuts_inhibit_state(&mut self) -> &mut KeyboardShortcutsInhibitState {
&mut self.keyboard_shortcuts_inhibit_state
Expand All @@ -310,14 +288,6 @@ impl<BackendData: Backend> KeyboardShortcutsInhibitHandler for AnvilState<Backen
}
}

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

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

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

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

impl<BackendData: Backend> PointerConstraintsHandler for AnvilState<BackendData> {
fn new_constraint(&mut self, surface: &WlSurface, pointer: &PointerHandle<Self>) {
// XXX region
Expand All @@ -328,9 +298,6 @@ impl<BackendData: Backend> PointerConstraintsHandler for AnvilState<BackendData>
}
}
}
delegate_pointer_constraints!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

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

impl<BackendData: Backend> XdgActivationHandler for AnvilState<BackendData> {
fn activation_state(&mut self) -> &mut XdgActivationState {
Expand Down Expand Up @@ -369,7 +336,6 @@ impl<BackendData: Backend> XdgActivationHandler for AnvilState<BackendData> {
}
}
}
delegate_xdg_activation!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend> XdgDecorationHandler for AnvilState<BackendData> {
fn new_decoration(&mut self, toplevel: ToplevelSurface) {
Expand Down Expand Up @@ -421,11 +387,6 @@ impl<BackendData: Backend> XdgDecorationHandler for AnvilState<BackendData> {
}
}
}
delegate_xdg_decoration!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

delegate_xdg_shell!(@<BackendData: Backend + 'static> AnvilState<BackendData>);
delegate_layer_shell!(@<BackendData: Backend + 'static> AnvilState<BackendData>);
delegate_presentation!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend> FractionalScaleHandler for AnvilState<BackendData> {
fn new_fractional_scale(
Expand Down Expand Up @@ -474,7 +435,6 @@ impl<BackendData: Backend> FractionalScaleHandler for AnvilState<BackendData> {
});
}
}
delegate_fractional_scale!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend + 'static> SecurityContextHandler for AnvilState<BackendData> {
fn context_created(&mut self, source: SecurityContextListenerSource, security_context: SecurityContext) {
Expand All @@ -494,7 +454,6 @@ impl<BackendData: Backend + 'static> SecurityContextHandler for AnvilState<Backe
.expect("Failed to init wayland socket source");
}
}
delegate_security_context!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

#[cfg(feature = "xwayland")]
impl<BackendData: Backend + 'static> XWaylandKeyboardGrabHandler for AnvilState<BackendData> {
Expand All @@ -506,8 +465,6 @@ impl<BackendData: Backend + 'static> XWaylandKeyboardGrabHandler for AnvilState<
Some(FocusTarget::Window(elem.clone()))
}
}
#[cfg(feature = "xwayland")]
delegate_xwayland_keyboard_grab!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend + 'static> AnvilState<BackendData> {
pub fn init(
Expand Down
4 changes: 0 additions & 4 deletions anvil/src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ use smithay::{
vulkan::{version::Version, Instance, PhysicalDevice},
SwapBuffersError,
},
delegate_dmabuf, delegate_drm_lease,
desktop::{
space::{Space, SurfaceTree},
utils::OutputPresentationFeedback,
Expand Down Expand Up @@ -174,7 +173,6 @@ impl DmabufHandler for AnvilState<UdevData> {
}
}
}
delegate_dmabuf!(AnvilState<UdevData>);

impl Backend for UdevData {
const HAS_RELATIVE_MOTION: bool = true;
Expand Down Expand Up @@ -610,8 +608,6 @@ impl DrmLeaseHandler for AnvilState<UdevData> {
}
}

delegate_drm_lease!(AnvilState<UdevData>);

pub type RenderSurface = GbmBufferedSurface<GbmAllocator<DrmDeviceFd>, Option<OutputPresentationFeedback>>;

pub type GbmDrmCompositor = DrmCompositor<
Expand Down
2 changes: 0 additions & 2 deletions anvil/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use smithay::{
winit::{self, WinitEvent, WinitGraphicsBackend},
SwapBuffersError,
},
delegate_dmabuf,
input::{
keyboard::LedState,
pointer::{CursorImageAttributes, CursorImageStatus},
Expand Down Expand Up @@ -81,7 +80,6 @@ impl DmabufHandler for AnvilState<WinitData> {
}
}
}
delegate_dmabuf!(AnvilState<WinitData>);

impl Backend for WinitData {
fn seat_name(&self) -> String {
Expand Down
2 changes: 0 additions & 2 deletions anvil/src/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use smithay::{
vulkan::{version::Version, Instance, PhysicalDevice},
x11::{WindowBuilder, X11Backend, X11Event, X11Surface},
},
delegate_dmabuf,
input::{
keyboard::LedState,
pointer::{CursorImageAttributes, CursorImageStatus},
Expand Down Expand Up @@ -84,7 +83,6 @@ impl DmabufHandler for AnvilState<X11Data> {
}
}
}
delegate_dmabuf!(AnvilState<X11Data>);

impl Backend for X11Data {
fn seat_name(&self) -> String {
Expand Down
3 changes: 0 additions & 3 deletions examples/compositor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::Arc;

use smithay::delegate_compositor;
use smithay::reexports::wayland_server::Display;

use smithay::wayland::compositor::{CompositorClientState, CompositorHandler, CompositorState};
Expand Down Expand Up @@ -74,5 +73,3 @@ impl AsMut<CompositorState> for App {
&mut self.compositor_state
}
}

delegate_compositor!(App);
8 changes: 0 additions & 8 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use smithay::{
},
winit::{self, WinitEvent},
},
delegate_compositor, delegate_data_device, delegate_seat, delegate_shm, delegate_xdg_shell,
input::{keyboard::FilterResult, Seat, SeatHandler, SeatState},
reexports::wayland_server::{protocol::wl_seat, Display},
utils::{Rectangle, Serial, Transform},
Expand Down Expand Up @@ -288,10 +287,3 @@ impl ClientData for ClientState {
println!("disconnected");
}
}

// Macros used to delegate protocol handling to types in the app state.
delegate_xdg_shell!(App);
delegate_compositor!(App);
delegate_shm!(App);
delegate_seat!(App);
delegate_data_device!(App);
3 changes: 0 additions & 3 deletions examples/seat.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::Arc;

use smithay::delegate_seat;
use smithay::input::{keyboard::FilterResult, Seat, SeatHandler, SeatState};
use smithay::reexports::wayland_server::{
backend::{ClientData, ClientId, DisconnectReason},
Expand Down Expand Up @@ -83,5 +82,3 @@ impl ClientData for ClientState {
println!("disconnected");
}
}

delegate_seat!(App);
4 changes: 0 additions & 4 deletions smallvil/src/handlers/compositor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{grabs::resize_grab, state::ClientState, Smallvil};
use smithay::{
backend::renderer::utils::on_commit_buffer_handler,
delegate_compositor, delegate_shm,
reexports::wayland_server::{
protocol::{wl_buffer, wl_surface::WlSurface},
Client,
Expand Down Expand Up @@ -52,6 +51,3 @@ impl ShmHandler for Smallvil {
&self.shm_state
}
}

delegate_compositor!(Smallvil);
delegate_shm!(Smallvil);
6 changes: 0 additions & 6 deletions smallvil/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use smithay::wayland::selection::data_device::{
set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler,
};
use smithay::wayland::selection::SelectionHandler;
use smithay::{delegate_data_device, delegate_output, delegate_seat};

impl SeatHandler for Smallvil {
type KeyboardFocus = WlSurface;
Expand All @@ -34,8 +33,6 @@ impl SeatHandler for Smallvil {
}
}

delegate_seat!(Smallvil);

//
// Wl Data Device
//
Expand All @@ -53,11 +50,8 @@ impl DataDeviceHandler for Smallvil {
impl ClientDndGrabHandler for Smallvil {}
impl ServerDndGrabHandler for Smallvil {}

delegate_data_device!(Smallvil);

//
// Wl Output & Xdg Output
//

impl OutputHandler for Smallvil {}
delegate_output!(Smallvil);
4 changes: 0 additions & 4 deletions smallvil/src/handlers/xdg_shell.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use smithay::{
delegate_xdg_shell,
desktop::{find_popup_root_surface, get_popup_toplevel_coords, PopupKind, PopupManager, Space, Window},
input::{
pointer::{Focus, GrabStartData as PointerGrabStartData},
Expand Down Expand Up @@ -123,9 +122,6 @@ impl XdgShellHandler for Smallvil {
}
}

// Xdg Shell
delegate_xdg_shell!(Smallvil);

fn check_grab(
seat: &Seat<Smallvil>,
surface: &WlSurface,
Expand Down
4 changes: 2 additions & 2 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub mod keyboard;
pub mod pointer;

/// Handler trait for Seats
pub trait SeatHandler: Sized {
pub trait SeatHandler: Sized + 'static {
/// Type used to represent the target currently holding the keyboard focus
type KeyboardFocus: KeyboardTarget<Self> + 'static;
/// Type used to represent the target currently holding the pointer focus
Expand Down Expand Up @@ -290,7 +290,7 @@ impl<D: SeatHandler> SeatState<D> {
}
}

impl<D: SeatHandler + 'static> Seat<D> {
impl<D: SeatHandler> Seat<D> {
/// Access the `UserDataMap` associated with this `Seat`
pub fn user_data(&self) -> &UserDataMap {
&self.arc.user_data_map
Expand Down
12 changes: 12 additions & 0 deletions src/utils/user_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ use std::thread::{self, ThreadId};

use self::list::AppendList;

// TODO: Perhaps make this public
#[cfg(feature = "wayland_frontend")]
pub(crate) trait UserdataGetter<U, DelegatedTo>: wayland_server::Resource
where
U: 'static,
DelegatedTo: 'static,
{
fn user_data(&self) -> Option<&U> {
self.delegated_data::<_, DelegatedTo>()
}
}

// `UserData.get()` is called frequently, and unfortunately
// `thread::current().id()` is not very efficient to be calling every time.
#[inline]
Expand Down
Loading

0 comments on commit b27cb8e

Please sign in to comment.