From fbd6f18c2d703857d372fa2b23478775f0cf1efa Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Sun, 8 Jul 2012 02:07:33 +0200 Subject: Initial commit --- .gitignore | 1 + Makefile | 7 +++++++ xrandr-notify.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 xrandr-notify.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9080e5e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +xrandr-notify diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a12808a --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +TARGETS:= xrandr-notify +LDFLAGS:=-lX11 -lXrandr + +all: $(TARGETS) + +clean: + $(RM) $(TARGETS) diff --git a/xrandr-notify.c b/xrandr-notify.c new file mode 100644 index 0000000..3c1ad52 --- /dev/null +++ b/xrandr-notify.c @@ -0,0 +1,46 @@ +#include +#include +#include + +#include +#include + +int main(int argc, char **argv) +{ + Display *dpy; + Window root; + XEvent event; + int dummy, screen, randr_event_base; + bool has_randr; + + dpy = XOpenDisplay(NULL); + if (dpy == NULL) { + fputs("ERROR: Could not open display!\n", stderr); + return EXIT_FAILURE; + } + + /* Is the randr extension available? */ + has_randr = false; + has_randr = XRRQueryExtension(dpy, &randr_event_base, &dummy); + + if (has_randr) { + /* Get root window */ + screen = DefaultScreen(dpy) ; + root = RootWindow(dpy, screen) ; + + /* Notify on configuration change */ + XRRSelectInput(dpy, root, RRScreenChangeNotifyMask); + } + + while (true) { + XNextEvent(dpy, &event); + + if (event.type == randr_event_base + RRScreenChangeNotify) { + return EXIT_SUCCESS; + } + } + + /* should never happen */ + return EXIT_FAILURE; +} + -- cgit v1.2.3