4

Introduction

In order to group several instances of a given application under one icon in the desktop launcher (I am using Ubuntu 17.04) they must have the same appName property of the WM_CLASS string. For example, if I run emacs twice:

$ emacs &
$ emacs &

Both instances will show up under the Emacs icon in the desktop launchbar. The reason is that both instances have the same WM_CLASS string. We can check this string using

$ xprop WM_CLASS

and then click on the Emacs window. It then shows:

WM_CLASS(STRING) = "emacs", "Emacs"

Here "emacs" is the resource (appName), and "Emacs" is the className, see xdotool: what are “class” and “classname” for a window? for more information.

Question

Consider this program (my-tkapp.py):

#! /usr/bin/env python
import tkinter as tk
root = tk.Tk(className='myTkApp')
label = tk.Label(root, text="Hello World")
label.pack()
root.mainloop()

If I run this program twice:

$ my-tkapp.py &
$ my-tkapp.py &

and then run xprop to check the WM_CLASS property of both windows, the first window gives:

WM_CLASS(STRING) = "myTkApp", "Mytkapp"

whereas the second gives:

WM_CLASS(STRING) = "myTkApp #2", "Mytkapp"

Note that tkinter has added a #2 suffix to the app name property. This is not desired. It makes the window manager group the two windows under separate icons in the desktop launch bar.

How can I keep the same appName property of the WM_CLASS string for different instances of my application?

See also

How to add launcher icon for python script?

Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174

2 Answers2

1

This is tkinters behavior by default. The className must be unique in order to work with tkinter.send and is documented as appname.

If newName is not specified, this command returns the name of the application (the name that may be used in send commands to communicate with the application). If newName is specified, then the name of the application is changed to newName. If the given name is already in use, then a suffix of the form “ #2” or “ #3” is appended in order to make the name unique. The command's result is the name actually chosen. newName should not start with a capital letter. This will interfere with option processing, since names starting with capitals are assumed to be classes; as a result, Tk may not be able to find some options for the application. If sends have been disabled by deleting the send command, this command will reenable them and recreate the send command.

Use wm_group instead. Also see this Q&A for dialog windows

Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
-1

While the first string does add the suffix, if you use the second string the "Mytkapp" in your configuration, it will apply to all versions of the app that are running.

mrk
  • 8,059
  • 3
  • 56
  • 78