0

In a C or C++ program, what is the best way to connect to all X displays on a computer? I would like to check the X idle time of each display, to determine whether the computer is idle across all displays.

My current way of doing it is to put a filesystem watch on /tmp/.X11-unix to detect new X sockets. When a new display is detected, it waits a few seconds, then tries to connect to it. Usually, this will fail, since the process doesn't have permissions to access the display. So, to fix this, I added xhost +SI:localuser:root to the GDM presession script (display-setup-script for LightDM). This seems to work most of the time.

However, this method fails every so often, and I don't know why. I'm guessing this is because the xhost command is not reliable. I'm considering extracting the Xauthority cookie from each individual display, but I cannot find any reliable/portable way of doing so.

  • You didn't describe your method precisely but it sounds like it would have a race condition between running xhost +… and your monitor trying to connect. Why don't you have the monitor retrieve the cookie from where GDM puts the cookie file? – Gilles Jan 13 '15 at 23:25
  • Okay. So maybe I could find the process cmdline for a particular display's Xorg process. That should show where the authorization cookie is located. I suppose I'd have to switch to xcb instead of xlib; I can't see any way to provide an authorization cookie from xlib. – Azmisov Jan 15 '15 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.