如何在 Gnome Shell 中设置应用程序标题?
我是 Gtk+ 开发的新手,正在尝试使用 PyGObject 和 Gtk+3.0 编写一个应用程序。然而,当我从命令行在 Gnome Shell 中运行应用程序时,出现在左上角(紧邻“活动”热角右侧)的应用程序名称仅设置为 Python 源文件的名称我跑去启动应用程序。有什么方法可以设置我的应用程序的名称出现在 Gnome Shell 中吗?我查看了 Gtk.Application,虽然它似乎做了一些我想要的事情(无论如何从 Gtk+3.3 开始),但我似乎不知道如何修复活动名称或应用程序名称。
I am new to Gtk+ development, and am trying to write an app using PyGObject and Gtk+3.0. When I run my app in Gnome Shell from the command line, however, the application name as it appears in the upper-left hand corner (immediately to the right of the Activities hot corner) is just set to the name of the Python source file that I ran to start the app. Is there any way to set the name to appear in Gnome Shell for my application? I've looked at Gtk.Application, and though it seems to do some of what I want (starting in Gtk+3.3, anyway), I can't seem to figure out how to fix the activity name or the application name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
gnome-shell 尝试将窗口与应用程序(
ShellApp
实例)匹配并使用该名称。执行此操作的代码位于: http://git.gnome .org/browse/gnome-shell/tree/src/shell-window-tracker.c#n328但是,如果它无法找到窗口的
ShellApp
,那么它会回退到使用ICCCM指定WM_CLASS
(规范位于 http://tronche. com/gui/x/icccm/sec-4.html#s-4.1.2.5)这里:http://git.gnome.org/browse/gnome-shell/tree/ src/shell-app.c#n361因此,如果您没有安装 .desktop 文件来查找应用程序名称,那么您将获得默认的
WM_CLASS
出现在其中。 GTK 根据可执行文件名称自动生成。您可以在实现窗口之前(这意味着在窗口上调用_show
之前)使用gtk_window_set_wmclass()
覆盖它。这是一个简单的示例,将显示为“Hello World” 。不要忘记设置窗口标题!
gnome-shell tries to match the window to an an app (a
ShellApp
instance) and use that name. The code do that is here: http://git.gnome.org/browse/gnome-shell/tree/src/shell-window-tracker.c#n328But if it fails to find
ShellApp
for the window then it falls back to using the ICCCM specifiedWM_CLASS
(spec is at http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.2.5) here: http://git.gnome.org/browse/gnome-shell/tree/src/shell-app.c#n361So if you're not installing a .desktop file for it to find the application name from you'll get the default
WM_CLASS
appearing in there. GTK automatically generates based on the executable name. You can override that before the window is realized (this means before calling_show
on the window) usinggtk_window_set_wmclass()
Here is a simple example that will appear as "Hello World". Don't forget to set a window title too!
2023 年和 GTK4 的答案:
set_wmclass
已弃用。要在 Gnome shell 顶部栏中获取自定义名称,您可以使用set_prgname
(C 链接,Vala),请注意set_application_name
不会更改顶栏中的名称。这是 Vala 中的一个示例:
构建:
An answer from 2023 and GTK4:
set_wmclass
is deprecated. To get a custom name in the Gnome shell topbar you can useset_prgname
(link for C, link for Vala), note thatset_application_name
won't change the name in the topbar.Here is an example in Vala:
To build: