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

Conversation

PolyMeilex
Copy link
Member

So... I was not happy with #1090, it was a bit hacky and required the macro crate to depend on smithay just for module definitions.

So this is take two:
The proc macro allows us to delegate so-called bundles like so:

struct State<T> {
    my: usize,
    state: usize,
    generic: T,
}

smithay_macros::delegate_bundle!(
    impl<T> 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: (),
            },
        ],
    },
);

The macro is intentionaly built from valid rust syntax, and therefore this piece of code is fully rustfmt compatible.

Tho, one can opt out of rustfmt compatibility by dropping some optional pieces of syntax for example all of those are valid:

  • impl<T> State<T> {}
  • impl<T> State<T>
  • State (only if your state is not generic)

So, now that we have a nice bundle macro, Smithay can just wrap it like so:

macro_rules! delegate_shm {
    ($($params:tt)*) => {
        $crate::reexports::smithay_macros::delegate_bundle!(
            $($params)*,
            Bundle {
                dispatch_to: $crate::wayland::shm::ShmState,
                globals: [
                    Global {
                        interface: $crate::reexports::wayland_server::protocol::wl_shm::WlShm,
                        data: (),
                    }
                ],
                resources: [
                    Resource {
                        interface: $crate::reexports::wayland_server::protocol::wl_shm::WlShm,
                        data: (),
                    },
                ],
            },
        );
    };
}

And end user can use it more or less like the old macro:

// Non generic case
delegate_shm!(State);

// Generic case
delegate_shm!(impl<T> State<T>);

Future

Derive macro could call those macros with proper generics automatically, it could look like this:

#[derive(AutoDelegate)]
#[delegate(
    smithay::delegate_compositor,
    smithay::delegate_output,
    smithay::delegate_shm,
)]
struct Anvil<T: Backend> {
    backend: T,
}

// Any delegates that can't be done automatically:
delegate_dmabuf!(AnvilState<UdevData>);

@codecov-commenter
Copy link

codecov-commenter commented Jan 13, 2024

Codecov Report

Attention: 106 lines in your changes are missing coverage. Please review.

Comparison is base (77686d7) 21.56% compared to head (e5ff361) 23.72%.
Report is 1 commits behind head on master.

Files Patch % Lines
src/wayland/pointer_gestures.rs 0.00% 30 Missing ⚠️
src/wayland/relative_pointer.rs 0.00% 22 Missing ⚠️
src/wayland/presentation/mod.rs 58.06% 13 Missing ⚠️
src/wayland/viewporter/mod.rs 58.06% 13 Missing ⚠️
smithay-macros/src/bundle.rs 89.71% 11 Missing ⚠️
src/backend/egl/display.rs 0.00% 9 Missing ⚠️
smithay-macros/src/item_impl.rs 69.23% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1279      +/-   ##
==========================================
+ Coverage   21.56%   23.72%   +2.15%     
==========================================
  Files         155      159       +4     
  Lines       24792    25898    +1106     
==========================================
+ Hits         5347     6144     +797     
- Misses      19445    19754     +309     
Flag Coverage Δ
wlcs-buffer 20.91% <88.08%> (+2.28%) ⬆️
wlcs-core 20.59% <88.08%> (+2.29%) ⬆️
wlcs-output 10.34% <88.08%> (+2.70%) ⬆️
wlcs-pointer-input 22.57% <88.08%> (+2.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@PolyMeilex
Copy link
Member Author

PolyMeilex commented Feb 11, 2024

I don't want to jinx it, but I found a way to get rid of those macros altogether, with minimal changes to wayland-rs so this might not be needed at all 🤞

(no I'm not working on wayland-rs 0.40 kind of situation 😆, this should be doable without braking changes)

#1327

@PolyMeilex PolyMeilex closed this Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants