On Wayland, fix deadlock when calling set_inner_size from event loop

Fixes #1571.
This commit is contained in:
Kirill Chibisov 2020-05-22 13:33:04 +03:00 committed by GitHub
parent 6cfddfea21
commit ff66bdda7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View file

@ -1,6 +1,8 @@
# Unreleased
- On Web, prevent the webpage from scrolling when the user is focused on a winit canvas
- On Wayland, fix deadlock when calling to `set_inner_size` from a callback.
# 0.22.2 (2020-05-16)
- Added Clone implementation for 'static events.

View file

@ -667,6 +667,8 @@ impl<T> EventLoop<T> {
window_target.store.lock().unwrap().for_each_redraw_trigger(
|refresh, frame_refresh, wid, frame| {
if let Some(frame) = frame {
let mut frame = frame.lock().unwrap();
if frame_refresh {
frame.refresh();
if !refresh {
@ -751,6 +753,7 @@ impl<T> EventLoop<T> {
if window.new_size.is_some() || window.new_scale_factor.is_some() {
if let Some(frame) = window.frame {
let mut frame = frame.lock().unwrap();
// Update decorations state
match window.decorations_action {
Some(DecorationsAction::Hide) => frame.set_decorate(false),

View file

@ -461,7 +461,7 @@ pub struct WindowStoreForEach<'a> {
pub grab_cursor: Option<bool>,
pub surface: &'a wl_surface::WlSurface,
pub wid: WindowId,
pub frame: Option<&'a mut SWindow<ConceptFrame>>,
pub frame: Option<Arc<Mutex<SWindow<ConceptFrame>>>>,
pub decorations_action: Option<DecorationsAction>,
}
@ -522,8 +522,7 @@ impl WindowStore {
if let Some(scale_factor) = window.new_scale_factor {
window.current_scale_factor = scale_factor;
}
let opt_arc = window.frame.upgrade();
let mut opt_mutex_lock = opt_arc.as_ref().map(|m| m.lock().unwrap());
let frame = window.frame.upgrade();
let decorations_action = { window.pending_decorations_action.lock().unwrap().take() };
f(WindowStoreForEach {
new_size: window.new_size.take(),
@ -534,7 +533,7 @@ impl WindowStore {
grab_cursor: window.cursor_grab_changed.lock().unwrap().take(),
surface: &window.surface,
wid: make_wid(&window.surface),
frame: opt_mutex_lock.as_mut().map(|m| &mut **m),
frame,
decorations_action,
});
// avoid re-spamming the event
@ -544,16 +543,15 @@ impl WindowStore {
pub fn for_each_redraw_trigger<F>(&mut self, mut f: F)
where
F: FnMut(bool, bool, WindowId, Option<&mut SWindow<ConceptFrame>>),
F: FnMut(bool, bool, WindowId, Option<Arc<Mutex<SWindow<ConceptFrame>>>>),
{
for window in &mut self.windows {
let opt_arc = window.frame.upgrade();
let mut opt_mutex_lock = opt_arc.as_ref().map(|m| m.lock().unwrap());
let frame = window.frame.upgrade();
f(
replace(&mut *window.need_refresh.lock().unwrap(), false),
replace(&mut *window.need_frame_refresh.lock().unwrap(), false),
make_wid(&window.surface),
opt_mutex_lock.as_mut().map(|m| &mut **m),
frame,
);
}
}