aboutsummaryrefslogtreecommitdiffstats
path: root/fbinfo.c
blob: dceca01e9cd6d7747d865e4513803c27b6869a33 (plain)
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
#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"

/* ------------------------------------------------------------------ */

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");
}

struct option long_opts[] = {
    {
        /* --- no argument --- */
        .name    = "help",
        .has_arg = false,
        .val     = 'h',
    },{

        /* --- 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 '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;
}