NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.19k stars 14.19k forks source link

gtk4 dark theme broken since upgrade to 23.11 #274554

Open merspieler opened 11 months ago

merspieler commented 11 months ago

Describe the bug

Since the upgrade to 23.11, gtk4 apps no longer respect the set dark mode.

Steps To Reproduce

Steps to reproduce the behavior:

  1. set dark mode for gtk4 via nix-shell -p glib --run "gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita-dark'"
  2. launch any gtk4 app via Dmenu or terminal
  3. it's not in dark mode

Only way I got it into using dark mode was like this: GTK_THEME=Adwaita-dark <program> but that's not feasible when using dmenu

Expected behavior

All gtk4 apps are in dark mode

Additional context

Add any other context about the problem here.

In case it makes a difference, I'm running i3wm under X.org.

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.67, NixOS, 23.11 (Tapir), 23.11.1779.cf28ee258fd5`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"nixos-23.11, nixos-unstable"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Add a :+1: reaction to issues you find important.

alesya-h commented 10 months ago

It's not just gtk4. For me it's mostly gtk3 apps with some exceptions, whereas gtk4 apps all work normally. I've tested the following apps: GTK3 (Tilix :x: , Terminator :x: , Meld :x:, Gnome Disks :green_circle: ) and GTK4 (BlackBox :green_circle: , Console :green_circle: , Gedit :green_circle: , Blanket :green_circle:). For apps that show in white style gtk inspector shows an unset theme, but setting it and/or toggling "Dark Variant" doesn't change anything: image image

mannp commented 9 months ago

For me, both gtk3 and gtk4 settings.ini had the following settings;

[Settings]
gtk-icon-theme-name=Adwaita
gtk-theme-name=Adwaita-dark
gtk-application-prefer-dark-theme=0

changing to;

[Settings]
gtk-icon-theme-name=Adwaita
gtk-theme-name=Adwaita
gtk-application-prefer-dark-theme=1

Made things dark again :)

merspieler commented 9 months ago

already had prefer dark theme, added the others as well now, programs are still white

mannp commented 9 months ago

Do you have gnome tweaks installed by any chance?

gtk-theme-name=Adwaita-dark, should be gtk-theme-name=Adwaita for me, will update.

alesya-h commented 9 months ago

@mannp adding those lines didn't fix it. To me it seems that the problem is with apps not being able to find Awaita Dark theme (or any theme at all, see inspector screenshots above)

mannp commented 9 months ago

@mannp adding those lines didn't fix it. To me it seems that the problem is with apps not being able to find Awaita Dark theme (or any theme at all, see inspector screenshots above)

Sure, I don't use inspector, but within gnome tweaks the adwaita dark theme is not specified separately now, it's just Adwaita for me.

jtojnar commented 9 months ago

Only way I got it into using dark mode was like this: GTK_THEME=Adwaita-dark <program> but that's not feasible when using dmenu

This sounds like OP is using libadwaita-based GTK 4 apps, where changing the gtk-theme GSettings key (from org.gnome.desktop.interface schema) does not work.


The rest of you are are probably encountering unrelated issue triggered by https://github.com/NixOS/nixpkgs/pull/278941.

In short, Adwaita-Dark should not be used these days since it is unmaintained. The aforementioned PR removes it from the default installation.

You should instead use the Adwaita theme shipped with GTK 3, which has dark theme built in (if you set gtk-application-prefer-dark-theme=1 in GTK 3 config).

For GTK 4 apps not using libadwaita, the theme is called Default, gtk-application-prefer-dark-theme=1 (in GTK 4 config) should work there as well.

For libadwaita-based GTK 4 apps, you need to set the color-scheme GSettings key (from org.gnome.desktop.interface schema) to 'prefer-dark'.

merspieler commented 9 months ago

tried all of those options, kdenlive for example... white

jtojnar commented 9 months ago

That is not a GTK app so no idea how it works there.

merspieler commented 9 months ago

wait do I have another problem here? cause that broke together in the same update with all the GTK stuff...

jtojnar commented 9 months ago

It might be that Kdenlive uses some kind of heuristic (e.g. checking if theme name ends with dark, or parsing the GTK theme to discover the background and not knowing about prefer-dark-theme setting).

You will probably be best off asking its maintainers.

dawidd6 commented 5 months ago

Only way I got it into using dark mode was like this: GTK_THEME=Adwaita-dark <program> but that's not feasible when using dmenu

This sounds like OP is using libadwaita-based GTK 4 apps, where changing the gtk-theme GSettings key (from org.gnome.desktop.interface schema) does not work.

The rest of you are are probably encountering unrelated issue triggered by #278941.

In short, Adwaita-Dark should not be used these days since it is unmaintained. The aforementioned PR removes it from the default installation.

You should instead use the Adwaita theme shipped with GTK 3, which has dark theme built in (if you set gtk-application-prefer-dark-theme=1 in GTK 3 config).

For GTK 4 apps not using libadwaita, the theme is called Default, gtk-application-prefer-dark-theme=1 (in GTK 4 config) should work there as well.

For libadwaita-based GTK 4 apps, you need to set the color-scheme GSettings key (from org.gnome.desktop.interface schema) to 'prefer-dark'.

This should be put in 24.05 release notes. I've just run into this problem and your post really helped. Thanks!

nixos-discourse commented 5 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nixos-24-05-released/46279/9

jtojnar commented 5 months ago

We mentioned the Adwaita-Dark removal in https://github.com/NixOS/nixpkgs/commit/86cc033bf9a44225c8caadb2e2ec6f02feee02eb but for some reason it disappeared from the history. https://github.com/NixOS/nixpkgs/pull/316270 adds it back.

auroraanna commented 5 months ago

when i try setting anything via gsettings i get No schemas installed.

jtojnar commented 5 months ago

We intentionally do not make schemas globally available. You need to run gsettings with XDG_DATA_DIRS environment variable to set to schema paths you need.

gepbird commented 4 months ago

For libadwaita-based GTK 4 apps, you need to set the color-scheme GSettings key (from org.gnome.desktop.interface schema) to 'prefer-dark'.

Any idea why this doesn't work for me? I tested it with nautilus on dwm window manager, using the latest nixos-unstable branch.

2024-06-23_20-55

Currently I'm using an ugly workaround where I link adw-gtk3's dark gtk.css to gtk4 config, but I'd like to remove it and properly set dark theme for gtk4 apps.

discapes commented 4 months ago

image @gepbird Same issue here. Took me a while to figure out I needed to add the schema to XDG_DATA_DIRS, so I'm really wondering why it didn't help.

discapes commented 4 months ago

@gepbird @auroraanna OMG I finally solved it. Use ADW_DISABLE_PORTAL=1 . The reason that libadwaita wasn't dark was that it tried to get the color scheme from a desktop portal, which would require even more tweaking to return dark. ADW_DISABLE_PORTAL makes it read gsettings. And you don't even need to add the gsettings schema to XDG_DATA_DIRS.

discapes commented 4 months ago

Also figured out how to get the gtk portal working on Hyprland, and presumably other WM:s as well.

  xdg.portal.extraportals = [ pkgs.xdg-desktop-portal-gtk ];

This makes dark mode also apply to programs like firefox that only support the portal, and makes ADW_DISABLE_PORTAL unnecessary.

gepbird commented 4 months ago

@discapes Thanks for your research, it works well with environment.sessionVariables.ADW_DISABLE_PORTAL = 1;.

I tried to make it work on dwm with portals (and without the env var) but it stays light theme, this is what I've tried:

  home-manager.users.user.dconf.settings."org/gnome/desktop/interface".color-scheme = "prefer-dark";
  xdg.portal.enable = true;
  xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-gtk ];

Can you share your whole hyprland config?

discapes commented 4 months ago

@gepbird https://github.com/discapes/dotfiles

discapes commented 4 months ago

You can test the portal manually with

dbus-send --print-reply --dest=org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings.Read "string:org.freedesktop.appearance"  "string:color-scheme"

Also use systemctl --user status xdg-desktop-portal-gtk to verify the service is started.

gepbird commented 4 months ago

Thanks for the dbus troubleshooting command, I'll check out your config and dive deeper into this later.

~ ❯ systemctl --user status xdg-desktop-portal-gtk                                                                                                                             
● xdg-desktop-portal-gtk.service - Portal service (GTK/GNOME implementation)
     Loaded: loaded (/etc/systemd/user/xdg-desktop-portal-gtk.service; linked-runtime; preset: enabled)
     Active: active (running) since Fri 2024-07-05 00:46:33 CEST; 31s ago
   Main PID: 33397 (.xdg-desktop-po)
      Tasks: 5 (limit: 38398)
     Memory: 3.5M (peak: 4.1M)
        CPU: 55ms
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/xdg-desktop-portal-gtk.service
             └─33397 /nix/store/3m78a12shpr516ny99gp3x3k9db7l98v-xdg-desktop-portal-gtk-1.15.1/libexec/xdg-desktop-portal-gtk

Jul 05 00:46:33 geppc systemd[1820]: Starting Portal service (GTK/GNOME implementation)...
Jul 05 00:46:33 geppc systemd[1820]: Started Portal service (GTK/GNOME implementation).

~ ❯ dbus-send --print-reply --dest=org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings.Read "string:org.freedesktop.appearance"  "string:color-scheme"
Error org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.portal.Settings” on object at path /org/freedesktop/portal/desktop
trya2l commented 4 months ago

Thanks guys, I've eventually managed to resolved my issue! According to https://wiki.archlinux.org/title/XDG_Desktop_Portal

Multiple backends can be installed: for example, a Sway user may use xdg-desktop-portal-wlr for screen sharing support and xdg-desktop-portal-gtk as a fallback for all other interfaces that xdg-desktop-portal-wlr does not implement.

Here is my config. It enables dark-theme for gtk2/3/4 and Qt.

{ config, pkgs, ... }:
{
  dconf = {
    settings = {
      "org/gnome/desktop/interface" = {
    gtk-theme = "Adwaita-dark";
    color-scheme = "prefer-dark";
      };
    };
  };

  gtk = {
    enable = true;
    theme = {
      name = "Adwaita-dark";
      package = pkgs.gnome.gnome-themes-extra;
    };
  };

  qt = {
    enable = true;
    platformTheme.name = "Adwaita-dark";
    style = {
      name = "Adwaita-dark";
      package = pkgs.adwaita-qt;
    };
  };

  xdg.portal = {
      enable = true;
      extraPortals = with pkgs; [ xdg-desktop-portal-gtk ];
      configPackages = with pkgs; [ xdg-desktop-portal-gtk ];
  };
}
max-ishere commented 1 month ago

I am having issues configuring dark mode system wide (I need this to resolve https://github.com/rharish101/ReGreet/issues/45#issuecomment-2323445064) and I've only managed to get dark mode once. It just doesnt work anymore......... I am so frustrated that I dont even wanna try anything anymore...