4

I am trying to make my GTK3 application look native on Windows 7. I tried the answer in the following question How to get native windows decorations on GTK3 on Windows 7+ and MSYS2

But it doesn't work. My GTK3 version on windows is 3.22 and I am using the Vala language. Tried with GTK3 version 3.20 to no avail either. I also tried changing the background color of the application in the code itself with the CssProvider and it works in Ubuntu, but not in Windows. In Windows, the application theme and all CSS manual settings are ignored.

Is there any way to achieve this? Thanks.

g_l
  • 621
  • 5
  • 15

1 Answers1

4

It worked by calling in the code, before displaying the main application window with show_all () :

Gtk.Settings.get_default ().gtk_theme_name = "win32";

When using a custom theme, the location of the theme should be: "YourApplicationExecutable\share\themes\ThemeFolder" as per described in the accepted answer of How to get native windows decorations on GTK3 on Windows 7+ and MSYS2

and the name set with gtk_theme_name in the code should be the name of the folder containing the theme.

Note that the method get_default () gets you the default GDK screen. If you want more control over specific widgets, use instead the method get_settings () over the specific widget that you want to change the theme for.

Sources:

How to get native windows decorations on GTK3 on Windows 7+ and MSYS2

https://valadoc.org/gtk+-3.0/Gtk.CssProvider.html

https://valadoc.org/gtk+-3.0/Gtk.Settings.html

g_l
  • 621
  • 5
  • 15
  • 1
    Although, the CSSProvider manually set settings to change specific parts like the background color are still being ignored on Windows. I can for example, using this method, change the theme in Ubuntu as well and have a custom background override the theme background, but in Windows it gets ignored and no CSS overriding happens. – g_l May 10 '17 at 09:22
  • 1
    Looks like applied CSS selectors and properties change between GTK versions and therefore, it worked in Ubuntu, but not in Windows. Because Ubuntu 16.04 has GTK 3.18 while Windows has GTK 3.22 as of the moment of writing this. So my CSSProvider was right, but because the way of changing the background color is different in different versions, it worked in one OS, but not in the other. I fixed it by using ".background" selector with "background-color" property, instead of using the "GtkWindow" selector with "background" property because the latter doesn't work in GTK 3.20 or higher. – g_l May 10 '17 at 11:37