diff --git a/src/platform_impl/linux/wayland/event_loop.rs b/src/platform_impl/linux/wayland/event_loop.rs index 97e134ce..7ba2c59a 100644 --- a/src/platform_impl/linux/wayland/event_loop.rs +++ b/src/platform_impl/linux/wayland/event_loop.rs @@ -509,24 +509,34 @@ impl EventLoop { ); } } - // do a second run of post-dispatch-triggers, to handle user-generated "request-redraw" - // in response of resize & friends - self.post_dispatch_triggers(); + // send Events cleared { - let mut guard = sink.lock().unwrap(); - guard.empty_with(|evt| { + sticky_exit_callback( + crate::event::Event::MainEventsCleared, + &self.window_target, + &mut control_flow, + &mut callback, + ); + } + + // handle request-redraw + { + self.redraw_triggers(|wid, window_target| { sticky_exit_callback( - evt, - &self.window_target, + crate::event::Event::RedrawRequested(crate::window::WindowId( + crate::platform_impl::WindowId::Wayland(wid), + )), + window_target, &mut control_flow, &mut callback, ); }); } - // send Events cleared + + // send RedrawEventsCleared { sticky_exit_callback( - crate::event::Event::MainEventsCleared, + crate::event::Event::RedrawEventsCleared, &self.window_target, &mut control_flow, &mut callback, @@ -652,6 +662,31 @@ impl EventLoopWindowTarget { */ impl EventLoop { + fn redraw_triggers(&mut self, mut callback: F) + where + F: FnMut(WindowId, &RootELW), + { + let window_target = match self.window_target.p { + crate::platform_impl::EventLoopWindowTarget::Wayland(ref wt) => wt, + _ => unreachable!(), + }; + window_target.store.lock().unwrap().for_each_redraw_trigger( + |refresh, frame_refresh, wid, frame| { + if let Some(frame) = frame { + if frame_refresh { + frame.refresh(); + if !refresh { + frame.surface().commit() + } + } + } + if refresh { + callback(wid, &self.window_target); + } + }, + ) + } + fn post_dispatch_triggers(&mut self) { let mut sink = self.sink.lock().unwrap(); let window_target = match self.window_target.p { @@ -690,11 +725,6 @@ impl EventLoop { *window.size = (w, h); } - } else if window.frame_refresh { - frame.refresh(); - if !window.refresh { - frame.surface().commit() - } } } if let Some(dpi) = window.new_dpi { @@ -703,10 +733,6 @@ impl EventLoop { window.wid, ); } - if window.refresh { - unimplemented!() - //sink.send_window_event(crate::event::WindowEvent::RedrawRequested, window.wid); - } if window.closed { sink.send_window_event(crate::event::WindowEvent::CloseRequested, window.wid); } diff --git a/src/platform_impl/linux/wayland/window.rs b/src/platform_impl/linux/wayland/window.rs index 7faed502..f6ed3964 100644 --- a/src/platform_impl/linux/wayland/window.rs +++ b/src/platform_impl/linux/wayland/window.rs @@ -396,8 +396,6 @@ pub struct WindowStoreForEach<'a> { pub newsize: Option<(u32, u32)>, pub size: &'a mut (u32, u32), pub new_dpi: Option, - pub refresh: bool, - pub frame_refresh: bool, pub closed: bool, pub grab_cursor: Option, pub surface: &'a wl_surface::WlSurface, @@ -463,8 +461,6 @@ impl WindowStore { newsize: window.newsize.take(), size: &mut *(window.size.lock().unwrap()), new_dpi: window.new_dpi, - refresh: replace(&mut *window.need_refresh.lock().unwrap(), false), - frame_refresh: replace(&mut *window.need_frame_refresh.lock().unwrap(), false), closed: window.closed, grab_cursor: window.cursor_grab_changed.lock().unwrap().take(), surface: &window.surface, @@ -478,4 +474,20 @@ impl WindowStore { window.closed = false; } } + + pub fn for_each_redraw_trigger(&mut self, mut f: F) + where + F: FnMut(bool, bool, WindowId, Option<&mut SWindow>), + { + 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()); + 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), + ); + } + } }