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

delegate macros as attributes #424

Open
l4l opened this issue Oct 29, 2023 · 4 comments
Open

delegate macros as attributes #424

l4l opened this issue Oct 29, 2023 · 4 comments

Comments

@l4l
Copy link

l4l commented Oct 29, 2023

For now for implementing a certain feature, one need to implement trait, then call a delegate_<feat>! on the structure which seems a little bit redundant, so instead of this:

impl<T: Xyz + 'static> ShmHandler for SimpleWindow<T> {
    fn shm_state(&mut self) -> &mut Shm {
        &mut self.shm
    }
}

delegate_shm!(@<T: Xyz + 'static> SimpleWindow<T>);

it would be nice to have this instead:

#[sctk::delegate]
impl<T: Xyz + 'static> ShmHandler for SimpleWindow<T> {
    fn shm_state(&mut self) -> &mut Shm {
        &mut self.shm
    }
}
@wash2
Copy link
Member

wash2 commented Oct 30, 2023

While this would be nice, currently the Handler traits don't always map 1:1 to delegate_<feat>! macros. Maybe things could be refactored a bit to make this work though. Also, how it's currently done matches the smithay crate.

@l4l
Copy link
Author

l4l commented Oct 30, 2023

currently the Handler traits don't always map 1:1 to delegate_! macros

You mean using supertraits for delegate macros bound? I didn't find any relative example, perhaps you have any related code to share?

@wash2
Copy link
Member

wash2 commented Oct 30, 2023

https://github.com/Smithay/client-toolkit/blob/master/examples/data_device.rs has an example of what I mean. PrimarySelectionDeviceHandler and PrimarySelectionSourceHandler both need to be implemented and used with delegate_primary_selection. Data device is similar. I guess I mean, #[sctk::delegate] would be used with just one of the trait implementations in these cases?

@l4l
Copy link
Author

l4l commented Oct 30, 2023

Oh, I see what you mean. Perhaps this could be solved with an additional trait specifically for delegation? E.g given the following defintions:

trait PrimarySelection {
  fn selection(..);
  fn send_request(..);
  fn cancelled(..);
}

impl<T: PrimarySelection> PrimarySelectionDeviceHandler for T {
  fn selection(self, args) { PrimarySelection::selection(self, args) }
}

impl<T: PrimarySelection> PrimarySelectionSourceHandler for T {
  fn send_request(self, args) { PrimarySelection::send_request(self, args) }
  fn cancelled(self, args) { PrimarySelection::cancelled(self, args) }
}

Then in user code impl only PrimarySelection:

#[sctk::delegate]
impl PrimarySelection for MySelection {
 ...
}

I'm not sure yet about this being breaking change though. That might be a problem

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

No branches or pull requests

2 participants