Replace GTK+ file dialog with alternative

14,079

Since around 2016 the answer is yes! At least for using the KDE file chooser with GTK3 apps.

Gtk+ developers call this “native file choosers” for “sandboxed applications”, while the primary target for this was Flatpak it also made it possible to use these on Windows. However you can also use this for non-sandboxed/flatpak applications using a trick:

  1. Install the xdg-desktop-portal-kde package: Arch Linux, Debian, Fedora, KDE Neon, Ubuntu (Direct Install link)
  2. If you are not actually using KDE, edit /usr/share/xdg-desktop-portal/portals/kde.portal and add the value of $XDG_CURRENT_DESKTOP, separated by a semi-colon to the UseIn=KDE line (i.e.: UseIn=KDE;XFCE)
  3. Add the line GTK_USE_PORTAL=1 to ~/.pam_environment so that GTK will always behave as if it were in an sandboxed environment
  4. Log out and back in to apply these changes
Share:
14,079

Related videos on Youtube

gandalf3
Author by

gandalf3

This user's About me is not about this user.

Updated on September 18, 2022

Comments

  • gandalf3
    gandalf3 almost 2 years

    Is there any way to configure GTK+ programs to use a different file dialog?

    Reading ancient articles on the default dialog and seeing no difference to the current version does no bode well for it's improvement in the near future.

    I've read this question, but I appear to be one of the few to do so in nearly a year. As I mentioned in a comment on that question:

    For archlinux there is a patched version of FF for KDE. It works well if you are in KDE and like the stripped down version of dolphin/whatever it is, but unfortunately doesn't seem to change the file selector if you are not using KDE

    As I'm currently in a custom openbox setup, Firefox is back to using the disliked GTK+ dialog. But this solution only works for Firefox, so I'd prefer a way to purge this from my system globally.

  • ntninja
    ntninja about 5 years
    I should maybe add that this will not work for apps using the classic GtkFileChooserDialog or GtkFileChooserWidget APIs: These expose the underlying GtkWidgets to the application which would not be available when rendering the file chooser using anything other than GTK. Hence, only GtkFileChooserNative and GtkFileChooserButton will work and if you see a GTK app still using the GTK file chooser after performing the above steps, you may want to send them a patch. ;-)
  • Wyatt Ward
    Wyatt Ward about 4 years
    Some "environments" don't use $XDG_CURRENT_DESKTOP. I run FVWM as my "X session manager". So I'd be setting it to an empty string, which doesn't sound right. I'm assuming I should just put something to set that value in my login scripts to e.g. fvwm and then match it in kde.portal. Also I'd really rather not install flatpak stuff if I can avoid it (xdg-desktop-portal-kde pulls in flatpak as a dependency in debian). Additionally, I don't think ~/.pam_environment does anything on my install.
  • ntninja
    ntninja about 4 years
    @Wyatt8740: If there is no standard value for $XDG_CURRENT_DESKTOP for your configuration making one up and using that is a reasonable solution. If ~/.pam_environment doesn't work try adding session required pam_env.so user_readenv=1 to end of /etc/pam.d/common-password (making it the very last session-type plugin executed) or, for X11, try exporting the value in ~/.Xsession instead. At least on my Debian unstable system I see no dependency of xdg-desktop-portal-kde on flatpak, only on bubblewrap
  • Wyatt Ward
    Wyatt Ward about 4 years
    it's through multiple levels of dependency, IIRC. I've figured it out now I think. It might have been related to a metapackage that could be provided by multiple solutions (one of which required systemd). I'm forgetting now. Thanks for the advice at any rate.
  • James Bond
    James Bond over 3 years
    Kubuntu 20.04, this method doesn't work.
  • QkiZ
    QkiZ over 3 years
    Ubuntu 20.10, doesn't work
  • mirabilos
    mirabilos about 3 years
    Debian unstable (May 2021), evilwm (thus no DE); this works, I don’t have to set XDG_CURRENT_DESKTOP or edit the file at all @WyattWard
  • Wyatt Ward
    Wyatt Ward almost 3 years
    @mirabilos I might give it a shot again since I'm also on Sid (running FVWM3). Assuming I can avoid the systemd dependency, that is. (edit: --no-install-recommends helped; I think this is going to work without getting rid of my sysvinit). Thanks.
  • mirabilos
    mirabilos almost 3 years
    @WyattWard mirbsd.org/~tg/Debs/dists/sid/wtf/Pkgs/mirabilos-support/… may also help with that ☺
  • cipricus
    cipricus over 2 years
    @JamesBond - this is not meant for Kubuntu, but for environments that lack Plasma. See this instead.