Skip to content

Instantly share code, notes, and snippets.

View christian-eriksson's full-sized avatar

Christian Eriksson christian-eriksson

View GitHub Profile
@christian-eriksson
christian-eriksson / window_finder_bash.sh
Last active January 24, 2022 23:23
Script using xprop and grep to look for a provided (as cmd-line argument) WM_CLASS. The script identifies a window which has a grandparent with 2 children somewhere in it's tree.
#!/bin/bash
# The script is looking for a window with a given WM_CLASS property. The window
# will be attached to the root node (R in the graph below), the root note is
# what you get from 'xprop -root'. There are two different types of windows with
# the same WM_CLASS (Q and W) but their tree structures are different. However,
# the tree structure of the two windows are different as seen in the graph
# below.
#
# R
@christian-eriksson
christian-eriksson / window_finder_timer.cpp
Last active January 24, 2022 23:23
Will find a window with the WM_CLASS (eg. Firefox) provided as an argument when starting the program. We detect when a window of the provided WM_CLASS is shown by investigating the tree of the shown window. A short pause is used to allow for the tree creation to be completed before fetching the tree.
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <assert.h>
#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
@christian-eriksson
christian-eriksson / window_finder_events.cpp
Last active January 24, 2022 23:23
Will find a window with the WM_CLASS (eg. Firefox) provided as an argument when starting the program. We detect when a window of the provided WM_CLASS is created and follow some events such as reparenting and destruction.
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <assert.h>
#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;