initial commit

This commit is contained in:
Sam 2024-10-12 12:20:01 +01:00
commit b39fb4b360
2 changed files with 66 additions and 0 deletions

26
Makefile Normal file
View File

@ -0,0 +1,26 @@
PREFIX := /usr/local
CC := cc
LDFLAGS := -lX11
all: options set_wm_class
options:
@echo set_wm_class build options:
@echo "LDFLAGS = ${LDFLAGS}"
@echo "CC = ${CC}"
set_wm_class: set_wm_class.c
${CC} -o set_wm_class set_wm_class.c ${LDFLAGS}
clean:
rm -f set_wm_class
install: set_wm_class
mkdir -p ${DESTDIR}${PREFIX}/bin
cp -f set_wm_class ${DESTDIR}${PREFIX}/bin
chmod 755 ${DESTDIR}${PREFIX}/bin/set_wm_class
uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/set_wm_class
.PHONY: all options clean install uninstall

40
set_wm_class.c Normal file
View File

@ -0,0 +1,40 @@
#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;
}