/* * Copyright 2008 Red Hat, Inc. * * MIT licensed. See: http://www.opensource.org/licenses/mit-license.php * * gcc -std=c99 -o xrrprimary xrrprimary.c -lXrandr -lXext -lX11 */ #include #include #include #include #include #include #include #include #include #include int main(int argc, char **argv) { Display *dpy = XOpenDisplay(NULL); XRRScreenResources *rr; XRROutputInfo *oi; XSynchronize(dpy, 1); if (argc == 1) { printf("usage: xrrprimary [get | set output]\n"); return 1; } rr = XRRGetScreenResources(dpy, DefaultRootWindow(dpy)); if (argc == 2 && !strcmp(argv[1], "get")) { RROutput output = XRRGetOutputPrimary(dpy, DefaultRootWindow(dpy)); if (output) { oi = XRRGetOutputInfo(dpy, rr, output); printf("%s (0x%x)\n", oi->name, output); XRRFreeOutputInfo(oi); } else { printf("None\n"); } } if (argc == 3 && !strcmp(argv[1], "set")) { RROutput output; if (isalpha(argv[2][0])) { /* it's a name */ for (int i = 0; i < rr->noutput; i++) { oi = XRRGetOutputInfo(dpy, rr, rr->outputs[i]); if (!strcmp(oi->name, argv[2])) output = rr->outputs[i]; XRRFreeOutputInfo(oi); } } else { /* it's an XID */ output = strtol(argv[2], NULL, 0); } if (output) XRRSetOutputPrimary(dpy, DefaultRootWindow(dpy), output); } XSync(dpy, 1); XCloseDisplay(dpy); return 0; }