Skip to content

Comments

nixos/gnome: enable platform integration for Qt#136071

Merged
jtojnar merged 2 commits intoNixOS:masterfrom
jtojnar:gnome-qpa
Sep 2, 2021
Merged

nixos/gnome: enable platform integration for Qt#136071
jtojnar merged 2 commits intoNixOS:masterfrom
jtojnar:gnome-qpa

Conversation

@jtojnar
Copy link
Member

@jtojnar jtojnar commented Aug 29, 2021

Motivation for this change

Qt links against GTK to be able to use native GTK file chooser in GTK-oriented DEs. However, GTK expects a specific environment, which means the application needs to be wrapped to prevent crashes when file chooser is opened in some environments.

This patch bypasses the need for wrapping Qt applications with GTK-related environment since the file chooser dialogue will now come from a separate process (instantiated by the XDG desktop portal via D-Bus).

In the future, we could remove the GTK dependency from Qt to fix the crashes on non-{GNOME,Pantheon} environments. Then, users would be able to choose between non-native Qt dialogue or native one facilitated by XDG portals (e.g. through setting QT_QPA_PLATFORMTHEME to either qgnomeplatform, or xdgdesktopportal).

One disadvantage is adding a Qt dependency to GNOME, even for people who might not use any Qt apps. But they can easily just add qt5.enable = false; to their NixOS configuration.

The configuration is also presumably less battle tested than plain Qt with its first-party GTK integration. But it is backed by Fedora and used by Manjaro GNOME so it cannot be that bad.

Lastly, I worry about ABI compatibility of the platform modules with apps installed from different Nixpkgs revision.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Confirmed that QT_QPA_PLATFORMTHEME=qgnomeplatform QT_STYLE_OVERRIDE=adwaita calibre follows the theme and file chooser uses portal.
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Qt links against GTK to be able to use native GTK file chooser
in GTK-oriented DEs. However, GTK expects a specific environment,
which means the application needs to be wrapped to prevent crashes
when file chooser is opened in some environments.

This patch bypasses the need for wrapping Qt applications with GTK-related
environment since the file chooser dialogue will now come from a separate
process (instantiated by the XDG desktop portal via D-Bus).

In the future, we could remove the GTK dependency from Qt to fix the crashes
on non-{GNOME,Pantheon} environments. Then, users would be able to choose
between non-native Qt dialogue or native one facilitated by XDG portals
(e.g. through setting `QT_QPA_PLATFORMTHEME` to either `qgnomeplatform`,
or `xdgdesktopportal`).

One disadvantage is adding a Qt dependency to GNOME, even for people
who might not use any Qt apps. But they can easily just add `qt5.enable = false;`
to their NixOS configuration.

The configuration is also presumably less battle tested than plain Qt
with its first-party GTK integration. But it is backed by Fedora
and used by Manjaro GNOME so it cannot be that bad.

Lastly, I worry about ABI compatibility of the platform modules
with apps installed from different Nixpkgs revision.
@github-actions github-actions bot added 6.topic: GNOME GNOME desktop environment and its underlying platform 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` labels Aug 29, 2021
@jtojnar jtojnar requested a review from a team August 29, 2021 02:26
@nixos-discourse
Copy link

@ofborg ofborg bot requested review from amaxine, dasj19 and hedning August 29, 2021 02:36
@ofborg ofborg bot added 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Aug 29, 2021
@r-rmcgibbo
Copy link

r-rmcgibbo commented Aug 29, 2021

Result of nixpkgs-review pr 136071 at 8828999 run on aarch64-linux 1

2 packages built successfully:
  • nixos-install-tools
  • qgnomeplatform

Result of nixpkgs-review pr 136071 at 8828999 run on x86_64-linux 1

2 packages built successfully:
  • nixos-install-tools
  • qgnomeplatform
1 suggestion:
  • warning: unused-argument

    Unused argument: pantheon.
    Near pkgs/development/libraries/qgnomeplatform/default.nix:11:3:

       |
    11 | , pantheon
       |   ^
    

@jtojnar jtojnar merged commit 07978cd into NixOS:master Sep 2, 2021
@jtojnar jtojnar deleted the gnome-qpa branch September 2, 2021 01:06
@ilya-fedin
Copy link
Contributor

In the future, we could remove the GTK dependency from Qt to fix the crashes on non-{GNOME,Pantheon} environments. Then, users would be able to choose between non-native Qt dialogue or native one facilitated by XDG portals (e.g. through setting QT_QPA_PLATFORMTHEME to either qgnomeplatform, or xdgdesktopportal).

That's not a really good idea. Unlike GTK, Qt doesn't have its own settings DB, it relies on the system to provide values. Currently, gtk platformtheme plugin is the only out-of-the-box way to set icon theme, fonts and etc for environments without its own platformtheme plugin. Also, QGnomePlatform uses GNOME/Cinnamon gsettings while the Qt's plugin uses generic GTK methods, so qgnomeplatform is useless on e.g. MATE or Xfce.

The only alternative for these envrionments is qt5ct, but it's a third-party plugin and in most cases you don't need it (you can set Qt style via QT_STYLE_OVERRIDE, all other settings via GTK configurators).

Also, when using xdgdesktopportal, you can't say Qt where to get other settings (like icon theme) from. And qt5ct doesn't support xdgdesktopportal (you can set it in config, but it will be reset as soon as you change something in the configurator).

It's also a surprise to me that Qt doesn't uses gtk as an always-fallback, to work properly in WM-only environments without manual configuration. Maybe I should try to submit a patch to Qt to fix this, that would be a way better UX for WM users, I know a lot of them who didn't know that Qt can use system theme before I explained how to configure it to them.

@jtojnar
Copy link
Member Author

jtojnar commented Sep 29, 2021

That's not a really good idea. Unlike GTK, Qt doesn't have its own settings DB, it relies on the system to provide values. Currently, gtk platformtheme plugin is the only out-of-the-box way to set icon theme, fonts and etc for environments without its own platformtheme plugin.

Hmm, did not realize that. That indeed complicates the matters.

Also, QGnomePlatform uses GNOME/Cinnamon gsettings while the Qt's plugin uses generic GTK methods, so qgnomeplatform is useless on e.g. MATE or Xfce.

Yeah, we might try to convince QGnomePlatform to fall back to GTK settings where possible.

Also, when using xdgdesktopportal, you can't say Qt where to get other settings (like icon theme) from.

I wonder if an official setting key for that would be recognized:

https://github.com/flatpak/xdg-desktop-portal/blob/e4523531cfc478036fc4554e1d1f0582bb6bdf59/data/org.freedesktop.portal.Settings.xml#L30-L46

Currently, flatpak just reads GtkSettings and likely needs dconf permission:
https://gist.github.com/lmintmate/b512680c0d1ee8f41b8f43cd2c81dc2c
https://blog.tingping.se/2017/05/11/flatpak-theming.html

And qt5ct doesn't support xdgdesktopportal (you can set it in config, but it will be reset as soon as you change something in the configurator).

Maybe that could be fixed in qt5ct or some other component?

It's also a surprise to me that Qt doesn't uses gtk as an always-fallback, to work properly in WM-only environments without manual configuration. Maybe I should try to submit a patch to Qt to fix this, that would be a way better UX for WM users, I know a lot of them who didn't know that Qt can use system theme before I explained how to configure it to them.

Do you mean https://github.com/qt/qtbase/tree/9db7cc79a26ced4997277b5c206ca15949133240/src/plugins/platformthemes/gtk3? Does that really support GTK themes? What is the purpose of QGnomePlatform then?

@ilya-fedin
Copy link
Contributor

I wonder if an official setting key for that would be recognized:

Well, gtk developers like dbus, Qt developers seem to prefer ini configs...

Maybe that could be fixed in qt5ct or some other component?

It's an one line patch for the configurator, but the fact qt5ct hosts on sourceforge turns submitting the patch into a quest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: GNOME GNOME desktop environment and its underlying platform 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants