0

I have a few instances (windows) of the same program. Of course, Gnome will group them and handle them as multiple windows of the same application. Grouping affects the task panel that I use, but also things like icons and Alt+Tab.

Not that rarely, it may happen that I have two windows of the same application that should not be treated as two instances of the same, but as fundamentally different. So I do not want to group them. This may affect the following applications in practice:

  • Eclipse (If I have multiple different Eclipse installations)
  • Many Java applications
  • Same for C# applications due to Mono
  • Running chromium as standalone with --app
  • ...

I do not care how this may be achieved and I am willing to put greater amounts of effort to achieve this goal since it is a major annoyance on a daily basis. I am using Gnome with the Dash-To-Panel addon, solutions may be specific to that setup or more broad.


What I tried so far: I tried manipulating the WM_CLASS property of the windows, but it does not really work because the property seems more to be used to group windows, not to ungroup them. Furthermore, the WM does not really always respect the StartupWMClass property in desktop files and the xprop command is not that useful.

piegames
  • 975
  • 12
  • 31
  • Warning: When writing this question, I had fundamentally wrong assumptions about how the `StartupWMClass` works. Setting it won't change the WM class of the application. It is only to tell the window manager how to associate a window to its desktop file. – piegames Jun 28 '20 at 11:08

2 Answers2

0

So I finally found a hacky workaround to resolve this problem.

the property seems more to be used to group windows, not to ungroup them.

This was a false assumtion. The truth is that the WM_CLASS is a tuple consisting of a res_name and a res_class (RTFM). The latter one is usually referred to as the WM_CLASS and is also the one you change normally.

So I extended the code from this answer to a very similar question to change the res_name as well:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

int main(int argc, char *argv[])
{
    unsigned long value;
    char *terminatedAt;
    XClassHint class;
    Status status;
    Display *display;
    Window window;

    if ( argc != 4 ) {
        printf( "Usage: %s <window id> <window class> <application name>\n", argv[0] );
        return 1;
    }
    window = strtoul( argv[1], &terminatedAt, 0 );
    if ( *terminatedAt != '\0' ) {
        printf( "Could not parse window id: %s\n", argv[1] );
        return 2;
    }

    display = XOpenDisplay( NULL );
    status = XGetClassHint( display, window, &class );
    if ( !status ) return 4;

    XFree( class.res_class );
    XFree( class.res_name );
    class.res_class = strdup( argv[2] );
    class.res_name = strdup( argv[3] );
    printf("Setting WM_CLASS of window %lu to res_name=\"%s\", res_class=\"%s\"\n", window, class.res_name, class.res_class );
    XSetClassHint( display, window, &class );

    XCloseDisplay( display );
    XFree( class.res_name );
    XFree( class.res_class );
    return 0;
}

Compile it with gcc set_wm_class.c -lX11 -o set_wm_classand use xdotool getactivewindow to get the required WID.


By the way I am open to less hacky solutions. I will award a bounty of 100 reputation for a way to set the full WM_CLASS using xprop -set and thus making this script obsolete.

piegames
  • 975
  • 12
  • 31
0

You can now 'disable' the alt-tab grouping in Gnome. In your Gnome keybindings, change the keybinding from 'Switch applications' to 'Switch windows'.

https://blogs.gnome.org/fmuellner/2018/10/11/the-future-of-alternatetab-and-why-you-need-not-worry/

Joost
  • 3,169
  • 2
  • 22
  • 40