1use anyhow::Result;
2use uuid::Uuid;
3use x11rb::{connection::Connection as _, xcb_ffi::XCBConnection};
4
5use crate::{Bounds, DevicePixels, DisplayId, PlatformDisplay, Size};
6
7#[derive(Debug)]
8pub(crate) struct X11Display {
9 x_screen_index: usize,
10 bounds: Bounds<DevicePixels>,
11 uuid: Uuid,
12}
13
14impl X11Display {
15 pub(crate) fn new(xc: &XCBConnection, x_screen_index: usize) -> Option<Self> {
16 let screen = xc.setup().roots.get(x_screen_index).unwrap();
17 Some(Self {
18 x_screen_index: x_screen_index,
19 bounds: Bounds {
20 origin: Default::default(),
21 size: Size {
22 width: DevicePixels(screen.width_in_pixels as i32),
23 height: DevicePixels(screen.height_in_pixels as i32),
24 },
25 },
26 uuid: Uuid::from_bytes([0; 16]),
27 })
28 }
29}
30
31impl PlatformDisplay for X11Display {
32 fn id(&self) -> DisplayId {
33 DisplayId(self.x_screen_index as u32)
34 }
35
36 fn uuid(&self) -> Result<Uuid> {
37 Ok(self.uuid)
38 }
39
40 fn bounds(&self) -> Bounds<DevicePixels> {
41 self.bounds
42 }
43}