diff options
Diffstat (limited to 'src/conn_info/cursors.rs')
-rw-r--r-- | src/conn_info/cursors.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/conn_info/cursors.rs b/src/conn_info/cursors.rs index 119de5c..bb547e4 100644 --- a/src/conn_info/cursors.rs +++ b/src/conn_info/cursors.rs @@ -1,7 +1,7 @@ use crate::error::Result; use xcb::{ - x::{CreateGlyphCursor, Cursor, Font, OpenFont}, - Connection, + x::{CloseFont, CreateGlyphCursor, Cursor, Font, FreeCursor, OpenFont}, + Connection as RawConnection, }; // https://tronche.com/gui/x/xlib/appendix/b/ @@ -18,7 +18,7 @@ pub struct Cursors { impl Cursors { /// Load default cursors using the given connection. - pub fn new_with(conn: &Connection) -> Result<Self> { + pub fn new_with(conn: &RawConnection) -> Result<Self> { // Open cursor font let font = conn.generate_id(); conn.check_request(conn.send_request_checked(&OpenFont { @@ -33,7 +33,7 @@ impl Cursors { } /// Load the cursor with the given id from `font` - fn load_cursor(conn: &Connection, font: Font, id: u16) -> Result<Cursor> { + fn load_cursor(conn: &RawConnection, font: Font, id: u16) -> Result<Cursor> { let cid = conn.generate_id(); // https://github.com/mirror/libX11/blob/ff8706a5eae25b8bafce300527079f68a201d27f/src/Cursor.c#L34 conn.check_request(conn.send_request_checked(&CreateGlyphCursor { @@ -56,4 +56,13 @@ impl Cursors { pub const fn normal(&self) -> Cursor { self.normal } + + /// Free the associated resources to avoid leaking them. + /// This object must not be used again after this method is called, as all resources will be invalid. + pub unsafe fn free(&self, conn: &RawConnection) { + conn.send_request(&FreeCursor { + cursor: self.normal, + }); + conn.send_request(&CloseFont { font: self.font }); + } } |