Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC Begone delegate macros #1327

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ profiling = "1.0"
smallvec = "1.11"
pixman = { version = "0.1.0", features = ["drm-fourcc"], optional = true }

[patch.crates-io]
wayland-egl = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2"}
wayland-protocols = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" }
wayland-protocols-wlr = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" }
wayland-protocols-misc = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" }
wayland-server = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" }
wayland-client = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" }
wayland-sys = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" }
wayland-backend = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" }
wayland-scanner = { git = "https://github.com/PolyMeilex/wayland-rs.git", branch = "new-delegate-v2" }
# wayland-egl = { path = "../wayland-rs/wayland-egl/" }
# wayland-protocols = { path = "../wayland-rs/wayland-protocols/" }
# wayland-protocols-wlr = { path = "../wayland-rs/wayland-protocols-wlr/" }
# wayland-protocols-misc = { path = "../wayland-rs/wayland-protocols-misc/" }
# wayland-server = { path = "../wayland-rs/wayland-server/" }
# wayland-client = { path = "../wayland-rs/wayland-client/" }
# wayland-sys = { path = "../wayland-rs/wayland-sys/" }
# wayland-backend = { path = "../wayland-rs/wayland-backend/" }
# wayland-scanner = { path = "../wayland-rs/wayland-scanner/" }


[dev-dependencies]
clap = { version = "4", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ gl_generator = "0.14"

[features]
debug = ["fps_ticker", "image/png", "renderdoc"]
default = ["egl", "winit", "x11", "udev", "xwayland"]
default = ["egl", "x11", "udev", "xwayland"]
egl = ["smithay/use_system_lib", "smithay/backend_egl"]
test_all_features = ["default", "debug"]
udev = [
Expand Down
44 changes: 0 additions & 44 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 @@ -96,7 +90,6 @@ use crate::{
};
#[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 @@ -173,8 +166,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 @@ -194,10 +185,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 @@ -233,22 +222,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 = KeyboardFocusTarget;
Expand Down Expand Up @@ -276,11 +261,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 @@ -303,8 +283,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 @@ -316,14 +294,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 @@ -334,9 +304,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 @@ -375,7 +342,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 @@ -427,11 +393,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 @@ -480,7 +441,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 @@ -500,7 +460,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 @@ -512,15 +471,12 @@ impl<BackendData: Backend + 'static> XWaylandKeyboardGrabHandler for AnvilState<
Some(KeyboardFocusTarget::Window(elem.0.clone()))
}
}
#[cfg(feature = "xwayland")]
delegate_xwayland_keyboard_grab!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend> XdgForeignHandler for AnvilState<BackendData> {
fn xdg_foreign_state(&mut self) -> &mut XdgForeignState {
&mut self.xdg_foreign_state
}
}
smithay::delegate_xdg_foreign!(@<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 @@ -50,7 +50,6 @@ use smithay::{
udev::{all_gpus, primary_gpu, UdevBackend, UdevEvent},
SwapBuffersError,
},
delegate_dmabuf, delegate_drm_lease,
desktop::{
space::{Space, SurfaceTree},
utils::OutputPresentationFeedback,
Expand Down Expand Up @@ -175,7 +174,6 @@ impl DmabufHandler for AnvilState<UdevData> {
}
}
}
delegate_dmabuf!(AnvilState<UdevData>);

impl Backend for UdevData {
const HAS_RELATIVE_MOTION: bool = true;
Expand Down Expand Up @@ -560,8 +558,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 @@ -289,10 +288,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 @@ -84,5 +83,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 @@ -56,6 +55,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 @@ -35,8 +34,6 @@ impl SeatHandler for Smallvil {
}
}

delegate_seat!(Smallvil);

//
// Wl Data Device
//
Expand All @@ -54,11 +51,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 @@ -142,7 +142,7 @@ pub mod pointer;
pub mod touch;

/// 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 @@ -307,7 +307,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
Loading