How to set application title in Gnome Shell?

别说谁变了你拦得住时间么 提交于 2020-01-11 01:49:05

问题


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.


回答1:


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()


来源:https://stackoverflow.com/questions/9324163/how-to-set-application-title-in-gnome-shell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!