mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 06:41:31 +11:00
Merge pull request #118 from ojacobson/macos-window-resize
Naive implementation of resize events for OS X.
This commit is contained in:
commit
6738f7cc2e
|
@ -43,6 +43,7 @@ struct DelegateState {
|
||||||
view: IdRef,
|
view: IdRef,
|
||||||
window: IdRef,
|
window: IdRef,
|
||||||
resize_handler: Option<fn(u32, u32)>,
|
resize_handler: Option<fn(u32, u32)>,
|
||||||
|
pending_resize: Mutex<Option<(u32, u32)>>,
|
||||||
|
|
||||||
/// Events that have been retreived with XLib but not dispatched with iterators yet
|
/// Events that have been retreived with XLib but not dispatched with iterators yet
|
||||||
pending_events: Mutex<VecDeque<Event>>,
|
pending_events: Mutex<VecDeque<Event>>,
|
||||||
|
@ -75,13 +76,15 @@ impl WindowDelegate {
|
||||||
|
|
||||||
// need to notify context before (?) event
|
// need to notify context before (?) event
|
||||||
// let _: () = msg_send![*state.context, update];
|
// let _: () = msg_send![*state.context, update];
|
||||||
|
let rect = NSView::frame(*state.view);
|
||||||
|
let scale_factor = NSWindow::backingScaleFactor(*state.window) as f32;
|
||||||
|
let width = (scale_factor * rect.size.width as f32) as u32;
|
||||||
|
let height = (scale_factor * rect.size.height as f32) as u32;
|
||||||
|
|
||||||
if let Some(handler) = state.resize_handler {
|
if let Some(handler) = state.resize_handler {
|
||||||
let rect = NSView::frame(*state.view);
|
(handler)(width, height);
|
||||||
let scale_factor = NSWindow::backingScaleFactor(*state.window) as f32;
|
|
||||||
(handler)((scale_factor * rect.size.width as f32) as u32,
|
|
||||||
(scale_factor * rect.size.height as f32) as u32);
|
|
||||||
}
|
}
|
||||||
|
*state.pending_resize.lock().unwrap() = Some((width, height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,6 +212,10 @@ impl<'a> Iterator for PollEventsIterator<'a> {
|
||||||
type Item = Event;
|
type Item = Event;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Event> {
|
fn next(&mut self) -> Option<Event> {
|
||||||
|
if let Some((width, height)) = self.window.delegate.state.pending_resize.lock().unwrap().take() {
|
||||||
|
return Some(Event::Resized(width, height));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ev) = self.window.delegate.state.pending_events.lock().unwrap().pop_front() {
|
if let Some(ev) = self.window.delegate.state.pending_events.lock().unwrap().pop_front() {
|
||||||
return Some(ev);
|
return Some(ev);
|
||||||
}
|
}
|
||||||
|
@ -238,6 +245,10 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
|
||||||
type Item = Event;
|
type Item = Event;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Event> {
|
fn next(&mut self) -> Option<Event> {
|
||||||
|
if let Some((width, height)) = self.window.delegate.state.pending_resize.lock().unwrap().take() {
|
||||||
|
return Some(Event::Resized(width, height));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ev) = self.window.delegate.state.pending_events.lock().unwrap().pop_front() {
|
if let Some(ev) = self.window.delegate.state.pending_events.lock().unwrap().pop_front() {
|
||||||
return Some(ev);
|
return Some(ev);
|
||||||
}
|
}
|
||||||
|
@ -311,6 +322,7 @@ impl Window {
|
||||||
view: view.clone(),
|
view: view.clone(),
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
resize_handler: None,
|
resize_handler: None,
|
||||||
|
pending_resize: Mutex::new(None),
|
||||||
pending_events: Mutex::new(VecDeque::new()),
|
pending_events: Mutex::new(VecDeque::new()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue