diff options
author | tcmal <me@aria.rip> | 2024-06-21 19:25:45 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-06-21 19:25:45 +0100 |
commit | e38b963fa4cf6a8bb1341ba5437f8ed9ebe70730 (patch) | |
tree | f0bf8698848994f56e4ce06b0727c72cbe3829d1 /src/conn_info/colours.rs | |
parent | 475253b7bcfd03a932c4b7efd969b3d2bf155035 (diff) |
avoid leaking resources on drop
Diffstat (limited to 'src/conn_info/colours.rs')
-rw-r--r-- | src/conn_info/colours.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/conn_info/colours.rs b/src/conn_info/colours.rs index 22b4fc2..d678bdb 100644 --- a/src/conn_info/colours.rs +++ b/src/conn_info/colours.rs @@ -1,7 +1,7 @@ use crate::error::Result; use xcb::{ - x::{AllocColor, Colormap}, - Connection, + x::{AllocColor, Colormap, FreeColors}, + Connection as RawConnection, }; /// Caches colours in an X11 color map. @@ -14,7 +14,7 @@ pub struct Colours { impl Colours { /// Load the colours into the given colour map - pub fn new_with(conn: &Connection, cmap: Colormap) -> Result<Self> { + pub fn new_with(conn: &RawConnection, cmap: Colormap) -> Result<Self> { // TODO: Move these colours out to config.rs let (border_normal, border_focused) = ( conn.wait_for_reply(conn.send_request(&AllocColor { @@ -47,4 +47,14 @@ impl Colours { pub const fn border_focused(&self) -> u32 { self.border_focused } + + /// 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(&FreeColors { + cmap: self.cmap, + plane_mask: 0, + pixels: &[self.border_normal, self.border_focused], + }); + } } |