Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/gl/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,9 @@ impl GlContext {
}

impl Drop for GlContext {
fn drop(&mut self) {}
fn drop(&mut self) {
unsafe {
glx::glXDestroyContext(self.display, self.context);
}
}
}
27 changes: 11 additions & 16 deletions src/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,13 @@ use crate::x11::visual_info::WindowVisualConfig;

pub struct WindowHandle {
raw_window_handle: Option<RawWindowHandle>,
close_requested: Arc<AtomicBool>,
close_requested: mpsc::SyncSender<()>,
is_open: Arc<AtomicBool>,
}

impl WindowHandle {
pub fn close(&mut self) {
if self.raw_window_handle.take().is_some() {
// FIXME: This will need to be changed from just setting an atomic to somehow
// synchronizing with the window being closed (using a synchronous channel, or
// by joining on the event loop thread).

self.close_requested.store(true, Ordering::Relaxed);
}
self.close_requested.send(()).ok();
}

pub fn is_open(&self) -> bool {
Expand All @@ -64,26 +58,26 @@ unsafe impl HasRawWindowHandle for WindowHandle {
}

pub(crate) struct ParentHandle {
close_requested: Arc<AtomicBool>,
close_requested: mpsc::Receiver<()>,
is_open: Arc<AtomicBool>,
}

impl ParentHandle {
pub fn new() -> (Self, WindowHandle) {
let close_requested = Arc::new(AtomicBool::new(false));
let (close_sender, close_receiver) = mpsc::sync_channel(0);
let is_open = Arc::new(AtomicBool::new(true));

let handle = WindowHandle {
raw_window_handle: None,
close_requested: Arc::clone(&close_requested),
close_requested: close_sender,
is_open: Arc::clone(&is_open),
};

(Self { close_requested, is_open }, handle)
(Self { close_requested: close_receiver, is_open }, handle)
}

pub fn parent_did_drop(&self) -> bool {
self.close_requested.load(Ordering::Relaxed)
self.close_requested.try_recv().is_ok()
}
}

Expand All @@ -94,16 +88,17 @@ impl Drop for ParentHandle {
}

pub(crate) struct WindowInner {
// GlContext should be dropped **before** XcbConnection is dropped
#[cfg(feature = "opengl")]
gl_context: Option<GlContext>,

pub(crate) xcb_connection: XcbConnection,
window_id: XWindow,
pub(crate) window_info: WindowInfo,
visual_id: Visualid,
mouse_cursor: Cell<MouseCursor>,

pub(crate) close_requested: Cell<bool>,

#[cfg(feature = "opengl")]
gl_context: Option<GlContext>,
}

pub struct Window<'a> {
Expand Down
Loading