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

Take two on delegate macros #1279

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[workspace]
members = [
"smithay-drm-extras",
"smithay-macros",
"smallvil",
"anvil",
"wlcs_anvil"
Expand Down Expand Up @@ -69,6 +70,7 @@ profiling = "1.0"
smallvec = "1.11"
pixman = { version = "0.1.0", features = ["drm-fourcc"], optional = true }

smithay-macros = { path = "./smithay-macros" }

[dev-dependencies]
clap = { version = "4", features = ["derive"] }
Expand Down
48 changes: 24 additions & 24 deletions anvil/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub struct AnvilState<BackendData: Backend + 'static> {
pub show_window_preview: bool,
}

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

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

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

impl<BackendData: Backend> SelectionHandler for AnvilState<BackendData> {
type SelectionUserData = ();
Expand Down Expand Up @@ -227,22 +227,22 @@ impl<BackendData: Backend> PrimarySelectionHandler for AnvilState<BackendData> {
&self.primary_selection_state
}
}
delegate_primary_selection!(@<BackendData: Backend + 'static> AnvilState<BackendData>);
delegate_primary_selection!(impl<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>);
delegate_data_control!(impl<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>);
delegate_shm!(impl<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend> SeatHandler for AnvilState<BackendData> {
type KeyboardFocus = FocusTarget;
Expand All @@ -265,11 +265,11 @@ impl<BackendData: Backend> SeatHandler for AnvilState<BackendData> {
*self.cursor_status.lock().unwrap() = image;
}
}
delegate_seat!(@<BackendData: Backend + 'static> AnvilState<BackendData>);
delegate_seat!(impl<BackendData: Backend + 'static> AnvilState<BackendData>);

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

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

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

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

impl<BackendData: Backend> KeyboardShortcutsInhibitHandler for AnvilState<BackendData> {
fn keyboard_shortcuts_inhibit_state(&mut self) -> &mut KeyboardShortcutsInhibitState {
Expand All @@ -305,13 +305,13 @@ impl<BackendData: Backend> KeyboardShortcutsInhibitHandler for AnvilState<Backen
}
}

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

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

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

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

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

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

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

impl<BackendData: Backend> XdgDecorationHandler for AnvilState<BackendData> {
fn new_decoration(&mut self, toplevel: ToplevelSurface) {
Expand Down Expand Up @@ -416,11 +416,11 @@ impl<BackendData: Backend> XdgDecorationHandler for AnvilState<BackendData> {
}
}
}
delegate_xdg_decoration!(@<BackendData: Backend + 'static> AnvilState<BackendData>);
delegate_xdg_decoration!(impl<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>);
delegate_xdg_shell!(impl<BackendData: Backend + 'static> AnvilState<BackendData>);
delegate_layer_shell!(impl<BackendData: Backend + 'static> AnvilState<BackendData>);
delegate_presentation!(impl<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend> FractionalScaleHandler for AnvilState<BackendData> {
fn new_fractional_scale(
Expand Down Expand Up @@ -469,7 +469,7 @@ impl<BackendData: Backend> FractionalScaleHandler for AnvilState<BackendData> {
});
}
}
delegate_fractional_scale!(@<BackendData: Backend + 'static> AnvilState<BackendData>);
delegate_fractional_scale!(impl<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 @@ -489,7 +489,7 @@ impl<BackendData: Backend + 'static> SecurityContextHandler for AnvilState<Backe
.expect("Failed to init wayland socket source");
}
}
delegate_security_context!(@<BackendData: Backend + 'static> AnvilState<BackendData>);
delegate_security_context!(impl<BackendData: Backend + 'static> AnvilState<BackendData>);

#[cfg(feature = "xwayland")]
impl<BackendData: Backend + 'static> XWaylandKeyboardGrabHandler for AnvilState<BackendData> {
Expand All @@ -502,7 +502,7 @@ impl<BackendData: Backend + 'static> XWaylandKeyboardGrabHandler for AnvilState<
}
}
#[cfg(feature = "xwayland")]
delegate_xwayland_keyboard_grab!(@<BackendData: Backend + 'static> AnvilState<BackendData>);
delegate_xwayland_keyboard_grab!(impl<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend + 'static> AnvilState<BackendData> {
pub fn init(
Expand Down
20 changes: 20 additions & 0 deletions smithay-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "smithay-macros"
version = "0.1.0"
edition = "2021"
license = "MIT"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = "1"
quote = "1"

[dependencies.syn]
version = "2"
default-features = false
features = ["parsing", "full", "proc-macro", "printing"]

[dev-dependencies]
smithay = { path = "../" }
49 changes: 49 additions & 0 deletions smithay-macros/examples/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use ::smithay::wayland::{buffer::BufferHandler, shm::ShmHandler};

trait MarkerTrait {}

struct State<T: MarkerTrait> {
_d: T,
}

impl<T: MarkerTrait> BufferHandler for State<T> {
fn buffer_destroyed(
&mut self,
_buffer: &smithay::reexports::wayland_server::protocol::wl_buffer::WlBuffer,
) {
todo!()
}
}

impl<T: MarkerTrait> ShmHandler for State<T> {
fn shm_state(&self) -> &smithay::wayland::shm::ShmState {
todo!()
}
}

smithay_macros::delegate_bundle!(
impl<T: MarkerTrait + 'static> State<T> {},
Bundle {
dispatch_to: smithay::wayland::shm::ShmState,
globals: [Global {
interface: smithay::reexports::wayland_server::protocol::wl_shm::WlShm,
data: (),
}],
resources: [
Resource {
interface: smithay::reexports::wayland_server::protocol::wl_shm::WlShm,
data: (),
},
Resource {
interface: smithay::reexports::wayland_server::protocol::wl_shm_pool::WlShmPool,
data: smithay::wayland::shm::ShmPoolUserData,
},
Resource {
interface: smithay::reexports::wayland_server::protocol::wl_buffer::WlBuffer,
data: smithay::wayland::shm::ShmBufferUserData,
},
],
},
);

fn main() {}
Loading
Loading