From b2fabbc764f90fa0a3ccab6ef42a5d83d1821cd4 Mon Sep 17 00:00:00 2001 From: Daniel Fainberg Date: Tue, 7 Jul 2026 16:26:38 +0200 Subject: [PATCH] feat(desktop): dark-mode Qt/GTK apps via portal color-scheme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Qt apps (keepassxc, pinentry-qt) rendered light while the GTK side was Adwaita-dark. keepassxc's `auto` theme reads dark/light only from the xdg-desktop-portal `color-scheme` value, which the gtk portal serves from dconf `org/gnome/desktop/interface/color-scheme` — unset, so it reported "no preference" and fell back to light. Set it to `prefer-dark`. Also route Qt through the `gtk3` platform theme (`libqgtk3` ships in qtbase, unlike an external `adwaita-qt` style plugin which nixpkgs' baked `QT_PLUGIN_PATH` makes unreachable), and set the GTK prefer-dark flag. Co-Authored-By: Claude Opus 4.8 --- modules/home.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/modules/home.nix b/modules/home.nix index 1d69ac8..6c5a469 100644 --- a/modules/home.nix +++ b/modules/home.nix @@ -323,6 +323,31 @@ in # Keep the GTK2 rc out of $HOME (default ~/.gtkrc-2.0). Setting this also # makes home-manager export GTK2_RC_FILES so GTK2 apps still find it. gtk2.configLocation = "${config.xdg.configHome}/gtk-2.0/gtkrc"; + # The theme *name* alone isn't enough: the qgtk3 Qt bridge and apps' dark + # detection (e.g. keepassxc's "auto" theme) read this flag, not the name. + # Set it so both GTK apps and the Qt-via-gtk3 apps resolve to dark. + gtk3.extraConfig.gtk-application-prefer-dark-theme = true; + gtk4.extraConfig.gtk-application-prefer-dark-theme = true; + }; + + # The canonical dark/light signal on Wayland: apps query the xdg-desktop-portal + # Settings interface for org.freedesktop.appearance/color-scheme over D-Bus, and + # the gtk portal serves that from this dconf key. keepassxc's "auto" theme reads + # it (NixUtils::isDarkMode) and ignores the GTK theme name / Qt style entirely, + # so without this the portal reports 0 ("no preference") and keepass stays light. + # prefer-dark makes the portal report dark to every color-scheme-aware app. + dconf.settings."org/gnome/desktop/interface".color-scheme = "prefer-dark"; + + # Match the Qt apps (keepassxc, pinentry-qt, ssh askpass) to the GTK + # Adwaita-dark above, else they render the default light Fusion style. Use the + # gtk3 platform theme, not an adwaita *style* override: nixpkgs wraps Qt apps + # with a baked QT_PLUGIN_PATH pointing only at their build deps, so an external + # style plugin (adwaita-qt) is unreachable and QT_STYLE_OVERRIDE is silently + # ignored. The gtk3 plugin (libqgtk3) ships inside qtbase itself, so it's + # always on that path, and it reads the GTK theme (Adwaita-dark) directly. + qt = { + enable = true; + platformTheme.name = "gtk3"; }; # The home-manager Hyprland module below enables xdg.portal and pins the