Repository navigation
feat: data device handling - #301
Conversation
| state.send(conn, qh, source, mime_type, fd); | ||
| } | ||
| wl_data_source::Event::Cancelled => { | ||
| source.destroy(); |
There was a problem hiding this comment.
Is destroying the surface an issue here? A user may instantiate extensions over the data device and needs to destroy it themselves?
There was a problem hiding this comment.
I don't think I understand what you mean. Do you mean destroying the source? I don't think there is any other necessary cleanup other than the data source, if that is what you mean.
| /// get the active dnd offer if it exists | ||
| fn dnd_offer(&self) -> Option<DndDataOffer> { | ||
| self.data_device_data().inner.lock().ok().and_then(|inner| inner.dnd_data_offer.clone()) | ||
| } | ||
|
|
||
| /// get the active selection offer if it exists | ||
| fn selection_offer(&self) -> Option<WlDataOffer> { | ||
| self.data_device_data().inner.lock().ok().and_then(|inner| inner.selection.clone()) | ||
| } |
There was a problem hiding this comment.
These two functions are override-able to handle dnd and selection offers that an extension may use I assume
| ); | ||
|
|
||
| /// The data device pointer has entered a surface at the provided location | ||
| #[allow(clippy::too_many_arguments)] |
| impl CopyPasteSource { | ||
| /// set the selection | ||
| /// internally tracks the serial for when unset selection may be called | ||
| pub fn set_selection(&self, device: &WlDataDevice, serial: u32) { |
There was a problem hiding this comment.
I am not too sure what this is supposed to do from the documentation here.
There was a problem hiding this comment.
This method is really just a wrapper that calls set_selection. After looking at it again, I think it shouldn't hold onto the serial so I removed that part and adjusted the docs.
| source.offer(mime.to_string()); | ||
| } | ||
| if let Some(dnd_actions) = dnd_actions { | ||
| source.set_actions(dnd_actions); |
There was a problem hiding this comment.
Apparently set_actions() was added in version 3 of the protocol, while this code is binding version 1..=3. So presumably this could result in a protocol error on a compositor implementing version 1 or 2.
|
I would be good if sctk could smooth out any differences between versions of this protocol and just have a high level API that won't break on an old protocol version, and guarantees you won't call a method that's only valid for drag-and-drop with a copy-paste source. |
99c9b8e to
aa64347
Compare
Ok, I will work on some API improvements |
267523b to
e976b89
Compare
| DataDeviceOffer::Drag(o) => { | ||
| *inner = DataDeviceOffer::Selection(SelectionOffer { | ||
| data_offer: o.data_offer.take(), | ||
| mime_types: o.mime_types.drain(..).collect(), |
There was a problem hiding this comment.
You can use std::mem::take() to replace the vec with an empty vec. Which should just move the pointer instead of creating a new allocation.
The pattern is a bit awkward to deal with in Rust, but perhaps it would be better to use inner: Arc<Mutex<Option<DataDeviceInner>>>? So you just .take() the inner value, and then consume the whole DataDeviceOffer.
05e7420 to
b5b4482
Compare
…er prints in example
i509VCB
left a comment
There was a problem hiding this comment.
I don't have much more that I can find needing any changes.
| /// Introduces a new data offer | ||
| /// ASHLEY left out because the data offer will be introduced to the user once the type is known | ||
| // fn data_offer( | ||
| // &mut self, | ||
| // conn: &Connection, | ||
| // qh: &QueueHandle<Self>, | ||
| // data_device: DataDevice, | ||
| // offer: WlDataOffer, | ||
| // ); |
There was a problem hiding this comment.
Mentioning the other traits here for maintainers would probably be fine.
| /// Introduces a new data offer | ||
| /// ASHLEY left out because the data offer will be introduced to the user once the type is known |
There was a problem hiding this comment.
These are doc comments and actually apply to DataDeviceHandler::entered
This PR adds data device handling and an example demonstrating its use.
I've also copied over the
ReadPipeimplementation from the previous version of sctk, because it seems useful.I haven't added very many abstractions, aside from the data sources, one for copy paste & another for drag and drop, to encourage that they are used correctly.
The example will read from the selection whenever it changes and can accept DnD.
If the user presses left click, it will start a DnD.
If the user presses "c" it will set the selection for copy paste.