summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jakob@kaivo.net>2016-10-01 15:42:05 -0400
committerJakob Kaivo <jakob@kaivo.net>2016-10-01 15:42:05 -0400
commit9b8e9fab044c99eb3e93c52d0d0f64b1f0d85be0 (patch)
treee8e382f7c4e454a280db805a34f769e885d95ab7
parente90964c7e492a1308848ee6106626bd2a838fe77 (diff)
rotating screen via libXrandr
-rw-r--r--Makefile1
-rw-r--r--autorotate.c39
2 files changed, 21 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index abb7686..7754dd0 100644
--- a/Makefile
+++ b/Makefile
@@ -1 +1,2 @@
+LDLIBS=-lXrandr -lX11
autorotate: autorotate.c
diff --git a/autorotate.c b/autorotate.c
index b916a64..4a80ce8 100644
--- a/autorotate.c
+++ b/autorotate.c
@@ -1,11 +1,12 @@
#define _XOPEN_SOURCE 700
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <X11/extensions/Xrandr.h>
#define ACPID_SOCK_PATH "/var/run/acpid.socket"
@@ -27,6 +28,21 @@ int tabletmode = 0;
int rotatelock = 0;
enum rotation { NORMAL, INVERSE, LEFT, RIGHT };
+void rotatescreen(enum rotation r)
+{
+ Rotation xr[] = { RR_Rotate_0, RR_Rotate_180, RR_Rotate_90, RR_Rotate_270 };
+ static Display *dpy = NULL;
+ if (dpy == NULL) {
+ dpy = XOpenDisplay(NULL);
+ }
+ static Window root = 0;
+ if (root == 0) {
+ root = RootWindow(dpy, DefaultScreen(dpy));
+ }
+ XRRScreenConfiguration *xsc = XRRGetScreenInfo(dpy, root);
+ XRRSetScreenConfig(dpy, xsc, root, 0, xr[r], CurrentTime);
+}
+
enum rotation setrotation(enum rotation r)
{
static enum rotation prev = NORMAL;
@@ -34,22 +50,7 @@ enum rotation setrotation(enum rotation r)
return r;
}
- switch (r) {
- case NORMAL:
- system("xrandr -o normal");
- break;
- case INVERSE:
- system("xrandr -o inverted");
- break;
- case LEFT:
- system("xrandr -o left");
- break;
- case RIGHT:
- system("xrandr -o right");
- break;
- default:
- break;
- }
+ rotatescreen(r);
prev = r;
return r;