#include #include #include #include #include #include #include #include #include #include #include #include "get-edid.h" int verbose = 0; int main(int argc, char **argv) { char edid[(1 + MAX_EXTENSION_COUNT) * EDID_BLOCK_SIZE]; int try_in_console = 0; int skip_vbe_check = 0; int port = 0; int i; for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (strcmp(arg, "-v") == 0) verbose = 1; else if (strcmp(arg, "--port") == 0 && i+1 < argc) port = atoi(argv[++i]); else if (strcmp(arg, "--try-in-console") == 0) try_in_console = 1; else if (strcmp(arg, "--skip-vbe-check") == 0) skip_vbe_check = 1; else if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) { printf("usage: monitor-get-edid [-v] [--port <0-3>] [--try-in-console]\n" " [--skip-vbe-check]\n"); exit(1); } } int size = get_edid(edid, port, skip_vbe_check); if (size < 0 && try_in_console) { int non_X_console = 1; struct vt_stat current; int fd = open("/dev/console", O_RDWR); if (getenv("DISPLAY") != NULL && ioctl(fd, VT_GETSTATE, ¤t) == 0 && current.v_active != non_X_console && ioctl(fd, VT_ACTIVATE, non_X_console) == 0 && ioctl(fd, VT_WAITACTIVE, non_X_console) == 0) { /* retrying */ size = get_edid(edid, port, skip_vbe_check); /* restore */ if (ioctl(fd, VT_ACTIVATE, current.v_active) == 0) ioctl(fd, VT_WAITACTIVE, current.v_active); } close(fd); } if (size >= 0) { write(1, edid, size); return 0; } /* returns 1 when VBE call was ok but not EDID call; * calling program can then speedup call on other ports with --skip-vbe-check; * also, calling program knows no ports work if the VBE call failed */ return -size; }