summaryrefslogtreecommitdiff
path: root/src/conn_info/cursors.rs
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-06-21 19:25:45 +0100
committertcmal <me@aria.rip>2024-06-21 19:25:45 +0100
commite38b963fa4cf6a8bb1341ba5437f8ed9ebe70730 (patch)
treef0bf8698848994f56e4ce06b0727c72cbe3829d1 /src/conn_info/cursors.rs
parent475253b7bcfd03a932c4b7efd969b3d2bf155035 (diff)
avoid leaking resources on drop
Diffstat (limited to 'src/conn_info/cursors.rs')
-rw-r--r--src/conn_info/cursors.rs17
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 });
+ }
}