Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
Co-Authored-By: Mads Marquart <mads@marquart.dk>
  • Loading branch information
daxpedda and madsmtm committed Aug 15, 2024
1 parent e9a4e0b commit 6a12fa1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
8 changes: 2 additions & 6 deletions src/platform_impl/apple/uikit/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use objc2_ui_kit::{UIScreen, UIScreenMode};

use super::app_state;
use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::monitor::VideoModeHandle as RootVideoModeHandle;

// Workaround for `MainThreadBound` implementing almost no traits
#[derive(Debug)]
Expand Down Expand Up @@ -170,17 +169,14 @@ impl MonitorHandle {
pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
run_on_main(|mtm| {
let ui_screen = self.ui_screen(mtm);
// Use Ord impl of RootVideoModeHandle

let modes: Vec<_> = ui_screen
.availableModes()
.into_iter()
.map(|mode| RootVideoModeHandle {
video_mode: VideoModeHandle::new(ui_screen.clone(), mode, mtm),
})
.map(|mode| VideoModeHandle::new(ui_screen.clone(), mode, mtm))
.collect();

modes.into_iter().map(|mode| mode.video_mode)
modes.into_iter()
})
}

Expand Down
15 changes: 6 additions & 9 deletions src/platform_impl/windows/monitor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::VecDeque;
use std::collections::{HashSet, VecDeque};
use std::hash::Hash;
use std::num::{NonZeroU16, NonZeroU32};
use std::{io, mem, ptr};
Expand All @@ -13,7 +13,6 @@ use windows_sys::Win32::Graphics::Gdi::{

use super::util::decode_wide;
use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::monitor::VideoModeHandle as RootVideoModeHandle;
use crate::platform_impl::platform::dpi::{dpi_to_scale_factor, get_monitor_dpi};
use crate::platform_impl::platform::util::has_flag;
use crate::platform_impl::platform::window::Window;
Expand Down Expand Up @@ -225,15 +224,14 @@ impl MonitorHandle {
pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
// EnumDisplaySettingsExW can return duplicate values (or some of the
// fields are probably changing, but we aren't looking at those fields
// anyway), so we're using a BTreeSet deduplicate
let mut modes = Vec::new();
let mod_map = |mode: RootVideoModeHandle| mode.video_mode;
// anyway), so we're using a HashSet to deduplicate.
let mut modes = HashSet::new();

let monitor_info = match get_monitor_info(self.0) {
Ok(monitor_info) => monitor_info,
Err(error) => {
tracing::warn!("Error from get_monitor_info: {error}");
return modes.into_iter().map(mod_map);
return modes.into_iter();
},
};

Expand All @@ -247,12 +245,11 @@ impl MonitorHandle {
break;
}

modes
.push(RootVideoModeHandle { video_mode: VideoModeHandle::new(self.clone(), mode) });
modes.insert(VideoModeHandle::new(self.clone(), mode));

i += 1;
}

modes.into_iter().map(mod_map)
modes.into_iter()
}
}

0 comments on commit 6a12fa1

Please sign in to comment.