-
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 RAII resource wrappers #620
Conversation
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>
Signed-off-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Uli Schlachter <psychon@znc.in>
cef7ba8
to
e676e1f
Compare
Signed-off-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Uli Schlachter <psychon@znc.in>
I'm not sure how this will scale for large projects, where XIDs might be stored in structs. Those structs would need have a connection lifetime parameter. Additionally, the same struct wouldn't be able to own both the connection and a wrapped XID, because it would lead to self-references. Additionally, I'm not sure I'm happy with sending data over a socket inside a Anyways, as long as wrappers are optional, I'm fine with it. |
Yeah, this is definitely not useful for everyone. Why I did this: I recently implemented paste (ICCCM selection transfers) "just because". For the transfer, the code creates a window that is destroyed at the end. I ended up writing another version of There is also code like this: https://github.com/linebender/druid/blob/f74a7120fa724b2d6dba88573942aa9864c16b94/druid-shell/src/platform/x11/window.rs#L290 The line in question is a
Hm, yeah... So, what do you think? I described how I ended up writing this PR. Am I approaching this completely wrong or could this still be useful? I am not sure how much that drop-during-panic is a problem. If it is, the code could check whether a panic is in progress and not free the window in this case, but this seems like a weird special case to me...
Yeah, this definitely cannot become the only possible way. Self-referential structs and all. I guess I'd want to add something like this for "everything" (not only core-protocol). Writing this by hand is way too cumbersome and Note to self: Before merging this, there should also be some |
This adds e.g. into_window() to WindowWrapper which consumes the wrapper and returns the underlying XID without destroying the window. Signed-off-by: Uli Schlachter <psychon@znc.in>
This PR implements #78 for the core protocol: This adds e.g.
x11rb::wrapper::WindowWrapper
which, well, wraps a window ID (u32
). In itsDrop
implementation, this callsdestroy_window
, thus preventing "window leaks".I am not sure how much I really like this, but here it is in the form of the PR.
Also, there is way too much hand-written code in this PR. I guess I'd prefer if the code generator generated the necessary code for these wrappers. But today is not the day for that...