I am working on x11/xlib safe bindings for my projects, I have this in my code:
impl Drop for Window {
fn drop(&mut self) {
unsafe { XDestroyWindow(self.display, self.id) };
}
}
However, this causes some problems:
let event = display.get_event();
match event.type_ {
// subwindow is Option<Window>
EventType::KeyPress(_key_event) => {
if let Some(_window) = event.subwindow {
// This will only happen if the key is pressed inside a Window, and
// not the root window in general
println!("Return was pressed inside a window!");
}
}
....
this program for example crashes completely, probably because when I try to check if the window is Some, the subwindow variable is dropped?
This gets printed as soon as I hit the key, and the program crashes
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 4 (X_DestroyWindow)
Resource id in failed request: 0xf8
Serial number of failed request: 13
Current serial number in output stream: 13