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
//! Low-level utilities to deal with framebuffer file descriptor

use nix::ioctl_read_bad;

/// System structure representing one RGB channel parameters
#[repr(C)]
#[derive(Clone, Default, Debug)]
pub struct fb_bitfield {
    /// Offset in bits from the right of pixel
    pub offset: u32,
    /// Length in bits
    pub length: u32,
    /// Is most significant bit at the right. Should be 0 on modern systems
    pub msb_right: u32,
}

/// System structure representing variable screen info
#[repr(C)]
#[derive(Clone, Default, Debug)]
pub struct fb_var_screeninfo {
    /// Resolution of screen, X axis
    pub xres: u32,
    /// Resolution of screen, Y axis
    pub yres: u32,
    pub xres_virtual: u32,
    pub yres_virtual: u32,
    pub xoffset: u32,
    pub yoffset: u32,
    /// Number of bits per one pixel. Should be 32
    pub bits_per_pixel: u32,
    /// Is framebuffer grayscale. Should be 0 on modern systems
    pub grayscale: u32,
    /// Definition of red channel format
    pub red: fb_bitfield,
    /// Definition of green channel format
    pub green: fb_bitfield,
    /// Definition of blue channel format
    pub blue: fb_bitfield,
    /// Definition of alpha channel format
    pub transp: fb_bitfield,
    pub nonstd: u32,
    pub activate: u32,
    /// Height of the screen, in mm
    pub height: u32,
    /// Width of the screen, in mm
    pub width: u32,
    pub accel_flags: u32,
    pub pixclock: u32,
    pub left_margin: u32,
    pub right_margin: u32,
    pub upper_margin: u32,
    pub lower_margin: u32,
    pub hsync_len: u32,
    pub vsync_len: u32,
    pub sync: u32,
    pub vmode: u32,
    pub rotate: u32,
    pub colorspace: u32,
    pub reserved: [u32; 4],
}

impl fb_var_screeninfo {
    /// Overall size of framebuffer in bytes
    pub fn overall_size(&self) -> usize {
        (self.xres * self.yres * self.bits_per_pixel / 8) as usize
    }
}

ioctl_read_bad! {
    /// Make a `get_var_screeninfo` ioctl call and return [`fb_var_screeninfo`] struct
    get_var_screeninfo, 0x4600, fb_var_screeninfo
}