/* gcc test-wm-class.c -o test-wm-class -lX11 */ /* Normally you'd use XSetClassHint() to set WM_CLASS, which ensures that it consists of 2 null terminated strings, but some applications don't and we must handle malformed WM_CLASS safely */ #include #include #include #include #include Display *d; void test(unsigned char *buffer, unsigned int buffer_length) { Window w; w = XCreateWindow(d, RootWindow(d, DefaultScreen(d)), 0, 0, 200, 200, 0, CopyFromParent, InputOutput, CopyFromParent, 0, 0); Atom wm_class = XInternAtom(d, "WM_CLASS", False); XChangeProperty(d, w, wm_class, XA_STRING, 8, PropModeReplace, buffer, buffer_length); XMapWindow(d, w); XFlush(d); sleep(1); } int main(int argc, char **argv) { d = XOpenDisplay(0); test("", 0); test("\0", 1); test("\0\0", 2); test("foo", 3); test("foo\0", 4); test("foo\0b", 5); test("foo\0bar", 7); test("foo\0bar\0", 8); while(1) sleep(1); }