You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.0 KiB
C
46 lines
1.0 KiB
C
4 years ago
|
#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 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;
|
||
|
}
|