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
feat: Use GtkFileChooserNative to support the XDG Desktop Portal specification #19159
Conversation
We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix. Examples of commit messages with semantic prefixes:
Things that will help get your PR across the finish line:
We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can. |
I would appreciate guidance in getting this PR to completion with regard to CI builds, styling, implementation, and testing. Off the bat, there are a few issues with this PR:
I am going to take a look at the Chromium source code, and see what I find. |
Please note that this was not on my dev machine, so I could not compile to check my work. |
Lint should be fixed. Apologies. |
@TingPing @ckerr since you guys were a part of the last PR, can you provide assistance on this one? @TingPing specifically if you see anything that can be done about casting a |
Thanks a lot for picking this up!
Hardcoding Since this already depends on GLib I suggest using GModule which avoids the linking and header portability concerns. You'd then use |
Thanks for the link @TingPing. I will take a look at |
Call for action: I do not currently run a KDE Plasma desktop. If someone who does could inevitably test this PR, that would be great. |
@TingPing I was more wondering if the |
8fcc326
to
4d36308
Compare
This is going to require a little more effort than previously thought. Still doable I think, but I am under the impression |
The behavior of Both I am going to need some guidance on Any skilled Electron contributor would be a huge help at this point. |
72a53d3
to
6dd34aa
Compare
I have also learned that preview widgets are ignored in the Native API. What should be the best course of action regarding that? Leaving the preview widget code in regardless of what dialog is actually being used seems best to me instead of making conditional checks around the code. |
baf26ce
to
a36ba29
Compare
I have gotten the build where it only fails on the So...I think this leaves a couple of options. Ask the Chromium developers for an overloaded function to be added, or mirror the function in Electron. I am thinking mirroring the function in Electron will work best. |
I have come up with the following patch diff --git a/shell/browser/ui/file_dialog_gtk.cc b/shell/browser/ui/file_dialog_gtk.cc
index ef6d3a545..50e536ad5 100644
--- a/shell/browser/ui/file_dialog_gtk.cc
+++ b/shell/browser/ui/file_dialog_gtk.cc
@@ -77,7 +77,10 @@ class FileChooserDialog {
if (parent_) {
parent_->SetEnabled(false);
- libgtkui::SetGtkTransientForAura(dialog_, parent_->GetNativeWindow());
+ if (GTK_IS_WIDGET(dialog_))
+ libgtkui::SetGtkTransientForAura(dialog_, parent_->GetNativeWindow());
+ else
+ SetGtkTransientForAura(parent_->GetNativeWindow());
if (GTK_IS_WINDOW(dialog_)) {
gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE);
} else {
@@ -225,6 +228,19 @@ class FileChooserDialog {
CHROMEG_CALLBACK_0(FileChooserDialog, void, OnUpdatePreview, GtkFileChooser*);
DISALLOW_COPY_AND_ASSIGN(FileChooserDialog);
+
+ // Sets |dialog| as transient for |parent|, which will keep it on top and
+ // center it above |parent|. Do nothing if |parent| is nullptr.
+ void SetGtkTransientForAura(aura::Window* parent) {
+ if (!parent || !parent->GetHost())
+ return;
+
+ void (*dl_gtk_native_dialog_set_transient_for)(void*, GtkWindow*) = nullptr;
+ g_module_symbol(
+ gtk_module_, "gtk_native_dialog_set_transient_for",
+ reinterpret_cast<void**>(&dl_gtk_native_dialog_set_transient_for);
+ dl_gtk_native_dialog_set_transient_for(dialog_, reinterpret_cast<GtkWindow*>(parent));
+ }
};
void FileChooserDialog::OnFileDialogResponse(GtkFileChooser* widget, int response) { I have decided to merge this patch for the time being. It can be reverted though. |
c735f82
to
fb7b5ac
Compare
Thank you to everyone who has worked on this. It will be much appreciated by KDE users. |
…ification (electron#19159) * feat: Use GtkFileChooserNative if available to support XDG portals With this commit, users on KDE/plasma will finally have support in Electron for their native file choosers dialogs. * fix: namespace * fix: labels were reversed * fix: lint issue * fix: clean up some implementation * fix: remove deprecation branch * fix: remove unused header * fix: remove unused gi18n.h include Not sure why this is * fix: add the set_data call into the mirrored SetGtkTransientForAura func * fix: remove gmodule support and use native for the dialog regardless * fix: undo yarn.lock changes * fix: lint * fix: remove x11 unncessary x11 include * fix: lint * fix: remove SetGtkTransientForAura * Revert "fix: remove gmodule support and use native for the dialog regardless" This reverts commit 062db59. * fix: add support in a backwards compatible way Use GModule to dynamically load functions from libgtk in order to support GtkNativeDialog. * fix: lint * docs: update comment * Revert "fix: remove x11 unncessary x11 include" This reverts commit 589cff5. * fix: compiler errors * fix: int -> x11::time * fix: move GtkNativeDialog static data to global state * fix: revert yarn.lock change * update: for code review comments * fix: remove functional header * fix: variable name * fix: rename GTK native initalization func * Help out the compiler * Help out the compiler * Help out the compiler * Fix function signature * Remove unused header * Rename optional boolean for GtkFileChooserNative support * Add back in USE_X11 check * Satisfy linter * Resatisfy linter * Fix alignment of if * Fix alignment of arguments * linting... * fix: add back in the i18n hack * fix: lint * Respond to some review comments * fix: lint * Make adding filter agnostic * fix: transform is in place * fix: remove std::transform because not c++17 * Remove unused include * fix: address Cheng's review * fix: Remove unused header
`GtkFileChooserNative` has merged and will be landed in Electron 14 (electron/electron#19159)
Hi, [Edit] : no consistent result depending on distributions. Cannot have ubuntu family work. Did have some success on Arch. Weird. |
No one’s been able to figure out the cause of this feature seemingly not working on Ubuntu (or in Flatpak) so I’ve opened a follow up: #31258 If anyone has ideas on what might be the problem please share them. |
Contains: - Chromium 91 -> 96, including multiple webrtc and security fixes - Linux file chooser portal fixes (electron/electron#19159) Closes: #629
Description of Change
With this commit, users on KDE/plasma will finally have support in Electron for their native file chooser dialogs. Fixes #2911.
Checklist
npm test
passesRelease Notes
Notes: Added support for alternative file choosers on Linux through the usage of the XDG Desktop Portal in
GtkFileChooserNative
.This PR is backwards compatible to support platforms like Ubuntu 16.04/14.04 whose GTK versions are less than 3.20.