Skip to content

Commit

Permalink
Android: remove MonitorHandle support
Browse files Browse the repository at this point in the history
Because we don't want to force all methods on `VideoModeHandle` to return `Option`, we decided to remove the already incomplete support in Android for both types.
  • Loading branch information
daxpedda committed Jul 26, 2024
1 parent 6985d31 commit b41ae81
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 48 deletions.
1 change: 1 addition & 0 deletions src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ changelog entry.
- On Web, remove unused `platform::web::CustomCursorError::Animation`.
- Remove `MonitorHandle::size()` and `refresh_rate_millihertz()` in favor of
`MonitorHandle::current_video_mode()`.
- On Android, remove all `MonitorHandle` support instead of emitting false data.

### Fixed

Expand Down
75 changes: 27 additions & 48 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::cell::Cell;
use std::collections::VecDeque;
use std::hash::Hash;
use std::marker::PhantomData;
use std::num::{NonZeroU16, NonZeroU32};
Expand Down Expand Up @@ -200,9 +199,8 @@ impl EventLoop {
app.window_event(self.window_target(), window_id, event);
},
MainEvent::ConfigChanged { .. } => {
let monitor = MonitorHandle::new(self.android_app.clone());
let old_scale_factor = monitor.scale_factor();
let scale_factor = monitor.scale_factor();
let old_scale_factor = scale_factor(&self.android_app);
let scale_factor = scale_factor(&self.android_app);
if (scale_factor - old_scale_factor).abs() < f64::EPSILON {
let new_inner_size = Arc::new(Mutex::new(screen_size(&self.android_app)));
let window_id = window::WindowId(WindowId);
Expand Down Expand Up @@ -587,18 +585,16 @@ impl ActiveEventLoop {
}

pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle::new(self.app.clone()))
None
}

pub fn create_custom_cursor(&self, source: CustomCursorSource) -> CustomCursor {
let _ = source.inner;
CustomCursor { inner: PlatformCustomCursor }
}

pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
let mut v = VecDeque::with_capacity(1);
v.push_back(MonitorHandle::new(self.app.clone()));
v
pub fn available_monitors(&self) -> Option<MonitorHandle> {
None
}

#[inline]
Expand Down Expand Up @@ -723,21 +719,19 @@ impl Window {
}

pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle::new(self.app.clone()))
None
}

pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
let mut v = VecDeque::with_capacity(1);
v.push_back(MonitorHandle::new(self.app.clone()));
v
pub fn available_monitors(&self) -> Option<MonitorHandle> {
None
}

pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle::new(self.app.clone()))
None
}

pub fn scale_factor(&self) -> f64 {
MonitorHandle::new(self.app.clone()).scale_factor()
scale_factor(&self.app)
}

pub fn request_redraw(&self) {
Expand Down Expand Up @@ -971,68 +965,49 @@ impl Display for OsError {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct MonitorHandle {
app: AndroidApp,
}
impl PartialOrd for MonitorHandle {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for MonitorHandle {
fn cmp(&self, _other: &Self) -> std::cmp::Ordering {
std::cmp::Ordering::Equal
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MonitorHandle;

impl MonitorHandle {
pub(crate) fn new(app: AndroidApp) -> Self {
Self { app }
}

pub fn name(&self) -> Option<String> {
Some("Android Device".to_owned())
unreachable!()
}

pub fn position(&self) -> Option<PhysicalPosition<i32>> {
None
unreachable!()
}

pub fn scale_factor(&self) -> f64 {
self.app.config().density().map(|dpi| dpi as f64 / 160.0).unwrap_or(1.0)
unreachable!()
}

pub fn current_video_mode(&self) -> Option<VideoModeHandle> {
Some(VideoModeHandle { size: screen_size(&self.app), monitor: self.clone() })
unreachable!()
}

pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
self.current_video_mode().into_iter()
pub fn video_modes(&self) -> std::iter::Empty<VideoModeHandle> {
unreachable!()
}
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct VideoModeHandle {
size: PhysicalSize<u32>,
monitor: MonitorHandle,
}
pub struct VideoModeHandle;

impl VideoModeHandle {
pub fn size(&self) -> PhysicalSize<u32> {
self.size
unreachable!()
}

pub fn bit_depth(&self) -> Option<NonZeroU16> {
None
unreachable!()
}

pub fn refresh_rate_millihertz(&self) -> Option<NonZeroU32> {
None
unreachable!()
}

pub fn monitor(&self) -> MonitorHandle {
self.monitor.clone()
unreachable!()
}
}

Expand All @@ -1043,3 +1018,7 @@ fn screen_size(app: &AndroidApp) -> PhysicalSize<u32> {
PhysicalSize::new(0, 0)
}
}

fn scale_factor(app: &AndroidApp) -> f64 {
app.config().density().map(|dpi| dpi as f64 / 160.0).unwrap_or(1.0)
}

0 comments on commit b41ae81

Please sign in to comment.