From c50699315bb84a1645a94c56012885686a6eea7c Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Tue, 8 Sep 2020 15:22:24 +0200 Subject: [PATCH] Add the source code --- dirot.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 dirot.c 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; +}