-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some wrapper for resources (e.g. pixmaps) that frees them on drop (free_pixmap()) #78
Comments
I gave this a go and I am not too happy about the necessary amount of code, not about the // CreateWindow/DestroyWindow
// OpenFont/CloseFont
// CreatePixmap/FreePixmap
// CreateGC/FreeGC
// CreateColormap/FreeColormap
// CreateCursor/CreateGlyphCursor/FreeCursor
//
// Plus the same for all the extensions that are out there.
/// TODO
#[derive(Debug)]
pub struct FreePixmap<'c, C: Connection>(&'c C, u32);
impl<'c, C: Connection> FreePixmap<'c, C>
{
/// TODO
pub fn for_pixmap(conn: &'c C, pixmap: PIXMAP) -> Self
{
FreePixmap(conn, pixmap)
}
/// TODO
pub fn create_pixmap(conn: &'c C, depth: u8, drawable: u32, width: u16, height: u16) -> Result<Self, ConnectionError> {
let pixmap = conn.generate_id();
drop(conn.create_pixmap(depth, pixmap, drawable, width, height)?);
Ok(Self::for_pixmap(conn, pixmap))
}
pub fn pixmap(&self) -> PIXMAP {
self.1
}
}
impl<C: Connection> Deref for FreePixmap<'_, C>
{
type Target = PIXMAP;
fn deref(&self) -> &PIXMAP {
&self.1
}
}
impl<C: Connection> Drop for FreePixmap<'_, C>
{
fn drop(&mut self) {
drop(self.0.free_pixmap(self.1).unwrap());
}
} |
This commits adds structs that e.g. wrap a window. When this struct is dropped, the contained window is destroyed. Such a wrapper is added for each kind of resource in the core protocol. Extensions are not (yet?) handled. Implements-most-of: #78 Signed-off-by: Uli Schlachter <psychon@znc.in>
#620 implemented the xproto part of this. For this issue, the remaining pieces are:
I think the second bullet point should be addressed before the first one. Hand-writing this stuff for xproto was already annoying enough. :-) |
I end up writing something like the following in most of the examples:
x11rb/examples/xeyes.rs
Lines 151 to 156 in 52b21fa
A proper implementation would add
Deref
, I guess. And some wrappers around things likeCreatePixmap
, although that is harder to do automatically...The text was updated successfully, but these errors were encountered: