wayland-rs icon indicating copy to clipboard operation
wayland-rs copied to clipboard

Why `wl_pointer::Event` is not `Copy` or `Clone`

Open Aetf opened this issue 3 years ago • 3 comments

I'm piping the event to a broadcast channel, it'd be really handy if the event implements Clone.

I checked the source code and didn't see anything preventing that. Am I missing something?

Aetf avatar Oct 19 '21 23:10 Aetf

I don't think there is anything strictly preventing the event/request enums from being Clone indeed, the only point that would require some care is for messages that contain a RawFd, as cloning them mindlessly may cause some unexpected bugs.

elinorbgr avatar Oct 27 '21 12:10 elinorbgr

Note that FromRawFd::from_raw_fd is already unsafe, so cloning the fd is likely "not unsafe".

That said, pointer events don't pass any file descriptors, you're probably thinking of keyboard events.

WhyNotHugo avatar Aug 28 '22 10:08 WhyNotHugo

That said, pointer events don't pass any file descriptors, you're probably thinking of keyboard events.

Well, I'm thinking about all events. As this code is auto-generated by wayland-scanner it's kind of an all-or-nothing situation, either all event enums are Clone, or none are.

elinorbgr avatar Aug 29 '22 08:08 elinorbgr

Wayland-rs now generates Event enums with OwnedFd instead of RawFd, so it's definitely not possible to derive clone in that case.

Wayland-scanner could add Clone only if all events could be cloned, but that would be a backwards compat issue if a new protocol version added an event with an fd.

But I don't think there's any reason you can't use something like Arc<wl_pointer::Event> and send that over a broadcast channel.

So this doesn't really seem viable or necessary. As far as I can tell.

ids1024 avatar Jan 16 '24 18:01 ids1024