diff --git a/dirot.c b/dirot.c new file mode 100644 index 0000000..bdb1246 --- /dev/null +++ b/dirot.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include + +void test_and_fail(void *ptr, char *msg) { + if (ptr == NULL) { + fprintf(stderr, "Fatal error: %s\n", msg); + exit(2); + } +} + +int ror4 (int x) { + // Just rotate right by 1 bit + int num = x & 0xf; + int lowbit = x & 0x1; + return (num >> 1) | (lowbit << 3); +} + +int main (void) { + Display *dpy = XOpenDisplay(NULL); + test_and_fail(dpy, "Could not open display"); + + int screen_number = XDefaultScreen(dpy); + Screen *screen = XDefaultScreenOfDisplay(dpy); + Window root = XRootWindow(dpy, screen_number); + + // TODO: Early check that RandR is supported by dpy + + Rotation current; + Rotation all; + all = XRRRotations(dpy, screen_number, ¤t); + + Rotation new = ror4(current); + + Time cfg_ts; + Rotation cfg_rot; + XRRScreenConfiguration *cfg = XRRGetScreenInfo(dpy, root); + XRRSetScreenConfig(dpy, cfg, root, XRRConfigCurrentConfiguration(cfg, &cfg_rot), new, XRRConfigTimes(cfg, &cfg_ts)); + + XRRFreeScreenConfigInfo(cfg); + return 0; +}