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