Skip to content

Fix wayland window identifier#76

Merged
bilelmoussaoui merged 1 commit into
bilelmoussaoui:masterfrom
A6GibKm:wayland-handle
Jul 28, 2022
Merged

Fix wayland window identifier#76
bilelmoussaoui merged 1 commit into
bilelmoussaoui:masterfrom
A6GibKm:wayland-handle

Conversation

@A6GibKm
Copy link
Copy Markdown
Collaborator

@A6GibKm A6GibKm commented Jun 9, 2022

No description provided.

@A6GibKm A6GibKm force-pushed the wayland-handle branch 11 times, most recently from f3b6641 to 99fb5ba Compare June 9, 2022 16:10
Comment thread src/window_identifier/wayland.rs Outdated
Comment thread src/window_identifier/wayland.rs
let backend = unsafe {
wayland_backend::sys::client::Backend::from_foreign_display(display_ptr as *mut _)
};
let conn = wayland_client::Connection::from_backend(backend);
Copy link
Copy Markdown

@i509VCB i509VCB Jun 9, 2022

Choose a reason for hiding this comment

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

Do we need to keep the connection alive? It is dropped at the end of the scope.

Copy link
Copy Markdown
Collaborator Author

@A6GibKm A6GibKm Jun 9, 2022

Choose a reason for hiding this comment

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

I moved the code a bit so to use at most a single connection on each time we request a handle, but idk if we can reuse them...

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think we have much of an option to avoid this.

Plus the from_foreign_display will act as a guest backend, so all the handles will still belong to the same underlying display.

Comment thread src/window_identifier/wayland.rs Outdated
@A6GibKm A6GibKm force-pushed the wayland-handle branch 5 times, most recently from 48209c5 to 2c92ca5 Compare June 9, 2022 17:54
Comment thread src/window_identifier/wayland.rs
Comment thread Cargo.toml Outdated
Comment thread src/window_identifier/mod.rs
Comment thread src/window_identifier/wayland.rs Outdated
/// Both pointers have to be valid surface and display pointers. You must
/// ensure the `display_ptr` lives longer than the returned
/// `WindowIdentifier`.
pub async unsafe fn from_wayland_raw(
Copy link
Copy Markdown

@i509VCB i509VCB Jul 8, 2022

Choose a reason for hiding this comment

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

I'm actually considering whether this function is necessary. Supporting this function introduces a bunch of safety requirements and lifetime questions we need to ask about the connection. Removing this function would make ashpd less scary internally and only displace maybe 20-30 lines of code to the user.

I think what we can do is explain where the user would create the required types from the surface and display pointers (wayland-backend) and then explain what lifetime constraints apply to such handles WaylandWindowIdentifier has (must not outlive the connection).

This would also mean the client_system feature would not be needed as ashpd would not be responsible for that and would operate on wayland-backend common types or wayland-client types.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actually no we have to have this, RawWindowHandle forces our hand here

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Actually no we have to have this, RawWindowHandle forces our hand here

Yes :(

Comment on lines 26 to 29
pub struct WaylandWindowIdentifier {
exported: ZxdgExportedV2,
exported_v1: Option<ZxdgExportedV1>,
exported_v2: Option<ZxdgExportedV2>,
type_: WindowIdentifierType,
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we need a Drop implementation to destroy the inner exported handles?

Do note that destroying exported handles will revoke any imports performed on other clients and the handle string will become inert.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

So how it should be handled? Should we expose a method for the user to drop the handle?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

gtk3 and gtk4 appear to destroy their exported handles. So yes Drop should destroy the exported protocol object.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yes, I wanted to be consistent with gtk's behaviour. Although, the issue with gtk is it errors out when you try to re-export a handle for an already exported surface instead of returning the same handle. Which make the WindowIdentifier not very nice with gtk, that is why I made it a kind of reference counted from ashpd's side and only unexport when the last usage is dropped.

I am thinking of going directly through the wayland-rs crates in the future and avoid using gtk's provided methods.

Comment thread src/window_identifier/wayland.rs Outdated
pub struct WaylandWindowIdentifier {
exported: ZxdgExportedV2,
exported_v1: Option<ZxdgExportedV1>,
exported_v2: Option<ZxdgExportedV2>,
Copy link
Copy Markdown

@i509VCB i509VCB Jul 8, 2022

Choose a reason for hiding this comment

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

We could use an Inner enum where v1 and v2 are variants go make the implementation a bit more idomatic.

@A6GibKm A6GibKm force-pushed the wayland-handle branch 3 times, most recently from 2093487 to 0a1d367 Compare July 25, 2022 14:08
@bilelmoussaoui
Copy link
Copy Markdown
Owner

@i509VCB Do you think this one is ready to be merged for now? we can update later once a new stable release is out.

@A6GibKm A6GibKm force-pushed the wayland-handle branch 2 times, most recently from 46e80e4 to d0aaa90 Compare July 26, 2022 08:04
@A6GibKm A6GibKm changed the title WIP: Fix wayland window identifier Fix wayland window identifier Jul 26, 2022
Comment thread src/window_identifier/mod.rs Outdated
@bilelmoussaoui
Copy link
Copy Markdown
Owner

I will go ahead and land this in order to fix the CI, we can do further changes on another PR if needed.

@bilelmoussaoui bilelmoussaoui merged commit 1b7c4d8 into bilelmoussaoui:master Jul 28, 2022
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.

4 participants