Skip to content

Prototype a Dispatch2/GlobalDispatch2 trait to dispatch delegate macros to oblivion#2008

Merged
Drakulix merged 2 commits intoSmithay:masterfrom
ids1024:dispatch2
Apr 30, 2026
Merged

Prototype a Dispatch2/GlobalDispatch2 trait to dispatch delegate macros to oblivion#2008
Drakulix merged 2 commits intoSmithay:masterfrom
ids1024:dispatch2

Conversation

@ids1024
Copy link
Copy Markdown
Member

@ids1024 ids1024 commented Apr 24, 2026

Description

See Smithay/client-toolkit#519 for a bit more context.

At present, this replaces delegate_compositor! with a single generic delegate_dispatch2! macro. It should be possible to update all the dispatch implementations this way.

If there are no issues with this, since smithay is less strict about API breaks than wayland-rs, we could merge this in smithay (compositors mostly should just need to add delegate_dispatch2! and remove the other macro calls). Then the next wayland-rs version (Smithay/wayland-rs#900) can incorporate the updated version of the trait. At which point the macro is no longer necessary, and more type bounds can be remove as implied.

Checklist

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 24.31319% with 551 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.45%. Comparing base (e84a4ca) to head (1dc32a6).
⚠️ Report is 68 commits behind head on master.

Files with missing lines Patch % Lines
src/wayland/dmabuf/dispatch.rs 0.00% 32 Missing ⚠️
src/wayland/image_copy_capture/mod.rs 6.89% 27 Missing ⚠️
src/wayland/foreign_toplevel_list/mod.rs 0.00% 23 Missing ⚠️
src/wayland/input_method/input_method_handle.rs 0.00% 17 Missing ⚠️
src/wayland/pointer_constraints.rs 15.78% 16 Missing ⚠️
src/wayland/pointer_gestures.rs 0.00% 15 Missing ⚠️
src/wayland/text_input/text_input_handle.rs 0.00% 15 Missing ⚠️
src/wayland/xdg_foreign/handlers.rs 0.00% 15 Missing ⚠️
src/wayland/xdg_toplevel_icon.rs 0.00% 15 Missing ⚠️
src/wayland/shell/xdg/handlers/surface.rs 33.33% 14 Missing ⚠️
... and 66 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2008      +/-   ##
==========================================
- Coverage   18.73%   18.45%   -0.28%     
==========================================
  Files         182      183       +1     
  Lines       28934    29194     +260     
==========================================
- Hits         5421     5388      -33     
- Misses      23513    23806     +293     
Flag Coverage Δ
wlcs-buffer 16.06% <23.48%> (-0.26%) ⬇️
wlcs-core 15.62% <23.62%> (-0.36%) ⬇️
wlcs-output 6.94% <20.87%> (+0.04%) ⬆️
wlcs-pointer-input 17.35% <23.48%> (-0.38%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This makes the documentation more consistent with other protocols, and
means there's a test for the protocol that doesn't otherwise exists
since `anvil` doesn't use it.
@ids1024 ids1024 force-pushed the dispatch2 branch 3 times, most recently from 8e67f07 to 1dc32a6 Compare April 29, 2026 18:50
@ids1024
Copy link
Copy Markdown
Member Author

ids1024 commented Apr 29, 2026

CI passes, this works with cosmic-comp, and #2017 shows it also works with an updated wayland-rs providing these versions of the trait (which allows removing more extra trait bounds).

So I think this should be good to merge.

@ids1024 ids1024 changed the title [WIP] Prototype a Dispatch2/GlobalDispatch2 trait to dispatch delegate macros to oblivion Prototype a Dispatch2/GlobalDispatch2 trait to dispatch delegate macros to oblivion Apr 29, 2026
@ids1024 ids1024 marked this pull request as ready for review April 29, 2026 22:19
Copy link
Copy Markdown
Member

@Drakulix Drakulix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. I'd say we shouldn't let this bit-rot as it is an improvement all around. But this needs a CHANGELOG entry, no? 😅

A single `delegate_dispatch2!` replaces all other delegate macros.

When wayland-rs updates the definition of `Dispatch`, this macro will be
unnecessary, and `Dispatch` type bounds should become inferable by the
type system.

`Dispatch` is now implemented for the user-data type, so `smithay` is
able to provide blanket implementations as long as the user data is a
type owned by `smithay`. Therefore, `GlobalData` replaces `()` as a user
data (`smithay-client-toolkit` already did this), and udata that is
simply a type like `Weak<WlSurface>` is wrapped.
@ids1024
Copy link
Copy Markdown
Member Author

ids1024 commented Apr 30, 2026

Amended with a line in the changelog.

This is pretty easy to adapt to, though when wayland-rs releases that will be more involved. May want to revive https://github.com/Smithay/smithay.github.io with an announcement of the new release.

@Drakulix Drakulix merged commit 0d14cd6 into Smithay:master Apr 30, 2026
14 checks passed
ids1024 added a commit to ids1024/smithay that referenced this pull request Apr 30, 2026
Based on Smithay#2008.

Beyond what that PR does, this also allows the availablility of
`Dispatch` implementations to be inferred usually by just the `*Handler`
trait for the protocol. Though it looks like Rust still can't infer
bounds like `<D as SeatHandler>::KeyboardFocus: WaylandFocus` from
placing them on the trait (*eventually* it should?).

Uses Smithay/wayland-rs#902.
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.

3 participants