Skip to content

feat: data device handling - #301

Merged
wash2 merged 13 commits into
Smithay:masterfrom
wash2:data_device
Mar 27, 2023
Merged

wash2 merged 13 commits into
Smithay:masterfrom
wash2:data_device

Conversation

@wash2

@wash2 wash2 commented Oct 4, 2022

Copy link
Copy Markdown
Member

This PR adds data device handling and an example demonstrating its use.
I've also copied over the ReadPipe implementation 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.

Comment thread src/data_device/mod.rs Resolved
Comment thread src/data_device/data_source.rs Resolved
Comment thread src/data_device/data_source.rs Resolved
Comment thread src/data_device/data_source.rs Outdated
state.send(conn, qh, source, mime_type, fd);
}
wl_data_source::Event::Cancelled => {
source.destroy();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is destroying the surface an issue here? A user may instantiate extensions over the data device and needs to destroy it themselves?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread src/data_device/data_source.rs Resolved
Comment thread src/data_device/mod.rs Resolved
Comment thread src/data_device/mod.rs Resolved
Comment thread src/data_device/mod.rs Resolved
Comment thread src/data_device/data_source.rs Resolved
Comment thread src/data_device/mod.rs Resolved
@i509VCB i509VCB added this to the sctk 0.30 milestone Oct 6, 2022
Comment thread Cargo.toml Resolved
Comment thread src/data_device_manager/data_device.rs Outdated
Comment on lines +50 to +116
/// 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())
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These two functions are override-able to handle dnd and selection offers that an extension may use I assume

Comment thread src/data_device_manager/data_device.rs Outdated
);

/// The data device pointer has entered a surface at the provided location
#[allow(clippy::too_many_arguments)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this lint dead?

Comment thread src/data_device_manager/data_device.rs Resolved
Comment thread src/data_device_manager/data_source.rs Outdated
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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not too sure what this is supposed to do from the documentation here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread src/data_device_manager/mod.rs Outdated
source.offer(mime.to_string());
}
if let Some(dnd_actions) = dnd_actions {
source.set_actions(dnd_actions);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@ids1024

ids1024 commented Jan 18, 2023

Copy link
Copy Markdown
Member

wl_data_offer::finish was also added in version 3. I guess currently that's not called in the library code but is used directly in the example. Perhaps the library should offer some API that calls that if supported? (However that would work.)

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.

@wash2
wash2 force-pushed the data_device branch 2 times, most recently from 99c9b8e to aa64347 Compare January 19, 2023 00:09
@wash2

wash2 commented Jan 19, 2023

Copy link
Copy Markdown
Member Author

wl_data_offer::finish was also added in version 3. I guess currently that's not called in the library code but is used directly in the example. Perhaps the library should offer some API that calls that if supported? (However that would work.)

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.

Ok, I will work on some API improvements

@wash2
wash2 marked this pull request as draft January 19, 2023 04:45
@wash2
wash2 force-pushed the data_device branch 2 times, most recently from 267523b to e976b89 Compare January 21, 2023 02:24
@wash2
wash2 marked this pull request as ready for review January 21, 2023 04:50
@i509VCB
i509VCB self-requested a review January 21, 2023 04:56
Comment thread src/data_device_manager/data_offer.rs Outdated
DataDeviceOffer::Drag(o) => {
*inner = DataDeviceOffer::Selection(SelectionOffer {
data_offer: o.data_offer.take(),
mime_types: o.mime_types.drain(..).collect(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@i509VCB i509VCB left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't have much more that I can find needing any changes.

Comment thread src/data_device_manager/data_device.rs Outdated
Comment on lines +130 to +138
/// 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,
// );

@i509VCB i509VCB Mar 27, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mentioning the other traits here for maintainers would probably be fine.

Comment thread src/data_device_manager/data_device.rs Outdated
Comment on lines +130 to +131
/// Introduces a new data offer
/// ASHLEY left out because the data offer will be introduced to the user once the type is known

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These are doc comments and actually apply to DataDeviceHandler::entered

@wash2
wash2 merged commit 31b7df5 into Smithay:master Mar 27, 2023
@wash2
wash2 deleted the data_device branch March 27, 2023 16:03
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