Simple program to show info about active X11 servers and screens.
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <X11/Xlib.h>
int main(void) {
DIR* d = opendir("/tmp/.X11-unix");
if (d != NULL) {
struct dirent *dr;
while ((dr = readdir(d)) != NULL) {
if (dr->d_name[0] != 'X')
continue;
char display_name[64] = ":";
strcat(display_name, dr->d_name + 1);
Display *disp = XOpenDisplay(display_name);
if (disp != NULL) {
int count = XScreenCount(disp);
// printf("Display %s has %d screens\n",
// display_name, count);
int i;
for (i=0; i<count; i++)
printf("%s.%d %dx%d\n",
display_name, i, XDisplayWidth(disp, i), XDisplayHeight(disp, i));
XCloseDisplay(disp);
}
}
closedir(d);
}
return 0;
}
Usage:
curl -SsL https://gist.githubusercontent.com/zubatyuk/df94ca36cb53f506bed1/raw/Makefile && make
Makefile
and x11screens.c
files in current dirCC = gcc
CFLAGS = -g -Wall
LIBS = -lX11
INSTALLPATH = /usr/local/bin
TARGET = x11screens
SOURCE = x11screens.c
OBJECTS = x11screens.o
$(TARGET) : $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) -o $(TARGET) $(LIBS)
%.c :
curl -SsL -O https://gist.github.com/zubatyuk/df94ca36cb53f506bed1/raw/x11screens.c
%.o : %.c
$(CC) $(CFLAGS) -c $<
all: $(TARGET)
clean:
$(RM) $(OBJECTS) $(TARGET)
install: $(TARGET)
install $(TARGET) $(INSTALLPATH)
dummy file