Make WindowStore::for_each less terrifying to rebase (#1304)

This commit is contained in:
Osspial 2019-12-04 03:55:49 -05:00 committed by GitHub
parent 07bdd3e218
commit 400f75a2b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 74 deletions

View file

@ -664,60 +664,53 @@ impl<T> EventLoop<T> {
} }
} }
// process pending resize/refresh // process pending resize/refresh
window_target.store.lock().unwrap().for_each( window_target.store.lock().unwrap().for_each(|window| {
|newsize, if let Some(frame) = window.frame {
size, if let Some(newsize) = window.newsize {
new_dpi,
refresh,
frame_refresh,
closed,
grab_cursor,
surface,
wid,
frame| {
if let Some(frame) = frame {
if let Some(newsize) = newsize {
// Drop resize events equaled to the current size // Drop resize events equaled to the current size
if newsize != *size { if newsize != *window.size {
let (w, h) = newsize; let (w, h) = newsize;
frame.resize(w, h); frame.resize(w, h);
frame.refresh(); frame.refresh();
let logical_size = crate::dpi::LogicalSize::new(w as f64, h as f64); let logical_size = crate::dpi::LogicalSize::new(w as f64, h as f64);
sink.send_window_event( sink.send_window_event(
crate::event::WindowEvent::Resized(logical_size), crate::event::WindowEvent::Resized(logical_size),
wid, window.wid,
); );
*size = (w, h); *window.size = (w, h);
} else { } else {
// Refresh csd, etc, otherwise // Refresh csd, etc, otherwise
frame.refresh(); frame.refresh();
} }
} else if frame_refresh { } else if window.frame_refresh {
frame.refresh(); frame.refresh();
if !refresh { if !window.refresh {
frame.surface().commit() frame.surface().commit()
} }
} }
} }
if let Some(dpi) = new_dpi { if let Some(dpi) = window.new_dpi {
sink.send_window_event( sink.send_window_event(
crate::event::WindowEvent::HiDpiFactorChanged(dpi as f64), crate::event::WindowEvent::HiDpiFactorChanged(dpi as f64),
wid, window.wid,
); );
} }
if refresh { if window.refresh {
sink.send_window_event(crate::event::WindowEvent::RedrawRequested, wid); sink.send_window_event(crate::event::WindowEvent::RedrawRequested, window.wid);
} }
if closed { if window.closed {
sink.send_window_event(crate::event::WindowEvent::CloseRequested, wid); sink.send_window_event(crate::event::WindowEvent::CloseRequested, window.wid);
} }
if let Some(grab_cursor) = grab_cursor { if let Some(grab_cursor) = window.grab_cursor {
let surface = if grab_cursor { Some(surface) } else { None }; let surface = if grab_cursor {
Some(window.surface)
} else {
None
};
self.cursor_manager.lock().unwrap().grab_pointer(surface); self.cursor_manager.lock().unwrap().grab_pointer(surface);
} }
}, })
)
} }
} }

View file

@ -385,6 +385,19 @@ pub struct WindowStore {
windows: Vec<InternalWindow>, windows: Vec<InternalWindow>,
} }
pub struct WindowStoreForEach<'a> {
pub newsize: Option<(u32, u32)>,
pub size: &'a mut (u32, u32),
pub new_dpi: Option<i32>,
pub refresh: bool,
pub frame_refresh: bool,
pub closed: bool,
pub grab_cursor: Option<bool>,
pub surface: &'a wl_surface::WlSurface,
pub wid: WindowId,
pub frame: Option<&'a mut SWindow<ConceptFrame>>,
}
impl WindowStore { impl WindowStore {
pub fn new() -> WindowStore { pub fn new() -> WindowStore {
WindowStore { WindowStore {
@ -434,34 +447,23 @@ impl WindowStore {
pub fn for_each<F>(&mut self, mut f: F) pub fn for_each<F>(&mut self, mut f: F)
where where
F: FnMut( F: FnMut(WindowStoreForEach<'_>),
Option<(u32, u32)>,
&mut (u32, u32),
Option<i32>,
bool,
bool,
bool,
Option<bool>,
&wl_surface::WlSurface,
WindowId,
Option<&mut SWindow<ConceptFrame>>,
),
{ {
for window in &mut self.windows { for window in &mut self.windows {
let opt_arc = window.frame.upgrade(); let opt_arc = window.frame.upgrade();
let mut opt_mutex_lock = opt_arc.as_ref().map(|m| m.lock().unwrap()); let mut opt_mutex_lock = opt_arc.as_ref().map(|m| m.lock().unwrap());
f( f(WindowStoreForEach {
window.newsize.take(), newsize: window.newsize.take(),
&mut *(window.size.lock().unwrap()), size: &mut *(window.size.lock().unwrap()),
window.new_dpi, new_dpi: window.new_dpi,
replace(&mut *window.need_refresh.lock().unwrap(), false), refresh: replace(&mut *window.need_refresh.lock().unwrap(), false),
replace(&mut *window.need_frame_refresh.lock().unwrap(), false), frame_refresh: replace(&mut *window.need_frame_refresh.lock().unwrap(), false),
window.closed, closed: window.closed,
window.cursor_grab_changed.lock().unwrap().take(), grab_cursor: window.cursor_grab_changed.lock().unwrap().take(),
&window.surface, surface: &window.surface,
make_wid(&window.surface), wid: make_wid(&window.surface),
opt_mutex_lock.as_mut().map(|m| &mut **m), frame: opt_mutex_lock.as_mut().map(|m| &mut **m),
); });
if let Some(dpi) = window.new_dpi.take() { if let Some(dpi) = window.new_dpi.take() {
window.current_dpi = dpi; window.current_dpi = dpi;
} }