// SPDX-License-Identifier: BSD-3-Clause // xresize.c - find a window by name substring and resize/move it (Xvfb has // no WM, so a client-side XMoveResizeWindow is the only way to force the // game window onto the screen). // Usage: xresize #include #include #include #include #include static Window find_named(Display *d, Window root, const char *sub) { Window r, parent, *kids = NULL; unsigned int nkids = 0; if (!XQueryTree(d, root, &r, &parent, &kids, &nkids)) return 0; for (unsigned int i = 0; i < nkids; i++) { char *name = NULL; if (XFetchName(d, kids[i], &name) && name) { int hit = strstr(name, sub) != NULL; XFree(name); if (hit) { Window w = kids[i]; if (kids) XFree(kids); return w; } } } if (kids) XFree(kids); return 0; } int main(int argc, char **argv) { Display *d; Window w; if (argc < 6) { fprintf(stderr, "usage: xresize \n"); return 2; } d = XOpenDisplay(argv[1]); if (!d) { fprintf(stderr, "no display\n"); return 1; } w = find_named(d, DefaultRootWindow(d), argv[2]); if (!w) { fprintf(stderr, "window '%s' not found\n", argv[2]); return 1; } XMoveResizeWindow(d, w, atoi(argv[5]), atoi(argv[6]), atoi(argv[3]), atoi(argv[4])); XFlush(d); printf("resized 0x%lx to %sx%s at %s,%s\n", w, argv[3], argv[4], argv[5], argv[6]); XCloseDisplay(d); return 0; }