Skip to content

feat(Themes): add support for GTK3 dynamic theming - #2523

Merged
bbedward merged 7 commits into
duxlabs-dev:masterfrom
nebeljam:gtk3
Jul 23, 2026
Merged

bbedward merged 7 commits into
duxlabs-dev:masterfrom
nebeljam:gtk3

Conversation

@nebeljam

@nebeljam nebeljam commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

'Proof of concept'

Instead of overriding named colors of all GTK3 themes via the config directory file, override only named colors for each variant of the adw-gtk3 theme (light and dark), and let GTK3 apps switch theme variant depending on the value of org.gnome.desktop.interface color-scheme.

This implies :

  • that GTK3 apps will auto adjust their theme in real time, without having to restart them ;
  • and that we can get rid of the stylesheet duplicata in the gtk-light-colors.css matugen template1.

However, the main shortcoming of this method is having to rely on the adw-gtk3 theme being installed in the user themes directory2 when package managers will install it system-wide in /usr/share.

This also entails that theming GTK3 apps without adw-gtk3 (via the .config override) would no longer be provided by DMS (at least I did not write anything to provide a fallback/choice).

Eventually, I don't know on which side you think the burden should weigh, but a stable solution could be to vendor the theme3.

Obviously, considering the size of the change, I could have overlooked some issues, but I've been using this patch for roughly a week and it seems stable.

Screenshots

contrib_DMS.mp4

Footnotes

  1. At least my tests showed no blatant issue without those 8000 LOC. ↩

  2. Considering they don't use the legacy $HOME/.themes folder. ↩

  3. with a "dank" prefix to differentiate it from the original ? ↩

@real-or-random

Copy link
Copy Markdown

This implies :

  • that GTK3 apps will auto adjust their theme in real time, without having to restart them ;

This will be great.

  • and that we can get rid of the stylesheet duplicata in the gtk-light-colors.css matugen template1.

This would probably also solve #1555 as a side effect.

This also entails that theming GTK3 apps without adw-gtk3 (via the .config override) would no longer be provided by DMS (at least I did not write anything to provide a fallback/choice).

Sounds acceptable to me. The current way of simply overwriting everything with the adw3 light theme is certainly not better.

Eventually, I don't know on which side you think the burden should weigh, but a stable solution could be to vendor the theme

If DMS is committed to adw-gtk3 anyway, it can also ship it. And if a prefix is added, this really keeps it separate from the system installation.

@Spoch-dev

This comment was marked as spam.

@nebeljam
nebeljam force-pushed the gtk3 branch 6 times, most recently from 17ce844 to d9e8cc8 Compare July 6, 2026 03:29
@nebeljam

nebeljam commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Following 8f10096 :

  • reverted the majority of the changes to the Go and Qml code ;
  • concentrated the logic in the gtk.sh script1.

If iterating over the adw-gtk3 installation directory candidates in order of preference is enough, then I gladly embrace the minimalism of the solution, and there is - I think - no need for any discussion at all.

N.B. : this also reverts part of 8f10096 (since adw-gtk3 assets healing is no longer needed)

Footnotes

  1. by recycling the check for adw-gtk3 installation directory introduced by the aforementioned commit. ↩

@nebeljam
nebeljam marked this pull request as ready for review July 6, 2026 03:35
@nebeljam
nebeljam force-pushed the gtk3 branch 2 times, most recently from 56fed1b to 8bf2ad1 Compare July 6, 2026 14:01
@nebeljam

nebeljam commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor Author

So, I spoke too soon and way too early in the morning and things were not exactly correct to say the least.
Everything should be working now.

@nebeljam
nebeljam force-pushed the gtk3 branch 3 times, most recently from bb053fb to f775ebe Compare July 6, 2026 23:05
@real-or-random

Copy link
Copy Markdown

@euletheia Is this ready for testing from your side?

@nebeljam
nebeljam force-pushed the gtk3 branch 2 times, most recently from f1eb709 to 99d7f5f Compare July 9, 2026 16:20
@nebeljam

nebeljam commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Added the missing update of GTK theme on dms theme change by re-implementing matugen.go:refreshGTK():910 in Theme.qml:1958.

@real-or-random Everything is even more ready and should be working as expected (don't forget to compile dms so that isDMSGTKActive() performs its checks on gtk4 files instead of gtk3).

Sorry for the repeated updates.

@real-or-random

Copy link
Copy Markdown

Okay, I installed this locally. A few observations.

When I started DMS for the first time, I didn't have a local copy of the theme. DMS greeted me with "failed to apply GTK colors" (or similar). Switching light/dark themes still works, but the colors are wrong. (I think that's exactly what we expect in the case of this error message).

After that first failure, clicking "Apply GTK colors" in Settings results in a confirmation "GTK colors applied succesfully". But the gtk.sh script still failed and the colors didn't work. When I run it manually, I see what's going on: The GTK3 part fails when I run it manually but the failure is not propagated to the exit code:

Info: backing up and removing global theme override for gtk3.
sed: couldn't open temporary file /usr/share/themes/adw-gtk3/gtk-3.0/sedd1KOII: Permission denied
sed: couldn't open temporary file /usr/share/themes/adw-gtk3-dark/gtk-3.0/sedruYvaR: Permission denied
GTK4 import already exists
GTK colors applied successfully

I copied the theme:

cp -r /usr/share/themes/adw-gtk3 ~/.local/share/themes/
cp -r /usr/share/themes/adw-gtk3-dark ~/.local/share/themes/

Then the script works, and the colors will be applied even in running apps. At least in light mode. Dark mode colors seem to be the adw-gtk3-dark default, and setting different colors in the DMS settings has no effect on dark mode colors in gtk3 apps.

And changing colors in running apps is not perfect (both after setting a different color of after toggling light/dark). For some UI elements, a redrawing needs to be forced manulaly For example, the background color of the active search bar in Evolution doesn't change when toggling dark/light mode. Only after starting a new search, it is redrawn and the new color applies. Not sure if anything can be done here or if this is even a bug in Evolution.

Does the initial error message at DMS startup also come from a run of the script? I haven't looked at the code, but shouldn't the script only run when clicking the button? If the error message is a result of script, then Why did the inital run of the script have a bad exit status? I don't know. Maybe ran before matugen and hit this error path?

Summary / conclusions:

  • I think we should never try to write to system paths. Vendoring seems like the proper approach to avoid all kinds of issues here.
  • Light/dark switching works well.
  • Matugen colors are not applied in dark mode. (Are you sure that dark mode uses the adw-gtk3-dark theme? Shouldn't it use the gtk-dark.css file inside the adw-gtk3 theme? It would make much more sense if a single theme controls both light and dark mode. I think adw-gtk3-dark is simply a different theme and we don't need it at all here.)
  • Color changing in running apps is not perfect (but still much better than before).
  • What about this failed to "apply GTK colors" error message at the first DMS startup after installation? (I didn't see it in further starts of DMS but I already had copied the themes.)

One more thought on the approach in general? Do you have an idea why overriding colors like this works while writing to ~/.config/gtk-3.0/gtk.css doesn't? It still feels to me like the latter should be the proper approach, and that there should be some way to make it work.

Comment thread quickshell/Common/Theme.qml Resolved
Comment thread quickshell/scripts/gtk.sh Resolved
Comment thread quickshell/Common/Theme.qml Resolved
Comment thread quickshell/scripts/gtk.sh Resolved
@nebeljam
nebeljam force-pushed the gtk3 branch 7 times, most recently from 473eea6 to f19ad82 Compare July 21, 2026 01:40
@nebeljam
nebeljam requested a review from bbedward July 21, 2026 02:08
@real-or-random

real-or-random commented Jul 21, 2026 •

Copy link
Copy Markdown

Sorry, too many moving parts.

@bbedward
I'm trying to test this via a patched of the AUR package that points at the PR branch. The AUR thing worked before the change to bundle quickshell assets in the dms binary. Now after this change, it seems that the gtk.sh can't be found:

  Jul 21 09:09:56 dms[93539]:   WARN: Process failed to start, likely because the binary could not be found. Command: QList("/run/user/1000/danklinux-shell/468f944f7286aecf/scripts/gtk.sh", "/home/tim/.config", "include", "true", "/run/user/1000/danklinux-shell/468f944f7286aecf")

When I download the script and run apply and include manually, I still see the default theme colors instead of the matugen colors in dark mode.

@euletheia Am I supposed to have a local copy of gtk3-adw-dark or only gtk3-adw?

@bbedward

Copy link
Copy Markdown
Member

Your branch might need rebased? There was a fix for that one of the last couple days.

Easier way to test though is to just run dms run -c /path/to/dms/quickshell with your local copy. Or since yours involves a go change you can just cd core; make then dms kill; ./bin/dms run to run your local copy in full with embedded assets

Comment thread quickshell/Common/Theme.qml Resolved
@nebeljam

Copy link
Copy Markdown
Contributor Author

@euletheia Am I supposed to have a local copy of gtk3-adw-dark or only gtk3-adw?

Both are needed.

@real-or-random real-or-random left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, this now works nicely for me. 👍

  • The embedded script now runs properly.
  • The colors are now applied correctly in dark mode.
  • The only thing that I can still observe is the that some rare UI elements (e.g. background color of search box in Evolution) are not updated on a color change, and need a "manual" refresh by interacting with the UI. But this is super minor and I tend to believe it's a bug in gtk3 or in Evolution.

As for further steps, which could happen in a separate PR (this is a maintainer call obviously), I still believe that vendoring the themes would be the cleanest thing to do. Or alternatively, we'll need proper docs that tell the user to have local copies of adw3-gtk and adw3-gtk-dark. If we decide to vendor, then I believe it will be fine to get rid of the fallback override entirely.

Comment thread quickshell/scripts/gtk.sh Resolved
Comment thread quickshell/scripts/gtk.sh Resolved
@nebeljam

nebeljam commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Depending on what seems right to the maintainers, I'd be happy to submit a PR for either the docs or the themes vendoring.

@nebeljam
nebeljam requested a review from real-or-random July 22, 2026 23:08
Comment thread quickshell/scripts/gtk.sh Outdated
CONFIG_DIR="$1"
SHELL_DIR="$3"
# apply: setup symlinks and config dirs
# refresh: refresh overrides in adw-gtk3

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still doesn't match, I think you want this:

Suggested change
# refresh: refresh overrides in adw-gtk3
# include: refresh overrides in adw-gtk3

@nebeljam nebeljam Jul 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thank you : seems like I wasn't quite settled on which term to use :)

EDIT: That might be splitting hairs, but I included an additional commit to make the actual behavior clearer.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I agree, "patch" is much better than "include". :)

nebeljam added 6 commits July 23, 2026 14:33
Instead of overriding named colors of all GTK3 themes via the config
directory file, only override named colors for each variant of the
adw-gtk3 theme (light and dark), and let GTK3 apps change themes
depending on the value of org.gnome.desktop.interface color-scheme.
- remove gtk3 override if it's a symlink
- remove call to gtk.sh with old arg 'assets-only'
- append key to dconf path to respect dconf write signature
- rename DMS_ENABLE_GTK4_REFRESH to DMS_ENABLE_GTK_REFRESH
- revert a3fba8
Allow to remove all inclusions and overrides for GTK.

@real-or-random real-or-random left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't retested this, but the diff from the tested 450a535 looks fine to me. Good to go from my side.

@bbedward
bbedward merged commit 99f452c into duxlabs-dev:master Jul 23, 2026
3 checks passed
@real-or-random

Copy link
Copy Markdown

As for further steps, which could happen in a separate PR (this is a maintainer call obviously), I still believe that vendoring the themes would be the cleanest thing to do. Or alternatively, we'll need proper docs that tell the user to have local copies of adw3-gtk and adw3-gtk-dark. If we decide to vendor, then I believe it will be fine to get rid of the fallback override entirely.

@bbedward What do you think should be the next step?

And big thanks to @euletheia for this PR and for volunteering to work on the next one.

@real-or-random

real-or-random commented Aug 27, 2026 •

Copy link
Copy Markdown

As for further steps, which could happen in a separate PR (this is a maintainer call obviously), I still believe that vendoring the themes would be the cleanest thing to do. Or alternatively, we'll need proper docs that tell the user to have local copies of adw3-gtk and adw3-gtk-dark. If we decide to vendor, then I believe it will be fine to get rid of the fallback override entirely.

@bbedward What do you think should be the next step?

And big thanks to @euletheia for this PR and for volunteering to work on the next one.

Friendly ping. @bbedward The main task is done but it will be hard for users to make use of without either vendoring gadw3-gtk(-dark) or updating the docs.

@bbedward

Copy link
Copy Markdown
Member

@real-or-random Vendoring adw-gtk3 is not exactly prohibited but a little shaky since its LGPL licensed and we're modifying it via matugen.

I think I'll go with documenting the install + copying the theme from system to ~/.local/share/themes ourselves in the gtk script

bbedward added a commit that referenced this pull request Aug 27, 2026
ref #2523
i with '#' will be ignored, and an empty message aborts the commit.
marcusramberg pushed a commit to marcusramberg/DankMaterialShell that referenced this pull request Sep 2, 2026
* feat(Themes): add support for GTK3 dynamic theming

Instead of overriding named colors of all GTK3 themes via the config
directory file, only override named colors for each variant of the
adw-gtk3 theme (light and dark), and let GTK3 apps change themes
depending on the value of org.gnome.desktop.interface color-scheme.

* fix(Themes): apply requested changes

- remove gtk3 override if it's a symlink
- remove call to gtk.sh with old arg 'assets-only'
- append key to dconf path to respect dconf write signature

* refactor(Themes): separate 'include'/'apply' logic for GTK3 dynamic theming

* revert(Themes): reset timer between color-scheme refresh

- rename DMS_ENABLE_GTK4_REFRESH to DMS_ENABLE_GTK_REFRESH
- revert a3fba8

* feat(Themes): add 'remove' mode to gtk.sh

Allow to remove all inclusions and overrides for GTK.

* fix(Themes): backup adw-gtk3 original css in 'apply' (not 'include')

* style(Themes): rename argument 'include' to 'patch' for clarity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants