8

When I run xprop I get a class string that has two values, one of them i3 calls an instance, the other a class, for example on chromium-browser the xprop utility will return something like this,

WM_CLASS(STRING) = "chromium-browser", "Chromium-browser"

What is the official guidance on a window and these two fields? For this they're pretty similar. Are they ever different? If so, what should I pick and why? How are GUI-authors supposed to class and instance their names?

Evan Carroll
  • 30,763
  • 48
  • 183
  • 315

1 Answers1

8

The actual behavior is defined by the spec entitled the Inter-Client Communication Conventions Manual (ICCM). Basically the class name is specified by the person who makes the app. The instance name can be specified by the user and its specified resources should override the class name specified resources.

Here is what ICCMv2 for X11r6 says on WM_CLASS,

4.1.2.5. WM_CLASS Property

The WM_CLASS property (of type STRING without control characters) contains two consecutive null-terminated strings. These specify the Instance and Class names to be used by both the client and the window manager for looking up resources for the application or as identifying information. This property must be present when the window leaves the Withdrawn state and may be changed only while the window is in the Withdrawn state. Window managers may examine the property only when they start up and when the window leaves the Withdrawn state, but there should be no need for a client to change its state dynamically.

The two strings, respectively, are:

  • A string that names the particular instance of the application to which the client that owns this window belongs. Resources that are specified by instance name override any resources that are specified by class name. Instance names can be specified by the user in an operating-system specific manner. On POSIX-conformant systems, the following conventions are used:

    • If -name NAME is given on the command line, NAME is used as the instance name.
    • Otherwise, if the environment variable RESOURCE_NAME is set, its value will be used as the instance name.
    • Otherwise, the trailing part of the name used to invoke the program (argv[0] stripped of any directory names) is used as the instance name.
  • A string that names the general class of applications to which the client that owns this window belongs. Resources that are specified by class apply to all applications that have the same class name. Class names are specified by the application writer. Examples of commonly used class names include: "Emacs", "XTerm", "XClock", "XLoad", and so on.

Note that WM_CLASS strings are null-terminated and, thus, differ from the general conventions that STRING properties are null-separated. This inconsistency is necessary for backwards compatibility.

(emphasis in bold added by me)

Quasímodo
  • 18,865
  • 4
  • 36
  • 73
Evan Carroll
  • 30,763
  • 48
  • 183
  • 315
  • hi, how does dock or panel applications group multiple instances together when they are given different WM_CLASS? I tried to start two xterm instances and each with a different instance name, And my dock( Plank) still knows they belong to the same application and group them together. – DeanSinaean Dec 15 '21 at 07:57