diff --git a/src/platform_impl/windows/event_loop/runner.rs b/src/platform_impl/windows/event_loop/runner.rs index 43b458bf51..fab5c61360 100644 --- a/src/platform_impl/windows/event_loop/runner.rs +++ b/src/platform_impl/windows/event_loop/runner.rs @@ -21,6 +21,9 @@ use crate::{ }; pub(crate) type EventLoopRunnerShared = Rc>; + +type EventHandler = Cell, &mut ControlFlow)>>>; + pub(crate) struct EventLoopRunner { // The event loop's win32 handles pub(super) thread_msg_target: HWND, @@ -29,8 +32,7 @@ pub(crate) struct EventLoopRunner { control_flow: Cell, runner_state: Cell, last_events_cleared: Cell, - - event_handler: Cell, &mut ControlFlow)>>>, + event_handler: EventHandler, event_buffer: RefCell>>, owned_windows: Cell>, diff --git a/src/platform_impl/windows/icon.rs b/src/platform_impl/windows/icon.rs index e09aa8cabe..8ef47d6a4a 100644 --- a/src/platform_impl/windows/icon.rs +++ b/src/platform_impl/windows/icon.rs @@ -18,7 +18,7 @@ use crate::icon::*; use super::util; impl Pixel { - fn to_bgra(&mut self) { + fn convert_to_bgra(&mut self) { mem::swap(&mut self.r, &mut self.b); } } @@ -32,7 +32,7 @@ impl RgbaIcon { unsafe { std::slice::from_raw_parts_mut(rgba.as_ptr() as *mut Pixel, pixel_count) }; for pixel in pixels { and_mask.push(pixel.a.wrapping_sub(std::u8::MAX)); // invert alpha channel - pixel.to_bgra(); + pixel.convert_to_bgra(); } assert_eq!(and_mask.len(), pixel_count); let handle = unsafe { diff --git a/src/platform_impl/windows/monitor.rs b/src/platform_impl/windows/monitor.rs index 1aacd58305..4a92eea769 100644 --- a/src/platform_impl/windows/monitor.rs +++ b/src/platform_impl/windows/monitor.rs @@ -33,7 +33,8 @@ pub struct VideoMode { pub(crate) bit_depth: u16, pub(crate) refresh_rate: u16, pub(crate) monitor: MonitorHandle, - pub(crate) native_video_mode: DEVMODEW, + // DEVMODEW is huge so we box it to avoid blowing up the size of winit::window::Fullscreen + pub(crate) native_video_mode: Box, } impl PartialEq for VideoMode { @@ -236,7 +237,7 @@ impl MonitorHandle { bit_depth: mode.dmBitsPerPel as u16, refresh_rate: mode.dmDisplayFrequency as u16, monitor: self.clone(), - native_video_mode: mode, + native_video_mode: Box::new(mode), }, }); } diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 3f632968a8..91d9467eba 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -421,22 +421,14 @@ impl Window { // Change video mode if we're transitioning to or from exclusive // fullscreen match (&old_fullscreen, &fullscreen) { - (&None, &Some(Fullscreen::Exclusive(ref video_mode))) - | ( - &Some(Fullscreen::Borderless(_)), - &Some(Fullscreen::Exclusive(ref video_mode)), - ) - | (&Some(Fullscreen::Exclusive(_)), &Some(Fullscreen::Exclusive(ref video_mode))) => - { + (_, Some(Fullscreen::Exclusive(video_mode))) => { let monitor = video_mode.monitor(); let monitor_info = monitor::get_monitor_info(monitor.inner.hmonitor()).unwrap(); - let native_video_mode = video_mode.video_mode.native_video_mode; - let res = unsafe { ChangeDisplaySettingsExW( monitor_info.szDevice.as_ptr(), - &native_video_mode, + &*video_mode.video_mode.native_video_mode, 0, CDS_FULLSCREEN, ptr::null(), @@ -449,8 +441,7 @@ impl Window { debug_assert!(res != DISP_CHANGE_FAILED); assert_eq!(res, DISP_CHANGE_SUCCESSFUL); } - (&Some(Fullscreen::Exclusive(_)), &None) - | (&Some(Fullscreen::Exclusive(_)), &Some(Fullscreen::Borderless(_))) => { + (Some(Fullscreen::Exclusive(_)), _) => { let res = unsafe { ChangeDisplaySettingsExW( ptr::null(), @@ -809,8 +800,8 @@ impl<'a, T: 'static> InitData<'a, T> { pub unsafe fn on_nccreate(&mut self, window: HWND) -> Option { let runner = self.event_loop.runner_shared.clone(); let result = runner.catch_unwind(|| { - let mut window = self.create_window(window); - let window_data = self.create_window_data(&mut window); + let window = self.create_window(window); + let window_data = self.create_window_data(&window); (window, window_data) });