Skip to content

Commit

Permalink
Clippy fixes for windows platform (rust-windowing#2131)
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai authored Mar 23, 2022
1 parent e22c76b commit 7369551
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
6 changes: 4 additions & 2 deletions src/platform_impl/windows/event_loop/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ use crate::{
};

pub(crate) type EventLoopRunnerShared<T> = Rc<EventLoopRunner<T>>;

type EventHandler<T> = Cell<Option<Box<dyn FnMut(Event<'_, T>, &mut ControlFlow)>>>;

pub(crate) struct EventLoopRunner<T: 'static> {
// The event loop's win32 handles
pub(super) thread_msg_target: HWND,
Expand All @@ -29,8 +32,7 @@ pub(crate) struct EventLoopRunner<T: 'static> {
control_flow: Cell<ControlFlow>,
runner_state: Cell<RunnerState>,
last_events_cleared: Cell<Instant>,

event_handler: Cell<Option<Box<dyn FnMut(Event<'_, T>, &mut ControlFlow)>>>,
event_handler: EventHandler<T>,
event_buffer: RefCell<VecDeque<BufferedEvent<T>>>,

owned_windows: Cell<HashSet<HWND>>,
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/windows/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions src/platform_impl/windows/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DEVMODEW>,
}

impl PartialEq for VideoMode {
Expand Down Expand Up @@ -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),
},
});
}
Expand Down
19 changes: 5 additions & 14 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -809,8 +800,8 @@ impl<'a, T: 'static> InitData<'a, T> {
pub unsafe fn on_nccreate(&mut self, window: HWND) -> Option<isize> {
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)
});

Expand Down

0 comments on commit 7369551

Please sign in to comment.