如何在Windows 7 +和MSYS2上的GTK3上获得本机Windows装饰 [英] How to get native windows decorations on GTK3 on Windows 7+ and MSYS2

查看:290
本文介绍了如何在Windows 7 +和MSYS2上的GTK3上获得本机Windows装饰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将我的应用程序从Linux移植到Windows,并且我有一个主题问题。在Linux中,这是一个盒子,编译它,应用程序使用良好的主题,看起来很原生。

我在MSYS2中安装了gtkmm3和gtk3,并且正在使用CMake构建它。这是好的,我不得不将所有dll复制到二进制目录以便能够执行它。我没有复制任何其他东西。我试图创建解压缩和执行包。



我的问题是,该应用程序看起来不合适。它看起来不是本地的。窗口周围有阴影,在Windows10中很好,但在Windows 7中它看起来不是原生的。还有几个图标丢失。





偶数gitk3-demo以相同的方式看起来不是原生的(但它至少有正确的最小化/最大化/关闭图标)。

所以问题是:我怎样才能在Windows上实现本机GTK3应用程序的外观?或者至少是本地窗口装饰?



谢谢

解决方案

Thera有两个子问题:并设置正确的主题。



缺少图标



对于缺失的图标,它足以复制这些图标




  • window-close-symbolic.symbolic.png

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



来自: C:\msys64\mingw32\\ \\share\icons\Adwaita\22x22\actions



到:您的可执行文件夹\share\icons\\ \\Adwaita\22x22\actions



主题



使用win32原生主题



GTK3中实际上有一个内置的类似本机的主题。对于使用类似本机的主题,只需在其中创建文件您的可执行文件夹\etc\gtk-3.0\settings.ini

  [设置] 
gtk-theme-name = win32

win32主题内置于GTK3中,似乎需要前一步中的三个图标。



在Windows 7上,它看起来如下:



问题是,即使在Windows 10(包括窗口装饰)上,装饰看起来也是一样的。

来自@andlabs的评论:GTK + 3使用uxtheme.dll API来获得它的Windows外观和感觉,不幸的是微软保留了那些类似Windows 7的窗口边界。 (更多评论)



您可以在这里看到带有 win32 主题的Windows 10 Gtk3应用程序:



)。 :)为了做到这一点,你需要创建配置文件:



您的可执行文件夹\etc\gtk-3.0\settings.ini

  [设置] 
gtk-theme-name =平台

您需要将主题文件复制到可执行文件路径中的目录中



您的可执行文件夹\share\themes\Flat-Plat



在该文件夹中, index.theme 文件和 gtk-xx 文件夹应该存在。显然 gtk-theme-name 和文件夹名称应该匹配。



运行完可执行文件后,您应该能够获得不同的主题。





编辑:所以有一个win32主题内置,谢谢@andlabs



EDIT2:增加了截图



编辑3:增加了Windows 10截图并更正事实。

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.

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

解决方案

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:

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:

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.

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

EDIT2: Added screenshots

EDIT3: Added Windows 10 screenshot and corrected facts.

这篇关于如何在Windows 7 +和MSYS2上的GTK3上获得本机Windows装饰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆