13

I'd like to achieve something I thought would take a couple of seconds and turns out to be a nervous breakdown: override a theme's selected item color in a GTK3 theme.

At first, I naively though that overriding the value in ~/.config/gtk-3.0/gtk.css would to the trick, but no, it is ignored.

$ cat ~/.config/gtk-3.0/gtk.css
@define-color selected_bg_color #ff4e9a;

I then rsync'ed /usr/share/themes/<name> to ~/.themes and changed the wanted color in there by modifying the value of selected_bg_color, but that did nothing.  I sed'ed all the color values in the css file. Still ignored.

Finally, the only way I found to override one simple color was to "register" the local copied theme:

cd /home/foo/.themes/themename/gtk-3.0
glib-compile-resources gtk.gresource.xml

Is GTK3 so overengineered that there's no other way to override a color?

Edit: before anybody advise to launch gnome's Appearance menu, I'm running Mate Desktop, where preferences apply to GTK2.
Also gtk-theme-config does strictly nothing apart from filling ~/.config/gtk-3.0/gtk.css.

4
  • 1
    have you tried editing org.gnome.desktop.interface.gtk-colorscheme using dconf and setup selected_bg_color:#ff4e9a as value?
    – zmo
    May 19, 2017 at 14:46
  • Strangely this value is already set to the color, possibly meaning that it actually reads this gtk.css file, but does really nothing with it...
    – iMil
    May 20, 2017 at 11:01
  • 1
    You can try installing gtkparasite and launch apps using GTK_MODULES=gtkparasite any-gnome-crap to try to reverse the 💩 that's going on in there.
    – zmo
    May 20, 2017 at 12:03
  • Does your theme use selected_bg_color at all?
    – L. Levrel
    Nov 6, 2018 at 11:02

1 Answer 1

1

I went through this recently. Often times there is more than one line that will outline decorations. Before you do anything, I would suggest making a backup of the file you are going to edit.

The way that I accomplished this initially was to install a color picker so I could get the exact hex code for the color I wanted to replace. Then I edited my theme's gtk.css file in Vim using find and replace. I replaced all instances of color {#ff4e9a} with my own color using the vim command:%s/#ff4e9a/#C7CDDB/g. After making changes make sure you write the file with :w and reload your shell.

Typically with GTK there is also a "fallback" color that is used for some windows. I suggest searching your theme file with Vim for this phrase using /fallback or using a color picker if you can visibly tell the difference window decorations.

GTK is very finicky, I messed up my themes a few times while learning so be careful.

1
  • Where are the default color definitions? It appears in gtk-3 all the defaults are hardcoded and the /usr/share/themes/Adwaita/gti-3.0/gtk.css file just contains a comment to the effect "this file is not used".
    – Ex Umbris
    Jul 25, 2020 at 21:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .