summaryrefslogblamecommitdiffstats
path: root/xrandr-notify.c
blob: fc8e60d978d857cdad92d9cac194321bacc3ad72 (plain) (tree)
























                                                                  


                                                                                 

     






                                                        











                                                                    
#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;
    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) {
        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;
}