summaryrefslogtreecommitdiff
path: root/src/conn_info/colours.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/conn_info/colours.rs')
-rw-r--r--src/conn_info/colours.rs16
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],
+ });
+ }
}