mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-23 10:26:34 +11:00
X11: Fix super fun race conditions (#554)
* X11: Fix super fun race conditions * Fix build on rustc<1.26
This commit is contained in:
parent
8891cfd85e
commit
262490d074
3 changed files with 39 additions and 24 deletions
|
@ -10,6 +10,7 @@
|
||||||
- macOS now generates `VirtualKeyCode::LAlt` and `VirtualKeyCode::RAlt` instead of `None` for both.
|
- macOS now generates `VirtualKeyCode::LAlt` and `VirtualKeyCode::RAlt` instead of `None` for both.
|
||||||
- On macOS, `VirtualKeyCode::RWin` and `VirtualKeyCode::LWin` are no longer switched.
|
- On macOS, `VirtualKeyCode::RWin` and `VirtualKeyCode::LWin` are no longer switched.
|
||||||
- On macOS, windows without decorations can once again be resized.
|
- On macOS, windows without decorations can once again be resized.
|
||||||
|
- Fixed race conditions when creating an `EventsLoop` on X11, most commonly manifesting as "[xcb] Unknown sequence number while processing queue".
|
||||||
|
|
||||||
# Version 0.15.0 (2018-05-22)
|
# Version 0.15.0 (2018-05-22)
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,8 @@ pub struct PlatformSpecificWindowBuilderAttributes {
|
||||||
pub x11_window_type: x11::util::WindowType,
|
pub x11_window_type: x11::util::WindowType,
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static!(
|
thread_local!(
|
||||||
pub static ref X11_BACKEND: Result<Arc<XConnection>, XNotSupported> = {
|
pub static X11_BACKEND: Result<Arc<XConnection>, XNotSupported> = {
|
||||||
XConnection::new(Some(x_error_callback)).map(Arc::new)
|
XConnection::new(Some(x_error_callback)).map(Arc::new)
|
||||||
};
|
};
|
||||||
);
|
);
|
||||||
|
@ -342,7 +342,8 @@ unsafe extern "C" fn x_error_callback(
|
||||||
display: *mut x11::ffi::Display,
|
display: *mut x11::ffi::Display,
|
||||||
event: *mut x11::ffi::XErrorEvent,
|
event: *mut x11::ffi::XErrorEvent,
|
||||||
) -> c_int {
|
) -> c_int {
|
||||||
if let Ok(ref xconn) = *X11_BACKEND {
|
X11_BACKEND.with(|result| {
|
||||||
|
if let &Ok(ref xconn) = result {
|
||||||
let mut buf: [c_char; 1024] = mem::uninitialized();
|
let mut buf: [c_char; 1024] = mem::uninitialized();
|
||||||
(xconn.xlib.XGetErrorText)(
|
(xconn.xlib.XGetErrorText)(
|
||||||
display,
|
display,
|
||||||
|
@ -363,6 +364,7 @@ unsafe extern "C" fn x_error_callback(
|
||||||
|
|
||||||
*xconn.latest_error.lock() = Some(error);
|
*xconn.latest_error.lock() = Some(error);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
// Fun fact: this return value is completely ignored.
|
// Fun fact: this return value is completely ignored.
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
@ -424,10 +426,14 @@ r#"Failed to initialize any backend!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_x11() -> Result<EventsLoop, XNotSupported> {
|
pub fn new_x11() -> Result<EventsLoop, XNotSupported> {
|
||||||
match *X11_BACKEND {
|
X11_BACKEND.with(|result| {
|
||||||
Ok(ref x) => Ok(EventsLoop::X(x11::EventsLoop::new(x.clone()))),
|
result
|
||||||
Err(ref err) => Err(err.clone()),
|
.as_ref()
|
||||||
}
|
.map(Arc::clone)
|
||||||
|
.map(x11::EventsLoop::new)
|
||||||
|
.map(EventsLoop::X)
|
||||||
|
.map_err(|err| err.clone())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -5,12 +5,20 @@ use std::sync::Arc;
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
use std::ffi::{CStr, CString, IntoStringError};
|
use std::ffi::{CStr, CString, IntoStringError};
|
||||||
|
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
use super::{ffi, util, XConnection, XError};
|
use super::{ffi, util, XConnection, XError};
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref GLOBAL_LOCK: Mutex<()> = Default::default();
|
||||||
|
}
|
||||||
|
|
||||||
unsafe fn open_im(
|
unsafe fn open_im(
|
||||||
xconn: &Arc<XConnection>,
|
xconn: &Arc<XConnection>,
|
||||||
locale_modifiers: &CStr,
|
locale_modifiers: &CStr,
|
||||||
) -> Option<ffi::XIM> {
|
) -> Option<ffi::XIM> {
|
||||||
|
let _lock = GLOBAL_LOCK.lock();
|
||||||
|
|
||||||
// XSetLocaleModifiers returns...
|
// XSetLocaleModifiers returns...
|
||||||
// * The current locale modifiers if it's given a NULL pointer.
|
// * The current locale modifiers if it's given a NULL pointer.
|
||||||
// * The new locale modifiers if we succeeded in setting them.
|
// * The new locale modifiers if we succeeded in setting them.
|
||||||
|
|
Loading…
Add table
Reference in a new issue