blob: ca552dbde35a00735089c75b5e4346e9ac99b68c (
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
|
use crate::x::atoms::Atoms;
use crate::x::connection::*;
use std::sync::Arc;
use xcb::x::Screen;
pub struct Display {
connection: Connection,
screen_index: i32,
atoms: Atoms,
}
impl HasConnection for Arc<Display> {
fn connection(&self) -> &Connection { &self.connection }
}
impl Display {
pub fn new() -> xcb::Result<Display> {
let (connection, screen_index) = Connection::connect(None)?;
let atoms = connection.get_atoms()?;
Ok(Display { connection, screen_index, atoms })
}
pub fn screen_index(&self) -> i32 {
self.screen_index
}
}
pub trait HasDisplay {
fn display(&self) -> &Arc<Display>;
fn atoms(&self) -> &Atoms { &self.display().atoms }
}
impl HasDisplay for Arc<Display> {
fn display(&self) -> &Arc<Display> { self }
}
pub trait DisplayExt: HasDisplay + HasConnection {
fn screen(&self) -> &Screen {
let setup = self.connection().get_setup();
let screen_index = self.display().screen_index() as usize;
&setup.roots().nth(screen_index).unwrap()
}
}
impl<T: HasDisplay + HasConnection> DisplayExt for T { }
|