From 9b8e9fab044c99eb3e93c52d0d0f64b1f0d85be0 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sat, 1 Oct 2016 15:42:05 -0400 Subject: rotating screen via libXrandr --- Makefile | 1 + autorotate.c | 39 ++++++++++++++++++++------------------- 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 +#include +#include #include #include #include #include -#include -#include -#include +#include #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; -- cgit v1.2.1