10

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.

Dan D.
  • 73,243
  • 15
  • 104
  • 123
Chris Granade
  • 913
  • 7
  • 21

1 Answers1

16

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()
Rob Bradford
  • 1,440
  • 12
  • 17
  • 3
    For posterity: GNOME Shell shows the final argument to `set_wmclass` in the top bar. – wjt Mar 05 '13 at 00:08
  • 1
    Ironically it says "Don’t use this function." in the [GTK docs](https://developer.gnome.org/gtk3/stable/GtkWindow.html#gtk-window-set-wmclass). However, I would recommend using it. – JayStrictor Mar 24 '16 at 14:54
  • This function is deprecated without replacement as of Gtk+ 3.22. – Daniel Jul 14 '17 at 00:10
  • 2
    2018 here. GNOME Shell [still fallbacks](https://gitlab.gnome.org/GNOME/gnome-shell/blob/gnome-3-30/src/shell-app.c#L270) to using the ICCCM specified `WM_CLASS`. Its behavior hasn't changed from GNOME 3.14 to GNOME 3.30 but for GNOME 3.32 there is an initiative to [retire application menus](https://blogs.gnome.org/aday/2018/10/09/farewell-application-menus/) entirely. `gtk_window_set_wmclass` may be deprecated but using it doesn't produce a deprecation notice (in `Python` at least) and even if it did I would still recommend using it. – Fake Code Monkey Rashid Oct 19 '18 at 00:06