How to observe changes in connected monitors via Xlib?

x11, xlib, xrandr

Solution

Xev's source code:

- http://cgit.freedesktop.org/xorg/app/xev/tree/

Or:

- `git clone git://anongit.freedesktop.org/xorg/app/xev`

Problem

I'm trying to write a program that would detect external monitors being plugged in and automatically enable and configure them through Xlib. I know that there is XRandr extension that allows this. My question is, how do I enable receiving XRandr events to my application? What event mask should I use? I know that xev app is able to do this.

Original source