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

Add file chooser on wl, x11 and gtk4 #606

Merged
merged 5 commits into from
Oct 19, 2023

Conversation

joantolo
Copy link
Contributor

@joantolo joantolo commented Oct 6, 2023

Use the file chooser provided from the desktop using the FileChooser interface of Portal.

The only way I could find to use XdpParent for wl and x11 was to add the parent-header.-private.h from libportal.
And then add an implementation as it is done for gtk.

On the wayland platform it was needed the addition of xdg-foreign interface which is needed by XdpParent. You can see the commits for a more detailed info.

I'm open to suggestions.

This fixes the file chooser part of #594.

@joantolo joantolo changed the title Add file chooser on wl, x11 and Add file chooser on wl, x11 and gtk4 Oct 6, 2023
@aperezdc aperezdc self-requested a review October 16, 2023 09:04
@aperezdc aperezdc self-assigned this Oct 16, 2023
@aperezdc aperezdc added the enhancement New feature or request label Oct 16, 2023
Copy link
Member

@aperezdc aperezdc left a comment

Choose a reason for hiding this comment

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

@joantolo Thanks for working on this! I actually like the approach of using libportal to “offload” the responsibility of providing a suitable file dialog out of Cog, good idea.

There are a couple of things I commented around, mainly:

  • Use g_autoptr(...) wherever possible.
  • Declare variables right before first use (C11/C++ style).
  • Make libportal suage optional.
  • Use the data/check-style script to check that your code following the coding style.

With the above ironed out, I would be super happy to have this PR merged.

Picking the parent-private.h header from libportal.h I think is fine because the header itself has a comment stating that the license is different for that source file, it is unmodified from the original, and does not result in machine code added to Cog—only the definitions from it are needed at compile time. IIUC this is allowed as “combined work” by the LGPL, but IANAL so if anyone has a clearer view on this comments are welcome.

platform/common/cog-file-chooser.c Outdated Show resolved Hide resolved
platform/common/cog-file-chooser.c Outdated Show resolved Hide resolved
platform/common/cog-file-chooser.c Outdated Show resolved Hide resolved
@@ -1,10 +1,12 @@
cogplatformcommon_dependencies = [
cogcore_dep,
dependency('epoxy'),
dependency('libportal'),
Copy link
Member

Choose a reason for hiding this comment

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

This adds a new depdendency unconditionally, and I am quite sure the ARM cross-build toolchains do not contain libportal (@psaavedra can confirm). I think it would be better to make the dependency optional, with a feature declared in meson_options.txt and the code built only if enabled. Then we can add the packages easily to the native CI builds once we updated them to use Ubuntu 22.04, because currently we are on 20.04 which does not have a libportal package.

Copy link
Contributor Author

@joantolo joantolo Oct 17, 2023

Choose a reason for hiding this comment

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

To use it I've set a config variable when libportal is found.

platform/gtk4/cog-platform-gtk4.c Show resolved Hide resolved
XdpPortal allows to communicate with all Portal interfaces.
In this case it is used the FileChooser portal to get a file chooser.
It is used when "run-file-chooser" signal from WebKitWebView is emitted.

It should get a XdpParent to keep the new dialog always on top of
cog.
On libportal-gtk4 there is a gtk4 implementation of XdpParent which allows
keeping the dialog always on top.
This is a copy of parent-private.h from libportal. And should be in sync
to allow the use of XdpParent functionality from libportal.

This is needed for the next commits to implement a different XdpParent,
for the moment one for wayland and another one for x11.
The XdpParent needs to know the "parent_window" string to keep the dialog on top.
On wayland this "parent_window" can be obtained using the xdg-foreign protocol.
This protocol is used on this XdpParent implementation.
First it must call export_toplevel method, and then register a callback to
receive a handle which is the "parent_window".

To store the required data for this XdpParent implementation it is used the
private "data" pointer property as a xdp_parent_wl_data.
XdpParent isn't responsible of freeing it, so that data is handled at
cog-platform-wl.
This adds a new implementation of XdpParent. To get the "parent_window"
is simpler, it's just the window_id which is the window property of xcb.
@joantolo
Copy link
Contributor Author

joantolo commented Oct 18, 2023

Should I modify the copy of xdp-parent-private.h to pass the check-style?

@aperezdc
Copy link
Member

Should I modify the copy of xdp-parent-private.h to pass the check-style?

I think it's not needed. Let me try to find a way of making the style checker ignore certain files; if not I can merge the PR manually.

Copy link
Member

@aperezdc aperezdc left a comment

Choose a reason for hiding this comment

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

Let's merge this, looks good. Thanks @joantolo!

I have posted #616 to easily mark paths to be ignored by the style checker, prompted by this PR 😄

@aperezdc aperezdc merged commit 71e9f61 into Igalia:master Oct 19, 2023
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants