// xfocus.c - print the current X input focus and the gzdoom window, and try // to focus the gzdoom window; then report again. Diagnostic for WM-less X. #include #include #include #include static Window find_named(Display *d, Window root, const char *sub, char *title, size_t tl) { Window r, parent, *kids = NULL; unsigned int nk = 0; title[0] = 0; if (!XQueryTree(d, root, &r, &parent, &kids, &nk)) return 0; for (unsigned int i = 0; i < nk; i++) { char *name = NULL; if (XFetchName(d, kids[i], &name) && name) { if (strstr(name, sub)) { snprintf(title, tl, "%s", name); Window w = kids[i]; XFree(name); if (kids) XFree(kids); return w; } XFree(name); } } if (kids) XFree(kids); return 0; } int main(void) { Display *d = XOpenDisplay(NULL); Window root, focus, w, croot; int rx, ry, wx, wy; unsigned int mask; char title[256]; if (!d) { printf("no display\n"); return 1; } root = DefaultRootWindow(d); w = find_named(d, root, "Freedoom", title, sizeof(title)); XGetInputFocus(d, &focus, &rx); printf("gzdoom window: 0x%lx '%s'\n", w, title); printf("input focus: 0x%lx\n", focus); printf("pointer window: "); if (XQueryPointer(d, root, &croot, &rx /*reuse*/, &wx, &wy, &rx, &ry, &mask)) printf("0x%lx at %d,%d mask=0x%x\n", rx, wx, wy, mask); else printf("query failed\n"); if (w) { XSetInputFocus(d, w, RevertToParent, CurrentTime); XFlush(d); XGetInputFocus(d, &focus, &rx); printf("after set: 0x%lx\n", focus); } XCloseDisplay(d); return 0; }