-
Notifications
You must be signed in to change notification settings - Fork 124
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
Delegated dispatchers #699
base: master
Are you sure you want to change the base?
Conversation
2d534c1
to
e0119b4
Compare
2348276
to
3b02108
Compare
This is a nice take on this problem! Thanks a lot, the general principle looks good to me 👍 Given this alters the generated code in a non-backward-compatible way, this will be a breaking change of wayland-scanner, and I think we should probably treat it as a breaking change of wayland-server as well as remove the cumbersome macros in the process. Apart from waiting on the resolution of #698 for our CI to be functional again, I think before this is in a mergeable state it needs:
|
For an implementation in https://docs.rs/wayland-client/latest/wayland_client/protocol/wl_seat/struct.WlSeat.html#method.get_keyboard for instance is defined as: pub fn get_keyboard<U: Send + Sync + 'static, D: Dispatch<WlKeyboard, U> + 'static>(
&self,
qh: &QueueHandle<D>,
udata: U
) -> WlKeyboard Without the delegated implementation the macro generated, Events with a |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #699 +/- ##
==========================================
- Coverage 75.34% 74.11% -1.23%
==========================================
Files 48 45 -3
Lines 8257 7969 -288
==========================================
- Hits 6221 5906 -315
- Misses 2036 2063 +27
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
31cae98
to
38c1c2b
Compare
Ok, client side is done. Code generated by the scanner will just output: fn get_registry(qh) -> WlRegistry {
let data = qh.make_data::<_, _, D>();
...
} So nothing will change for the general case of global We as SCTK on the other hand can call the constructor manually with our let data = qh.make_data::<WlRegistry, _, DelegateTo>(());
let wl_registry = display.send_constructor(wl_display::Request::GetRegistry {}, data).unwrap(); I belive that the code needed to call constructors manually is simple enough to no warrant an additional Also it turns out that thanks to ObjectData::data_as_any on client side the generic on |
Yeah, we wouldn't really want to end up with a duplicated The only other possibility I can think of is if |
I gave up, the Btw, Docs should be up-to-date now as well. So I guess this could be considered ready. |
Gentle ping @elinorbgr, no rush tho. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, a few documentation nitpicks and two last points:
- Please add changelog entries for these changes to the relevant crates (wayland-client, wayland-server and wayland-scanner)
- The two new examples could really use a few comments that explain what they do, what the flow of messages will be, etc...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we also removing the delegate_dispatch macros in the process? Or do you think there is a good reason to keep them alongside this new API?
Nope, removed. |
In wayland-client, |
Seems to work with something like: pub fn bind_delegated<I, State, U, DelegateTo>(
&self,
qh: &QueueHandle<State>,
version: RangeInclusive<u32>,
udata: U,
) -> Result<I, BindError>
where
I: Proxy + 'static,
State: 'static,
U: Send + Sync + 'static,
DelegateTo: Dispatch<I, U, State> + 'static,
{
...
Ok(self
.registry
.send_constructor(
wl_registry::Request::Bind { name, id: (I::interface(), version) },
qh.make_data::<I, U, DelegateTo>(udata),
)
.unwrap()) Then pub fn bind<I, State, U>(
&self,
qh: &QueueHandle<State>,
version: RangeInclusive<u32>,
udata: U,
) -> Result<I, BindError>
where
I: Proxy + 'static,
State: Dispatch<I, U> + 'static,
U: Send + Sync + 'static,
{
self.bind_delegated::<I, State, U, State>(qh, version, udata)
} |
|
94a6ccf
to
2557d58
Compare
2557d58
to
508cf99
Compare
This is an attempt to remove all delegate macros from Smithay, as well as remove obnoxious type constraints on
D
.Here is an example diff of
ZxdgOutputManagerV1
implementation in Smithay with new delegated dispatches.All of the constraints on
D
can be removed, asOutputManagerState
is the one implementing them.This also completely removes the need to write and invoke
delegate_*!
macros.I managed to implement delegated
GlobalData
without any breaking changes just by adding new default generic, but forResourceData
it's more cumbersome, as I had to add newDelegatedResourceData
user data type. While this does not introduce any braking changes, the split is weird. As we now have.data::<U>()
and.delegated_data::<U, DelegatedTo>()
variants. Ideas on how to merge those types together without polluting the whole API are welcome.(Smithay PR that demonstrates this in action Smithay/smithay#1327)