16

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

kracejic
  • 723
  • 1
  • 6
  • 17
  • 1
    @oldtechaa the win32 theme in GTK+ is built into GTK+; C++ is irrelevant. The lack of images there is due to a misconfigured icon theme and is unrelated to the source code. Though I wonder how the "standard" titlebar has no icons but the GtkHeaderBar used by gtk3-demo does... – andlabs May 05 '16 at 13:21
  • 2
    On the msys2 IRC channel, raymod2 said: "He needs to copy the icons from the Adwaita them to a location his binary can find them. I put mine in a folder called "share" in the same folder as my application binary. For the icons missing in his screenshot he needs: window-close.png, window-maximize-symbolic.symbolic.png, and window-minimize-symbolic.symbolic.png to be located in share/icons/Adwaita/16x16/actions." Hope that helps. – David Grayson May 05 '16 at 17:10
  • Thank you @DavidGrayson, that was actually it for the icons. – kracejic May 05 '16 at 20:55
  • There is definitely a way to do this, because MyPaint has proper native windows decorations (not like the fake XP one below). But I can't find anywhere in the code where they actually enable that. – Timmmm Apr 28 '17 at 10:22

5 Answers5

16

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.

kracejic
  • 723
  • 1
  • 6
  • 17
  • 2
    Wait, I thought there was a `win32` theme that was still part of GTK+. I'm not sure if 3.20 removed it, though. What happens if you run your program with the theme string set to `win32` (as above)? – andlabs May 06 '16 at 03:29
  • Thank you, I somehow missed it when reading your comment on the question (I missed the fact, that the theme is built-in, but not default and that it has a name `win32`). I edited my answer to correspond more with reality. :) – kracejic May 06 '16 at 08:50
  • Out of curiosity, what do `Flat-Pat` and `win32` look like with your sample program above? – andlabs May 06 '16 at 13:39
  • @andlabs I have updated the answer with screenshots. – kracejic May 06 '16 at 18:05
  • Thanks. What do you mean by "The problem is, that it looks the same (almost) even on Windows 10 (including window decorations)."? I could try to explain anything you find odd. – andlabs May 06 '16 at 18:53
  • That the window decorations are not native-like. They look the same as on Windows 7. I understand, that this is because of the way GTK3 theming works - as I understand it only mimics the native look. So by using `win32` theme you get `win32` look which is designed to fit into win7 world, but windows 10 have different look, and `win32` theme does not fit in there. Or am I wrong? Is there any way to get really "native/system" windows decorations? – kracejic May 06 '16 at 19:35
  • 2
    Actually I think 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 (try any MDI Windows program to see). You can check the source to confirm this. I'm not sure why the buttons also look like Windows 7, though... – andlabs May 06 '16 at 19:59
  • You are right, buttons and other widget look differently, I have not noticed, I use linux as my primary operating system and really cannot tell differences between Win7's and Win10's widgets... My mistake. I have added screenshot from win10 and corrected my text. Thank you for clarification. – kracejic May 06 '16 at 21:05
  • Can a custom theme be used on OSX too? – Mörkö Sep 04 '16 at 12:40
  • 2
    This does not look Win10-ish. – Colliot Sep 07 '16 at 08:55
  • @ThéoFriberg I do not see a reason why not. The steps should not be different. – kracejic Sep 07 '16 at 08:56
  • @Colliot Yes, it does not. I did not have time to investigate this further. As andlab wrote, that he thinks, that GTK3+ uses uxtheme.dll, which was not updated by Microsoft to fit new W10 theme. – kracejic Sep 07 '16 at 09:00
6

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.

Alexander
  • 61
  • 1
  • 1
0

Actually, Gtk+3 been compatible with Windows 10 and you can use the native windows theme by making this your default theme.

gtk-theme-name = MS-Windows
BaHaa Jr.
  • 534
  • 1
  • 7
  • 19
  • 1
    Does it look modern (win10 windows decoration)? Or does it look like win32 default theme (win7ish windows decoration)? I have no access to win10 machine, so I cannot test it. :( – kracejic Mar 08 '17 at 15:55
  • This doesn't work on my Win10 machine. Where did you get this information? – Jacob May 26 '17 at 23:34
  • Doesn't work on win7 with gtk 3.22. This only works for gtk-2.0. Source:https://mail.gnome.org/archives/gtk-app-devel-list/2010-September/msg00026.html – user2740652 Apr 28 '18 at 08:38
0

For people like me who use (activestate) perl, the /share and /etc need to be placed one directory above the perl.exe (say in C:\Perl64 if perl.exe is in C:\Perl64\bin).

Guillaume
  • 61
  • 2
0

While GTK_CSD=0 is doing a fine job for windows frame icons, it seams that default Drag-And-Drop (DND) icons are missing too.

Dragging GtkEntry or GtkTreeView contents shows a drag-icon.

I've prepared a button as drag source under Gtk+-3.24.4. When dragging the button, the mouse cursor disappears and no drag icon is shown.

When using gtk_drag_source_set_icon_pixbuf(bt, pixbuf), the pixbuf appears as drag icon. But doing it this way is only half the job done, because move/copy indicators are missing on the icon.