diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-22 23:18:13 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-22 23:18:13 -0700 |
| commit | b7319af1ed9e5dc3c29d05d6f5de9f325fa64191 (patch) | |
| tree | d3ce5e3b0f6835e4e8179ab8caf2921c7e4ad295 /src/x/text/font_context.rs | |
| parent | 1b24796bb97f64ab2771a884632d4b6f64d86f0f (diff) | |
new subdirectory src/x/text/
Force-Push: yes Change-Id: I1c428e1f7b42de263534965422dffe007300082c
Diffstat (limited to 'src/x/text/font_context.rs')
| -rw-r--r-- | src/x/text/font_context.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/x/text/font_context.rs b/src/x/text/font_context.rs new file mode 100644 index 0000000..56eb08e --- /dev/null +++ b/src/x/text/font_context.rs @@ -0,0 +1,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: 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) }; + } +} + |