1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdarg.h>
#include <sys/ioctl.h>
#include <sys/vt.h>
#include "get-edid.h"
int verbose = 0;
int main(int argc, char **argv)
{
char edid[256];
int try_in_console = 0;
int i;
for (i = 1; i < argc; i++)
if (strcmp(argv[i], "-v") == 0) verbose = 1;
else if (strcmp(argv[i], "--try-in-console") == 0) try_in_console = 1;
else if (strcmp(argv[i], "-h") == 0 ||
strcmp(argv[i], "--help") == 0) {
printf("usage: monitor-get-edid [-v]\n");
exit(1);
}
int size = get_edid(edid);
if (!size && try_in_console) {
int non_X_console = 1;
int first_X_console = 7;
struct vt_stat current;
int fd = open("/dev/console", O_RDWR);
if (ioctl(fd, VT_GETSTATE, ¤t) == 0 &&
current.v_state >= first_X_console &&
ioctl(fd, VT_ACTIVATE, non_X_console) == 0 &&
ioctl(fd, VT_WAITACTIVE, non_X_console) == 0) {
/* retrying */
size = get_edid(edid);
/* restore */
ioctl(fd, VT_ACTIVATE, current.v_active) == 0 &&
ioctl(fd, VT_WAITACTIVE, current.v_active) == 0;
}
close(fd);
}
if (size) write(1, edid, size);
return size ? 0 : 1;
}
|