Iβve been using Matugen to generate dynamic colors from my wallpaper, and I wanted the whole GNOME desktop to re-theme immediately after changing the wallpaper.
The problem is that GNOME Shell normally needs a logout to reliably pick up theme changes, while GTK applications generally need to be restarted before they notice updated styling.
I didnβt want to keep logging out or restarting everything, so I started experimenting with "gsettings" toggles. Surprisingly, I found a combination that lets me force all three to refresh while the session is running.
- GNOME Shell β reapply the theme without logging out
I found that clearing the User Themes extension's theme name and immediately setting it back causes GNOME Shell to re-parse the theme:
gsettings set org.gnome.shell.extensions.user-theme name ''
gsettings set org.gnome.shell.extensions.user-theme name 'Your-Custom-Theme'
The Shell refreshes almost immediately without ending the session.
- GTK3 β force open applications to redraw
I then tried the same idea with GTK3.
Normally, changing the CSS/theme files doesn't make already-running GTK3 applications pick up the changes. But toggling "gtk-theme" away from the current theme and back seems to force GTK3 to reload the styling:
gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita'
gsettings set org.gnome.desktop.interface gtk-theme 'Your-Custom-Theme'
This works on my setup without restarting the applications.
- GTK4 / Libadwaita β the interesting one
GTK4 was where the simple theme-switch trick stopped working.
For GTK4/Libadwaita applications, my generated CSS lives in:
~/.config/gtk-4.0/gtk.css
Changing that file doesn't seem to make already-running applications reload it just by changing "gtk-theme".
While testing light/dark palettes, however, I noticed that changing GNOME's system color-scheme caused the running GTK4 applications to re-read their CSS.
So I ended up using:
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
That causes the GTK4/Libadwaita applications on my system to update their styling without restarting them.
The result
I now chain all three operations in my Matugen post-processing hook:
Generate colors
β
Update GTK/Shell CSS
β
Refresh GNOME Shell
β
Refresh GTK3
β
Toggle color scheme β refresh GTK4/Libadwaita
There is a small visual flicker because the settings are being changed twice, and obviously this is more of a workaround than a proper solution.
But it means I can change my wallpaper and have the Shell + GTK3 + GTK4/Libadwaita styling update while everything is still open, without logging out or manually restarting applications.
I wish GNOME/GTK had a proper IPC/API for telling the running desktop and applications to reload their CSS. Until then, this has been working well for me.
Has anyone found a cleaner/native way to trigger these reloads?