Skip to content

Commit fc624c3

Browse files
authored
Merge branch 'master' into update-keyboard-events
2 parents ac19fdf + 237d323 commit fc624c3

4 files changed

Lines changed: 20 additions & 23 deletions

File tree

src/gl/x11.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,9 @@ impl GlContext {
241241
}
242242

243243
impl Drop for GlContext {
244-
fn drop(&mut self) {}
244+
fn drop(&mut self) {
245+
unsafe {
246+
glx::glXDestroyContext(self.display, self.context);
247+
}
248+
}
245249
}

src/x11/event_loop.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ impl EventLoop {
108108

109109
// Check if the parents's handle was dropped (such as when the host
110110
// requested the window to close)
111-
//
112-
// FIXME: This will need to be changed from just setting an atomic to somehow
113-
// synchronizing with the window being closed (using a synchronous channel, or
114-
// by joining on the event loop thread).
115111
if let Some(parent_handle) = &self.parent_handle {
116112
if parent_handle.parent_did_drop() {
117113
self.handle_must_close();

src/x11/keyboard.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,9 @@ pub(super) fn key_mods(mods: KeyButMask) -> Modifiers {
370370
// X11's mod keys are configurable, but this seems
371371
// like a reasonable default for US keyboards, at least,
372372
// where the "windows" key seems to be MOD_MASK_4.
373-
(KeyButMask::BUTTON1, Modifiers::ALT),
374-
(KeyButMask::BUTTON2, Modifiers::NUM_LOCK),
375-
(KeyButMask::BUTTON4, Modifiers::META),
373+
(KeyButMask::MOD1, Modifiers::ALT),
374+
(KeyButMask::MOD2, Modifiers::NUM_LOCK),
375+
(KeyButMask::MOD4, Modifiers::META),
376376
(KeyButMask::LOCK, Modifiers::CAPS_LOCK),
377377
];
378378
for (mask, modifiers) in &key_masks {

src/x11/window.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::ffi::c_void;
44
use std::sync::atomic::{AtomicBool, Ordering};
55
use std::sync::mpsc;
66
use std::sync::Arc;
7-
use std::thread;
7+
use std::thread::{self, JoinHandle};
88

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

3232
pub struct WindowHandle {
3333
raw_window_handle: Option<RawWindowHandle>,
34+
event_loop_handle: Option<JoinHandle<()>>,
3435
close_requested: Arc<AtomicBool>,
3536
is_open: Arc<AtomicBool>,
3637
}
3738

3839
impl WindowHandle {
3940
pub fn close(&mut self) {
40-
if self.raw_window_handle.take().is_some() {
41-
// FIXME: This will need to be changed from just setting an atomic to somehow
42-
// synchronizing with the window being closed (using a synchronous channel, or
43-
// by joining on the event loop thread).
44-
45-
self.close_requested.store(true, Ordering::Relaxed);
41+
self.close_requested.store(true, Ordering::Relaxed);
42+
if let Some(event_loop) = self.event_loop_handle.take() {
43+
let _ = event_loop.join();
4644
}
4745
}
4846

@@ -72,9 +70,9 @@ impl ParentHandle {
7270
pub fn new() -> (Self, WindowHandle) {
7371
let close_requested = Arc::new(AtomicBool::new(false));
7472
let is_open = Arc::new(AtomicBool::new(true));
75-
7673
let handle = WindowHandle {
7774
raw_window_handle: None,
75+
event_loop_handle: None,
7876
close_requested: Arc::clone(&close_requested),
7977
is_open: Arc::clone(&is_open),
8078
};
@@ -94,16 +92,17 @@ impl Drop for ParentHandle {
9492
}
9593

9694
pub(crate) struct WindowInner {
95+
// GlContext should be dropped **before** XcbConnection is dropped
96+
#[cfg(feature = "opengl")]
97+
gl_context: Option<GlContext>,
98+
9799
pub(crate) xcb_connection: XcbConnection,
98100
window_id: XWindow,
99101
pub(crate) window_info: WindowInfo,
100102
visual_id: Visualid,
101103
mouse_cursor: Cell<MouseCursor>,
102104

103105
pub(crate) close_requested: Cell<bool>,
104-
105-
#[cfg(feature = "opengl")]
106-
gl_context: Option<GlContext>,
107106
}
108107

109108
pub struct Window<'a> {
@@ -133,17 +132,15 @@ impl<'a> Window<'a> {
133132
};
134133

135134
let (tx, rx) = mpsc::sync_channel::<WindowOpenResult>(1);
136-
137135
let (parent_handle, mut window_handle) = ParentHandle::new();
138-
139-
thread::spawn(move || {
136+
let join_handle = thread::spawn(move || {
140137
Self::window_thread(Some(parent_id), options, build, tx.clone(), Some(parent_handle))
141138
.unwrap();
142139
});
143140

144141
let raw_window_handle = rx.recv().unwrap().unwrap();
145142
window_handle.raw_window_handle = Some(raw_window_handle.0);
146-
143+
window_handle.event_loop_handle = Some(join_handle);
147144
window_handle
148145
}
149146

0 commit comments

Comments
 (0)