mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 22:31:30 +11:00
Ignore locale if unsupported by X11 backend (#1445)
This restores default portable 'C' locale when target locale is unsupported by X11 backend (Xlib). When target locale is unsupported by X11, some locale-dependent Xlib functions like `XSetLocaleModifiers` fail or have no effect triggering later failures and panics. When target locale is not valid, `setLocale` should normally leave the locale unchanged (`setLocale` returns 'C'). However, in some situations, locale is accepted by `setLocale` (`setLocale` returns the new locale) but the accepted locale is unsupported by Xlib (`XSupportsLocale` returns `false`). Fix #636
This commit is contained in:
parent
96df858961
commit
a1b65f7080
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
- On Wayland, fix coordinates in touch events when scale factor isn't 1.
|
- On Wayland, fix coordinates in touch events when scale factor isn't 1.
|
||||||
- On Wayland, fix color from `close_button_icon_color` not applying.
|
- On Wayland, fix color from `close_button_icon_color` not applying.
|
||||||
|
- Ignore locale if unsupported by X11 backend
|
||||||
|
|
||||||
# 0.21.0 (2020-02-04)
|
# 0.21.0 (2020-02-04)
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,8 @@ unsafe fn open_im(xconn: &Arc<XConnection>, locale_modifiers: &CStr) -> Option<f
|
||||||
// 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.
|
||||||
// * NULL if the locale modifiers string is malformed.
|
// * NULL if the locale modifiers string is malformed or if the
|
||||||
|
// current locale is not supported by Xlib.
|
||||||
(xconn.xlib.XSetLocaleModifiers)(locale_modifiers.as_ptr());
|
(xconn.xlib.XSetLocaleModifiers)(locale_modifiers.as_ptr());
|
||||||
|
|
||||||
let im = (xconn.xlib.XOpenIM)(
|
let im = (xconn.xlib.XOpenIM)(
|
||||||
|
|
|
@ -29,6 +29,7 @@ use std::{
|
||||||
mem::{self, MaybeUninit},
|
mem::{self, MaybeUninit},
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
os::raw::*,
|
os::raw::*,
|
||||||
|
ptr,
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
slice,
|
slice,
|
||||||
sync::{mpsc, Arc, Mutex, Weak},
|
sync::{mpsc, Arc, Mutex, Weak},
|
||||||
|
@ -105,7 +106,25 @@ impl<T: 'static> EventLoop<T> {
|
||||||
// Input methods will open successfully without setting the locale, but it won't be
|
// Input methods will open successfully without setting the locale, but it won't be
|
||||||
// possible to actually commit pre-edit sequences.
|
// possible to actually commit pre-edit sequences.
|
||||||
unsafe {
|
unsafe {
|
||||||
|
// Remember default locale to restore it if target locale is unsupported
|
||||||
|
// by Xlib
|
||||||
|
let default_locale = setlocale(LC_CTYPE, ptr::null());
|
||||||
setlocale(LC_CTYPE, b"\0".as_ptr() as *const _);
|
setlocale(LC_CTYPE, b"\0".as_ptr() as *const _);
|
||||||
|
|
||||||
|
// Check if set locale is supported by Xlib.
|
||||||
|
// If not, calls to some Xlib functions like `XSetLocaleModifiers`
|
||||||
|
// will fail.
|
||||||
|
let locale_supported = (xconn.xlib.XSupportsLocale)() == 1;
|
||||||
|
if !locale_supported {
|
||||||
|
let unsupported_locale = setlocale(LC_CTYPE, ptr::null());
|
||||||
|
warn!(
|
||||||
|
"Unsupported locale \"{}\". Restoring default locale \"{}\".",
|
||||||
|
CStr::from_ptr(unsupported_locale).to_string_lossy(),
|
||||||
|
CStr::from_ptr(default_locale).to_string_lossy()
|
||||||
|
);
|
||||||
|
// Restore default locale
|
||||||
|
setlocale(LC_CTYPE, default_locale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let ime = RefCell::new({
|
let ime = RefCell::new({
|
||||||
let result = Ime::new(Arc::clone(&xconn));
|
let result = Ime::new(Arc::clone(&xconn));
|
||||||
|
|
Loading…
Reference in a new issue