command line - Constantly checking if display is working on Linux -


is there possibility check if display(monitor) working or not , import data code? assume there command-line tricks or devices 'leak' info it. using linux.

you can use x11 extension xrandr (x resolution , rotation or that).

you can see status of output displays command xrandr. in pc example get:

$ xrandr | grep connected dvi-i-0 disconnected (normal left inverted right x axis y axis) dvi-i-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 531mm x 299mm .... 

the names of outputs device specific, of course.

if want access data c program, xrandr extension easy enough program. sample code print connection status of outputs (error checking omitted):

#include <x11/xlib.h> #include <x11/extensions/xrandr.h> #include <stdio.h>  int main() {     display *dsp = xopendisplay(null);     window root = xrootwindow(dsp, 0);     xrrscreenresources *sres = xrrgetscreenresources(dsp, root);     printf("n outputs %d\n", sres->noutput);     (int = 0; < sres->noutput; ++i)     {         xrroutputinfo *info = xrrgetoutputinfo(dsp, sres, sres->outputs[i]);         printf("  %d: '%s' %s\n", i, info->name, info->connection == rr_connected ? "connected" : "");         xrrfreeoutputinfo(info);      }     xrrfreescreenresources(sres);     xclosedisplay(dsp);     return 0; } 

if want real-time notification of changes can use xrroutputchangenotifyevent x event, bit more complicated: need event loop or use widget toolkit , hook x event handler...


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -