Skip to content

Instantly share code, notes, and snippets.

@tgr
Created September 8, 2016 16:28
Show Gist options
  • Save tgr/eae411cefde08cbed5c59d4f51ddb062 to your computer and use it in GitHub Desktop.
Save tgr/eae411cefde08cbed5c59d4f51ddb062 to your computer and use it in GitHub Desktop.
#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 != 3 ) {
printf( "Usage: %s <window id> <window class>\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 );
class.res_class = strdup( argv[2] );
printf("Setting WM_CLASS of window %lu to \"%s\", \"%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;
}
@tgr
Copy link
Author

tgr commented Sep 8, 2016

Set the class part of WM_CLASS for a given window id in X. Apparently there is no command-line tool to do this: xprop can set the first half (the name) but not the second part (the class).

@piegamesde
Copy link

Hi, thanks for this neat little script. To really separate the windows, you need to set class.res_name too so I added this in a fork.

@Fmstrat
Copy link

Fmstrat commented Nov 11, 2020

You could just use xdotool..

apt install -y xdotool
xdotool search --name "Title of App" set_window --class "New WM Class"

@tgr
Copy link
Author

tgr commented Nov 11, 2020

Thanks @Fmstrat! Copied that to the StackOverflow question that prompted this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment