Bug 477479 - KDE file chooser portal can't be hidden programmatically, but it can in GNOME
Summary: KDE file chooser portal can't be hidden programmatically, but it can in GNOME
Status: RESOLVED MOVED
Alias: None
Product: xdg-desktop-portal-kde
Classification: Plasma
Component: general (show other bugs)
Version: git-stable-Plasma/5.27
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-24 20:23 UTC by Emilio Cobos Álvarez (:emilio)
Modified: 2023-11-25 02:54 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Example program. (1.37 KB, text/plain)
2023-11-25 00:49 UTC, Emilio Cobos Álvarez (:emilio)
Details
Gtk4 program that works. (1.48 KB, text/plain)
2023-11-25 01:02 UTC, Emilio Cobos Álvarez (:emilio)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Emilio Cobos Álvarez (:emilio) 2023-11-24 20:23:11 UTC
SUMMARY

We're trying to add an API close open file pickers in Firefox (I can give more reasoning for that if wanted). However the KDE file picker doesn't react to the `Close` method.

We're using `gtk_native_dialog_hide` / `_destroy`, which sends a `Close` method to the portal, see [here](https://gitlab.gnome.org/GNOME/gtk/-/blob/bcab0e4254ace10bb2b3de8d4c10bc25ef3368ce/gtk/gtkfilechoosernativeportal.c#L219-222) for gtk4, and [here](https://gitlab.gnome.org/GNOME/gtk/-/blob/65b0c289b03680b825101b68a5c4b11e99e31b43/gtk/gtkfilechoosernativeportal.c#L187-190) for the gtk3 equivalent.

I was filing this as a bug when I noticed that `Close` is not documented [here](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.FileChooser.html), so maybe it should be an enhancement request? 

I filed https://github.com/flatpak/xdg-desktop-portal/issues/1225 on it not being documented. My _guess_ is that this should be fairly easy to implement, happy to give it a go with some pointers.

Thanks :)
Comment 1 Emilio Cobos Álvarez (:emilio) 2023-11-24 21:25:39 UTC
Ah, I was pointed out in the GitHub issue that this is, indeed defined in https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Request.html#org-freedesktop-portal-request-close

So it is a bug in the KDE portal impl after all.
Comment 2 Nicolas Fella 2023-11-24 23:09:36 UTC
What version of Plasma are you testing? As far as I can tell this should work since Plasma 5.25 (https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/90)
Comment 3 Emilio Cobos Álvarez (:emilio) 2023-11-25 00:37:19 UTC
(In reply to Nicolas Fella from comment #2)
> What version of Plasma are you testing? As far as I can tell this should
> work since Plasma 5.25
> (https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/90)

KDE Plasma Version: 5.27.9
KDE Frameworks Version: 5.112.0
Qt Version: 5.15.11
Kernel Version: 6.6.2-arch1-1 (64-bit)
Graphics Platform: Wayland

A coworker of mine could repro on Fedora as well, though not sure the exact version.
Comment 4 Emilio Cobos Álvarez (:emilio) 2023-11-25 00:49:30 UTC
Created attachment 163443 [details]
Example program.

Build with:

gcc $(pkg-config --cflags --libs gtk+-3.0) hello-world.c -o hello-world

Run with:

GTK_USE_PORTAL=1 ./hello-world

And click the button.

ER: KDE file picker appears, then disappears in 3 seconds.

AR: File picker stays open.
Comment 5 Emilio Cobos Álvarez (:emilio) 2023-11-25 01:02:08 UTC
Created attachment 163445 [details]
Gtk4 program that works.

Hmm, sorry, this does work. I think it's a gtk3 bug and I must have mistested in GNOME.
Comment 6 Nicolas Fella 2023-11-25 01:04:54 UTC
Running your example and dbus-monitor I get

method call time=1700873953.362815 sender=:1.1276 -> destination=org.freedesktop.portal.Desktop serial=97 path=/org/freedesktop/portal/desktop; interface=org.freedesktop.portal.FileChooser; member=Close
   object path "/org/freedesktop/portal/desktop/request/1_1276/gtk458574415"
method call time=1700873953.362947 sender=:1.1276 -> destination=org.freedesktop.DBus serial=98 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
   string "type='signal',interface='ca.desrt.dconf.Writer',path='/ca/desrt/dconf/Writer/user',arg0path='/org/gtk/settings/file-chooser/'"
method return time=1700873953.362985 sender=org.freedesktop.DBus -> destination=:1.1276 serial=4294967295 reply_serial=98
error time=1700873953.363167 sender=:1.27 -> destination=:1.1276 error_name=org.freedesktop.DBus.Error.UnknownMethod reply_serial=97
   string "No such method “Close”"

so yes, it looks like the app is doing something not right
Comment 7 Nicolas Fella 2023-11-25 01:08:14 UTC
(In reply to Emilio Cobos Álvarez (:emilio) from comment #5)
> Created attachment 163445 [details]
> Gtk4 program that works.
> 
> Hmm, sorry, this does work. I think it's a gtk3 bug and I must have
> mistested in GNOME.

Indeed, that works for me too
Comment 8 Emilio Cobos Álvarez (:emilio) 2023-11-25 01:26:36 UTC
Yeah, they seem to be sending the request to the wrong interface.

https://gitlab.gnome.org/GNOME/gtk/-/blob/65b0c289b03680b825101b68a5c4b11e99e31b43/gtk/gtkfilechoosernativeportal.c#L189

Should be "org.freedesktop.portal.Request". Will file there. Thanks
Comment 9 Emilio Cobos Álvarez (:emilio) 2023-11-25 02:09:27 UTC
(In reply to Nicolas Fella from comment #7)
> Indeed, that works for me too

Hah, this _seems_ to work, but actually doesn't. But I still think it's not KDE's fault...
Comment 10 Emilio Cobos Álvarez (:emilio) 2023-11-25 02:45:10 UTC
https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/6611
Comment 11 Emilio Cobos Álvarez (:emilio) 2023-11-25 02:54:42 UTC
https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/6613 for GTK4 (which suffered from a slightly different issue)