-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfbinfo.c
105 lines (93 loc) · 2.23 KB
/
fbinfo.c
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <inttypes.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <cairo.h>
#include "fbtools.h"
#include "logind.h"
#include "complete.h"
/* ------------------------------------------------------------------ */
static void usage(FILE *fp)
{
fprintf(fp,
"\n"
"usage: fbinfo [ options ]\n"
"\n"
"options:\n"
" -h | --help print this\n"
" -f | --fbdev <nr> pick framebuffer\n"
"\n");
}
enum {
OPT_LONG_COMP_BASH = 0x100,
OPT_LONG_COMP_FBDEV,
};
static struct option long_opts[] = {
{
/* --- no argument --- */
.name = "help",
.has_arg = false,
.val = 'h',
},{
.name = "complete-bash",
.has_arg = false,
.val = OPT_LONG_COMP_BASH,
},{
.name = "complete-fbdev",
.has_arg = false,
.val = OPT_LONG_COMP_FBDEV,
},{
/* --- with argument --- */
.name = "fbdev",
.has_arg = true,
.val = 'f',
},{
/* end of list */
}
};
int main(int argc, char **argv)
{
int framebuffer = 0;
int c;
for (;;) {
c = getopt_long(argc, argv, "hf:", long_opts, NULL);
if (c == -1)
break;
switch (c) {
case 'f':
framebuffer = atoi(optarg);
break;
case OPT_LONG_COMP_BASH:
complete_bash("fbinfo", long_opts);
exit(0);
case OPT_LONG_COMP_FBDEV:
complete_device_nr("/dev/fb");
exit(0);
case 'h':
usage(stdout);
exit(0);
default:
usage(stderr);
exit(1);
}
}
logind_init();
fb_query(framebuffer);
logind_fini();
fprintf(stderr, "fb%d: %s, %dx%d, %d bpp, r/g/b/a %d/%d/%d/%d\n",
framebuffer,
fb_fix.id,
fb_var.xres, fb_var.yres,
fb_var.bits_per_pixel,
fb_var.red.length,
fb_var.green.length,
fb_var.blue.length,
fb_var.transp.length);
return 0;
}