|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/extensions/Xrandr.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <err.h>
|
|
|
|
|
|
|
|
void test_and_fail(void *ptr, char *msg) {
|
|
|
|
if (ptr == NULL) {
|
|
|
|
fprintf(stderr, "Fatal error: %s\n", msg);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int rol4 (int x) {
|
|
|
|
// Just rotate left by 1 bit
|
|
|
|
int num = x & 0xf;
|
|
|
|
int sh = num << 1;
|
|
|
|
int overflow = (sh & 0x10) >> 4;
|
|
|
|
return (sh & 0xf) | overflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = rol4(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;
|
|
|
|
}
|