Skip to content
Merged
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
4 changes: 0 additions & 4 deletions src/x11/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ impl EventLoop {

// Check if the parents's handle was dropped (such as when the host
// requested the window to close)
//
// 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).
if let Some(parent_handle) = &self.parent_handle {
if parent_handle.parent_did_drop() {
self.handle_must_close();
Expand Down
20 changes: 8 additions & 12 deletions src/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::ffi::c_void;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc;
use std::sync::Arc;
use std::thread;
use std::thread::{self, JoinHandle};

use raw_window_handle::{
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle, XlibDisplayHandle,
Expand All @@ -31,18 +31,16 @@ use crate::x11::visual_info::WindowVisualConfig;

pub struct WindowHandle {
raw_window_handle: Option<RawWindowHandle>,
event_loop_handle: Option<JoinHandle<()>>,
close_requested: Arc<AtomicBool>,
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.store(true, Ordering::Relaxed);
if let Some(event_loop) = self.event_loop_handle.take() {
let _ = event_loop.join();
}
}

Expand Down Expand Up @@ -72,9 +70,9 @@ impl ParentHandle {
pub fn new() -> (Self, WindowHandle) {
let close_requested = Arc::new(AtomicBool::new(false));
let is_open = Arc::new(AtomicBool::new(true));

let handle = WindowHandle {
raw_window_handle: None,
event_loop_handle: None,
close_requested: Arc::clone(&close_requested),
is_open: Arc::clone(&is_open),
};
Expand Down Expand Up @@ -134,17 +132,15 @@ impl<'a> Window<'a> {
};

let (tx, rx) = mpsc::sync_channel::<WindowOpenResult>(1);

let (parent_handle, mut window_handle) = ParentHandle::new();

thread::spawn(move || {
let join_handle = thread::spawn(move || {
Self::window_thread(Some(parent_id), options, build, tx.clone(), Some(parent_handle))
.unwrap();
});

let raw_window_handle = rx.recv().unwrap().unwrap();
window_handle.raw_window_handle = Some(raw_window_handle.0);

window_handle.event_loop_handle = Some(join_handle);
window_handle
}

Expand Down