mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-12 05:31:31 +11:00
Make WindowStore::for_each less terrifying to rebase (#1304)
This commit is contained in:
parent
07bdd3e218
commit
400f75a2b3
|
@ -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,
|
// Drop resize events equaled to the current size
|
||||||
refresh,
|
if newsize != *window.size {
|
||||||
frame_refresh,
|
let (w, h) = newsize;
|
||||||
closed,
|
frame.resize(w, h);
|
||||||
grab_cursor,
|
|
||||||
surface,
|
|
||||||
wid,
|
|
||||||
frame| {
|
|
||||||
if let Some(frame) = frame {
|
|
||||||
if let Some(newsize) = newsize {
|
|
||||||
// Drop resize events equaled to the current size
|
|
||||||
if newsize != *size {
|
|
||||||
let (w, h) = newsize;
|
|
||||||
frame.resize(w, h);
|
|
||||||
frame.refresh();
|
|
||||||
let logical_size = crate::dpi::LogicalSize::new(w as f64, h as f64);
|
|
||||||
sink.send_window_event(
|
|
||||||
crate::event::WindowEvent::Resized(logical_size),
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
*size = (w, h);
|
|
||||||
} else {
|
|
||||||
// Refresh csd, etc, otherwise
|
|
||||||
frame.refresh();
|
|
||||||
}
|
|
||||||
} else if frame_refresh {
|
|
||||||
frame.refresh();
|
frame.refresh();
|
||||||
if !refresh {
|
let logical_size = crate::dpi::LogicalSize::new(w as f64, h as f64);
|
||||||
frame.surface().commit()
|
sink.send_window_event(
|
||||||
}
|
crate::event::WindowEvent::Resized(logical_size),
|
||||||
|
window.wid,
|
||||||
|
);
|
||||||
|
*window.size = (w, h);
|
||||||
|
} else {
|
||||||
|
// Refresh csd, etc, otherwise
|
||||||
|
frame.refresh();
|
||||||
|
}
|
||||||
|
} else if window.frame_refresh {
|
||||||
|
frame.refresh();
|
||||||
|
if !window.refresh {
|
||||||
|
frame.surface().commit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(dpi) = new_dpi {
|
}
|
||||||
sink.send_window_event(
|
if let Some(dpi) = window.new_dpi {
|
||||||
crate::event::WindowEvent::HiDpiFactorChanged(dpi as f64),
|
sink.send_window_event(
|
||||||
wid,
|
crate::event::WindowEvent::HiDpiFactorChanged(dpi as f64),
|
||||||
);
|
window.wid,
|
||||||
}
|
);
|
||||||
if refresh {
|
}
|
||||||
sink.send_window_event(crate::event::WindowEvent::RedrawRequested, wid);
|
if window.refresh {
|
||||||
}
|
sink.send_window_event(crate::event::WindowEvent::RedrawRequested, window.wid);
|
||||||
if closed {
|
}
|
||||||
sink.send_window_event(crate::event::WindowEvent::CloseRequested, wid);
|
if window.closed {
|
||||||
}
|
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 {
|
||||||
self.cursor_manager.lock().unwrap().grab_pointer(surface);
|
Some(window.surface)
|
||||||
}
|
} else {
|
||||||
},
|
None
|
||||||
)
|
};
|
||||||
|
self.cursor_manager.lock().unwrap().grab_pointer(surface);
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue