如何在Gnome Shell中设置应用程序标题? [英] How to set application title in Gnome Shell?

查看:111
本文介绍了如何在Gnome Shell中设置应用程序标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Gtk +开发新手,尝试使用PyGObject和Gtk + 3.0编写应用程序。但是,当我从命令行在Gnome Shell中运行我的应用程序时,应用程序名称显示在左上角(即活动热点右侧),只是设置为Python源文件的名称我跑了启动应用程序。有什么方法可以将名称设置为在我的应用程序中出现在Gnome Shell中?我已经看过Gtk.Application,虽然它似乎做了我想要的一些东西(无论如何,从Gtk + 3.3开始),但我似乎无法弄清楚如何修复活动名称或应用程序名称。 / p>

解决方案

gnome-shell尝试将窗口与应用程序匹配(a ShellApp instance)并使用该名称。代码是这样的: http://git.gnome .org / browse / gnome-shell / tree / src / shell-window-tracker.c#n328

但如果找不到 ShellApp 作为窗口,然后返回使用指定的 WM_CLASS 的I​​CCCM(spec位于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。不要忘记设置一个窗口标题!

 #!/ usr / bin / python 
from gi。存储库导入Gtk
$ b $ win = Gtk.Window()
win.connect(delete-event,Gtk.main_quit)
win.set_wmclass(Hello World, Hello World)
win.set_title(Hello World)
win.show_all()
Gtk.main()


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.

解决方案

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#n328

But if it fails to find ShellApp for the window then it falls back to using the ICCCM specified WM_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#n361

So 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) using gtk_window_set_wmclass()

Here is a simple example that will appear as "Hello World". Don't forget to set a window title too!

#!/usr/bin/python
from gi.repository import Gtk

win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.set_wmclass ("Hello World", "Hello World")
win.set_title ("Hello World")
win.show_all()
Gtk.main()

这篇关于如何在Gnome Shell中设置应用程序标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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