blob: 30e5165b8ef2b5a99b5c6b64d50a90436cdeb065 (
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
|
use crate::x::*;
use std::sync::Arc;
use x11::xft::{ XftDraw, XftDrawCreate, XftDrawDestroy };
use xcb::{ Xid };
pub struct FontGraphicContext {
display: Arc<Display>,
context_state: *mut XftDraw,
}
impl FontGraphicContext {
pub fn new(window: &Window) -> xcb::Result<FontGraphicContext> {
let display = Arc::clone(window.display());
let xlib_display = display.connection().get_xlib_display();
let x_visual = unsafe {
x11::xlib::XDefaultVisual(xlib_display, display.screen_index())
};
let colormap = window.screen().default_colormap();
let context_state = unsafe {
XftDrawCreate(xlib_display,
window.window_id().resource_id() as u64,
x_visual,
colormap.resource_id() as u64)
};
Ok(FontGraphicContext { display, context_state })
}
pub fn get_xft_draw(&self) -> *mut XftDraw {
self.context_state
}
}
impl Drop for FontGraphicContext {
fn drop(&mut self) {
unsafe { XftDrawDestroy(self.context_state) };
}
}
|