Merge pull request #239 from glennw/fix-close-crash

Fix crash on close in some X11 drivers
This commit is contained in:
tomaka 2015-01-29 22:47:15 +01:00
commit 26c0c966d5

View file

@ -7,7 +7,7 @@ use std::cell::Cell;
use std::sync::atomic::AtomicBool;
use std::collections::RingBuf;
use super::ffi;
use std::sync::{Arc, Once, ONCE_INIT};
use std::sync::{Arc, Once, ONCE_INIT, Weak};
use std::sync::{StaticMutex, MUTEX_INIT};
pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor};
@ -50,6 +50,9 @@ struct XWindow {
im: ffi::XIM,
}
unsafe impl Send for XWindow {}
unsafe impl Sync for XWindow {}
unsafe impl Send for Window {}
unsafe impl Sync for Window {}
@ -74,25 +77,30 @@ impl Drop for XWindow {
#[derive(Clone)]
pub struct WindowProxy {
x: Arc<XWindow>,
x: Weak<XWindow>,
}
impl WindowProxy {
pub fn wakeup_event_loop(&self) {
match self.x.upgrade() {
Some(x) => {
let mut xev = ffi::XClientMessageEvent {
type_: ffi::ClientMessage,
window: self.x.window,
window: x.window,
format: 32,
message_type: 0,
serial: 0,
send_event: 0,
display: self.x.display,
display: x.display,
l: [0, 0, 0, 0, 0],
};
unsafe {
ffi::XSendEvent(self.x.display, self.x.window, 0, 0, mem::transmute(&mut xev));
ffi::XFlush(self.x.display);
ffi::XSendEvent(x.display, x.window, 0, 0, mem::transmute(&mut xev));
ffi::XFlush(x.display);
}
}
None => {}
}
}
}
@ -488,7 +496,7 @@ impl Window {
pub fn create_window_proxy(&self) -> WindowProxy {
WindowProxy {
x: self.x.clone()
x: self.x.downgrade()
}
}