Android: remove MonitorHandle support

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.
This commit is contained in:
daxpedda 2024-07-26 15:59:17 +02:00
parent 58142680ce
commit 3bab4ef4fb
No known key found for this signature in database
GPG key ID: 43D62A3EA388E46F
2 changed files with 27 additions and 46 deletions

View file

@ -122,6 +122,7 @@ changelog entry.
- Remove `Touch::id` in favor of `Touch::finger_id`. - Remove `Touch::id` in favor of `Touch::finger_id`.
- Remove `MonitorHandle::size()` and `refresh_rate_millihertz()` in favor of - Remove `MonitorHandle::size()` and `refresh_rate_millihertz()` in favor of
`MonitorHandle::current_video_mode()`. `MonitorHandle::current_video_mode()`.
- On Android, remove all `MonitorHandle` support instead of emitting false data.
### Fixed ### Fixed

View file

@ -1,6 +1,5 @@
use std::any::Any; use std::any::Any;
use std::cell::Cell; use std::cell::Cell;
use std::collections::VecDeque;
use std::hash::Hash; use std::hash::Hash;
use std::num::{NonZeroU16, NonZeroU32}; use std::num::{NonZeroU16, NonZeroU32};
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
@ -201,9 +200,8 @@ impl EventLoop {
app.window_event(&self.window_target, window_id, event); app.window_event(&self.window_target, window_id, event);
}, },
MainEvent::ConfigChanged { .. } => { MainEvent::ConfigChanged { .. } => {
let monitor = MonitorHandle::new(self.android_app.clone()); let old_scale_factor = scale_factor(&self.android_app);
let old_scale_factor = monitor.scale_factor(); let scale_factor = scale_factor(&self.android_app);
let scale_factor = monitor.scale_factor();
if (scale_factor - old_scale_factor).abs() < f64::EPSILON { if (scale_factor - old_scale_factor).abs() < f64::EPSILON {
let new_inner_size = Arc::new(Mutex::new(screen_size(&self.android_app))); let new_inner_size = Arc::new(Mutex::new(screen_size(&self.android_app)));
let window_id = window::WindowId(WindowId); let window_id = window::WindowId(WindowId);
@ -609,12 +607,11 @@ impl RootActiveEventLoop for ActiveEventLoop {
} }
fn available_monitors(&self) -> Box<dyn Iterator<Item = RootMonitorHandle>> { fn available_monitors(&self) -> Box<dyn Iterator<Item = RootMonitorHandle>> {
let handle = RootMonitorHandle { inner: MonitorHandle::new(self.app.clone()) }; Box::new(std::iter::empty())
Box::new(vec![handle].into_iter())
} }
fn primary_monitor(&self) -> Option<RootMonitorHandle> { fn primary_monitor(&self) -> Option<RootMonitorHandle> {
Some(RootMonitorHandle { inner: MonitorHandle::new(self.app.clone()) }) None
} }
fn system_theme(&self) -> Option<Theme> { fn system_theme(&self) -> Option<Theme> {
@ -744,21 +741,19 @@ impl Window {
} }
pub fn primary_monitor(&self) -> Option<MonitorHandle> { pub fn primary_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle::new(self.app.clone())) None
} }
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> { pub fn available_monitors(&self) -> Option<MonitorHandle> {
let mut v = VecDeque::with_capacity(1); None
v.push_back(MonitorHandle::new(self.app.clone()));
v
} }
pub fn current_monitor(&self) -> Option<MonitorHandle> { pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(MonitorHandle::new(self.app.clone())) None
} }
pub fn scale_factor(&self) -> f64 { pub fn scale_factor(&self) -> f64 {
MonitorHandle::new(self.app.clone()).scale_factor() scale_factor(&self.app)
} }
pub fn request_redraw(&self) { pub fn request_redraw(&self) {
@ -957,68 +952,49 @@ impl Display for OsError {
} }
} }
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MonitorHandle { 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
}
}
impl MonitorHandle { impl MonitorHandle {
pub(crate) fn new(app: AndroidApp) -> Self {
Self { app }
}
pub fn name(&self) -> Option<String> { pub fn name(&self) -> Option<String> {
Some("Android Device".to_owned()) unreachable!()
} }
pub fn position(&self) -> Option<PhysicalPosition<i32>> { pub fn position(&self) -> Option<PhysicalPosition<i32>> {
None unreachable!()
} }
pub fn scale_factor(&self) -> f64 { 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> { 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> { pub fn video_modes(&self) -> std::iter::Empty<VideoModeHandle> {
self.current_video_mode().into_iter() unreachable!()
} }
} }
#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct VideoModeHandle { pub struct VideoModeHandle;
size: PhysicalSize<u32>,
monitor: MonitorHandle,
}
impl VideoModeHandle { impl VideoModeHandle {
pub fn size(&self) -> PhysicalSize<u32> { pub fn size(&self) -> PhysicalSize<u32> {
self.size unreachable!()
} }
pub fn bit_depth(&self) -> Option<NonZeroU16> { pub fn bit_depth(&self) -> Option<NonZeroU16> {
None unreachable!()
} }
pub fn refresh_rate_millihertz(&self) -> Option<NonZeroU32> { pub fn refresh_rate_millihertz(&self) -> Option<NonZeroU32> {
None unreachable!()
} }
pub fn monitor(&self) -> MonitorHandle { pub fn monitor(&self) -> MonitorHandle {
self.monitor.clone() unreachable!()
} }
} }
@ -1029,3 +1005,7 @@ fn screen_size(app: &AndroidApp) -> PhysicalSize<u32> {
PhysicalSize::new(0, 0) PhysicalSize::new(0, 0)
} }
} }
fn scale_factor(app: &AndroidApp) -> f64 {
app.config().density().map(|dpi| dpi as f64 / 160.0).unwrap_or(1.0)
}