Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change GTK+3 look on Windows

I developed a GTK3 application on stock Ubuntu 14.04, and ported it over to Windows without any major issues.However the look of the application on Ubuntu is completely different from Windows (Much uglier on Windows). However GIMP which also uses GTK has a consistent look on Windows and Ubuntu.

I am not too familiar with how Ubuntu changes the look of GTK application, I am wondering what do I need to do for the GTK application on Windows to make it look like the one on Ubuntu?

like image 584
Zhu Mengxi Avatar asked Mar 12 '23 16:03

Zhu Mengxi


1 Answers

GIMP uses GTK+-2.x. GTK+-2.x theming is complicated and strange.

GTK+-3.0 uses Adwaita theme on all platforms.

You can install a different GTK+-3.x theme.

You can change current GTK+-3.x theme by editing settings.ini, located (when using current glib) in

  • DLL prefix/share/gtk-3.0/settings.ini
  • DLL prefix/etc/gtk-3.0/settings.ini
  • C:/Documents and Settings/All Users/Application Data/gtk-3.0/settings.ini
  • C:/Documents and Settings/username/Local Settings/Application Data/gtk-3.0/settings.ini

and adding gtk-theme-name=yourthemename to the [Settings] section.

(settings.ini is also good for all kinds of other settings, look it up!)

GTK+-3.x themes are written in CSS.

As for theme installation, this is what GTK+-3.22 documentation says:

In addition, certain files will be read when GTK+ is initialized. First, the file $XDG_CONFIG_HOME/gtk-3.0/gtk.css is loaded if it exists. Then, GTK+ loads the first existing file among XDG_DATA_HOME/themes/theme-name/gtk-VERSION/gtk.css, $HOME/.themes/theme-name/gtk-VERSION/gtk.css, $XDG_DATA_DIRS/themes/theme-name/gtk-VERSION/gtk.css and DATADIR/share/themes/THEME/gtk-VERSION/gtk.css, where THEME is the name of the current theme (see the #GtkSettings:gtk-theme-name setting), DATADIR is the prefix configured when GTK+ was compiled (unless overridden by the GTK_DATA_PREFIX environment variable), and VERSION is the GTK+ version number. If no file is found for the current version, GTK+ tries older versions all the way back to 3.0.

On Windows, with current glib, this would translate to (taking into account that 3.0 here means starting with 3.x and counting all the way down to 3.0):

  • C:/Documents and Settings/username/Local Settings/Application Data/gtk-3.0/gtk.css

Note the lack of themes and themename anywhere in this path.

  • C:/Documents and Settings/username/Local Settings/Application Data/themes/themename/gtk-3.0/gtk.css /gtk.css
  • C:/Documents and Settings/username/.themes/themename/gtk-3.0/gtk.css
  • C:/Documents and Settings/All Users/Application Data/themes/themename/gtk-3.0/gtk.css
  • C:/Documents and Settings/All Users/Documents/themes/themename/gtk-3.0/gtk.css
  • DLL prefix/share/themes/themename/gtk-3.0/gtk.css
  • exe prefix/share/themes/themename/gtk-3.0/gtk.css

You might also provide gtk-dark.css for the dark variant of the theme.

The default Adwaita theme is baked into GTK+ library, so you won't find Adwaita theme css files in any of the directories listed above. If you want to look at the CSS code for Adwaita, you'll have to download GTK+ source code - the theme will be in gtk/theme/ subdirectory.

like image 191
LRN Avatar answered Mar 18 '23 19:03

LRN