Fix behaviour of window resizing on Windows.

This commit is contained in:
Josh Matthews 2019-06-01 14:40:07 -04:00
parent 9d9fff3b0a
commit 4c0afcea97
3 changed files with 14 additions and 1 deletions

View file

@ -622,6 +622,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
} }
self.send_window_size(WindowSizeType::Resize); self.send_window_size(WindowSizeType::Resize);
self.composite_if_necessary(CompositingReason::Resize);
} }
pub fn on_mouse_window_event_class(&mut self, mouse_window_event: MouseWindowEvent) { pub fn on_mouse_window_event_class(&mut self, mouse_window_event: MouseWindowEvent) {
@ -1525,4 +1526,6 @@ pub enum CompositingReason {
NewWebRenderFrame, NewWebRenderFrame,
/// WebRender has processed a scroll event and has generated a new frame. /// WebRender has processed a scroll event and has generated a new frame.
NewWebRenderScrollFrame, NewWebRenderScrollFrame,
/// The window has been resized and will need to be synchronously repainted.
Resize,
} }

View file

@ -19,6 +19,15 @@ impl GlContext {
GlContext::None => unreachable!(), GlContext::None => unreachable!(),
} }
} }
pub fn resize(&mut self, size: glutin::dpi::PhysicalSize) {
if let GlContext::NotCurrent(_) = self {
self.make_current();
}
match self {
GlContext::Current(c) => c.resize(size),
_ => unreachable!(),
}
}
pub fn make_current(&mut self) { pub fn make_current(&mut self) {
*self = match std::mem::replace(self, GlContext::None) { *self = match std::mem::replace(self, GlContext::None) {
GlContext::Current(c) => { GlContext::Current(c) => {

View file

@ -441,7 +441,8 @@ impl WindowPortsMethods for Window {
self.event_queue.borrow_mut().push(WindowEvent::Quit); self.event_queue.borrow_mut().push(WindowEvent::Quit);
}, },
glutin::WindowEvent::Resized(size) => { glutin::WindowEvent::Resized(size) => {
self.gl_context.borrow_mut().window().set_inner_size(size); let physical_size = size.to_physical(self.device_hidpi_factor().get() as f64);
self.gl_context.borrow_mut().resize(physical_size);
// window.set_inner_size() takes DeviceIndependentPixel. // window.set_inner_size() takes DeviceIndependentPixel.
let (width, height) = size.into(); let (width, height) = size.into();
let new_size = TypedSize2D::new(width, height); let new_size = TypedSize2D::new(width, height);