summaryrefslogtreecommitdiffstats
path: root/xrandr-notify.c
blob: dc0e65fba04a1ad8a69555a2be3700babe765087 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>

#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>

int main(int argc, char **argv)
{
    Display *dpy;
    Window root;
    XEvent event;
    int dummy, screen, randr_event_base;

    dpy = XOpenDisplay(NULL);
    if (dpy == NULL) {
        fputs("ERROR: Could not open display!\n", stderr);
        return EXIT_FAILURE;
    }

    /* Is the randr extension available? */
    if (!XRRQueryExtension(dpy, &randr_event_base, &dummy)) {
        fputs("ERROR: RandR extension unavailable on current screen!\n", stderr);
        return EXIT_FAILURE;
    }

    /* 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;
}