Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to port my application from linux to windows and I have a problem with theming. In linux this works out of a box, just compile it and application is using good theme and looks native.

I have installed gtkmm3 and gtk3 in MSYS2 and I am building it with CMake. This is OK, I had to copy all dlls to directory with binary to be able to execute it. I did not copy anything else. I am trying to create "unzip and execute" package.

My problem is, that application looks out of place. It does not look native at all. There are shadows around the window, which is fine in Windows10, but in Windows 7 it looks not native. Also several icons are missing.

bad gtk3 application theme on Windows10

Even gitk3-demo looks non-native in the same way (but it has at least the minimize/maximize/close icons correct).

So the question is: How can I achieve native look of GTK3 application on Windows? Or at least native window decorations?

Thanks

like image 427
kracejic Avatar asked May 04 '16 19:05

kracejic


People also ask

Can GTK be used on Windows?

GTK can be also run on Microsoft Windows, where it is used by some popular cross-platform applications like Pidgin and GIMP. wxWidgets, a cross-platform GUI tool-kit, uses GTK on Linux by default.

How do I make my own GTK theme?

To create a GTK3 theme, developers can start with an empty file or they can use a pre-existing theme as a template. It may help beginners to start with a pre-existing theme. For instance, a theme can be copied to the user's home folder and then the developer can start editing the files.

How do I choose GTK theme?

Search for gnome-tweak-tool or Advanced Settings (as it is named) in the Unity dash and open the tool. Move to 'Theme' option on the left sidebar. You can now change the GTK+ theme by changing the options in the dropdown list.


2 Answers

You can set GTK_CSD=0 environment variable to disable client-side window decorations and enable Windows native decorations, which gets rid of the ugly win7-like titlebar, as well as Adwaita-like one.

like image 40
Alexander Avatar answered Oct 11 '22 13:10

Alexander


Thera are two sub-problems: missing icons and setting right theme.

Missing icons

For missing icons it was enough to copy these icons

  • window-close-symbolic.symbolic.png
  • window-maximize-symbolic.symbolic.png
  • window-minimize-symbolic.symbolic.png

from: C:\msys64\mingw32\share\icons\Adwaita\22x22\actions

to: "your executable folder"\share\icons\Adwaita\22x22\actions

Theme

Using win32 native theme

There is actually a built-in native-like theme in GTK3. For using native-like theme just create file "your executable folder"\etc\gtk-3.0\settings.ini with this in it

[Settings]
gtk-theme-name=win32

win32 theme is built in into GTK3 and only three icons from previous step seems to be needed.

On windows 7 this looks as following:

enter image description here

The problem is, that the decorations looks the same even on Windows 10 (including window decorations).

From comment from @andlabs : GTK+ 3 uses the uxtheme.dll APIs to get its Windows look and feel, and unfortunately Microsoft has kept those Windows 7-like for window borders. (more in comments)

You can see Windows 10 Gtk3 application with win32 theme here:

enter image description here

Using non default theme

And if you are not happy with default or win32 theme, you can use custom themes (like this Flat-Pat) from the internet. :) In order to do it you need to create config file:

"your executable folder"\etc\gtk-3.0\settings.ini with this in it

[Settings]
gtk-theme-name=Flat-Plat

and you need to copy the theme files to directory in path of your executable

"your executable folder"\share\themes\Flat-Plat

in that folder, the index.theme file and gtk-x.x folders should be present. Obviously gtk-theme-name and folder name should match.

After you run the executable you should be able to get different theme.

enter image description here

EDIT: So there is a win32 theme built-in, thank you @andlabs

EDIT2: Added screenshots

EDIT3: Added Windows 10 screenshot and corrected facts.

like image 120
kracejic Avatar answered Oct 11 '22 13:10

kracejic