chore(rustfmt): use nightly (#2325)
Stable rustfmt lacks a lot of features resulting in worse formatted code, thus use nightly formatter.
This commit is contained in:
parent
7006c7ceca
commit
7b0c7b6cb2
154 changed files with 3439 additions and 5891 deletions
|
|
@ -4,10 +4,8 @@ use objc2_foundation::{MainThreadMarker, NSObject, NSObjectProtocol};
|
|||
use super::app_state::{self, EventWrapper};
|
||||
use super::uikit::{UIApplication, UIWindow};
|
||||
use super::window::WinitUIWindow;
|
||||
use crate::{
|
||||
event::{Event, WindowEvent},
|
||||
window::WindowId as RootWindowId,
|
||||
};
|
||||
use crate::event::{Event, WindowEvent};
|
||||
use crate::window::WindowId as RootWindowId;
|
||||
|
||||
declare_class!(
|
||||
pub struct AppDelegate;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
#![deny(unused_results)]
|
||||
|
||||
use std::{
|
||||
cell::{RefCell, RefMut},
|
||||
collections::HashSet,
|
||||
fmt, mem,
|
||||
os::raw::c_void,
|
||||
ptr,
|
||||
sync::{Arc, Mutex, OnceLock},
|
||||
time::Instant,
|
||||
};
|
||||
use std::cell::{RefCell, RefMut};
|
||||
use std::collections::HashSet;
|
||||
use std::os::raw::c_void;
|
||||
use std::sync::{Arc, Mutex, OnceLock};
|
||||
use std::time::Instant;
|
||||
use std::{fmt, mem, ptr};
|
||||
|
||||
use core_foundation::base::CFRelease;
|
||||
use core_foundation::date::CFAbsoluteTimeGetCurrent;
|
||||
|
|
@ -25,12 +22,10 @@ use objc2_foundation::{
|
|||
|
||||
use super::uikit::UIView;
|
||||
use super::window::WinitUIWindow;
|
||||
use crate::{
|
||||
dpi::PhysicalSize,
|
||||
event::{Event, InnerSizeWriter, StartCause, WindowEvent},
|
||||
event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow},
|
||||
window::WindowId as RootWindowId,
|
||||
};
|
||||
use crate::dpi::PhysicalSize;
|
||||
use crate::event::{Event, InnerSizeWriter, StartCause, WindowEvent};
|
||||
use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow};
|
||||
use crate::window::WindowId as RootWindowId;
|
||||
|
||||
macro_rules! bug {
|
||||
($($msg:tt)*) => {
|
||||
|
|
@ -94,13 +89,7 @@ enum UserCallbackTransitionResult<'a> {
|
|||
|
||||
impl Event<HandlePendingUserEvents> {
|
||||
fn is_redraw(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::RedrawRequested,
|
||||
..
|
||||
}
|
||||
)
|
||||
matches!(self, Event::WindowEvent { event: WindowEvent::RedrawRequested, .. })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -216,10 +205,7 @@ impl AppState {
|
|||
}
|
||||
|
||||
fn has_launched(&self) -> bool {
|
||||
!matches!(
|
||||
self.state(),
|
||||
AppStateImpl::NotLaunched { .. } | AppStateImpl::Launching { .. }
|
||||
)
|
||||
!matches!(self.state(), AppStateImpl::NotLaunched { .. } | AppStateImpl::Launching { .. })
|
||||
}
|
||||
|
||||
fn has_terminated(&self) -> bool {
|
||||
|
|
@ -228,11 +214,9 @@ impl AppState {
|
|||
|
||||
fn will_launch_transition(&mut self, queued_handler: EventLoopHandler) {
|
||||
let (queued_windows, queued_events, queued_gpu_redraws) = match self.take_state() {
|
||||
AppStateImpl::NotLaunched {
|
||||
queued_windows,
|
||||
queued_events,
|
||||
queued_gpu_redraws,
|
||||
} => (queued_windows, queued_events, queued_gpu_redraws),
|
||||
AppStateImpl::NotLaunched { queued_windows, queued_events, queued_gpu_redraws } => {
|
||||
(queued_windows, queued_events, queued_gpu_redraws)
|
||||
},
|
||||
s => bug!("unexpected state {:?}", s),
|
||||
};
|
||||
self.set_state(AppStateImpl::Launching {
|
||||
|
|
@ -250,12 +234,7 @@ impl AppState {
|
|||
queued_events,
|
||||
queued_handler,
|
||||
queued_gpu_redraws,
|
||||
} => (
|
||||
queued_windows,
|
||||
queued_events,
|
||||
queued_handler,
|
||||
queued_gpu_redraws,
|
||||
),
|
||||
} => (queued_windows, queued_events, queued_handler, queued_gpu_redraws),
|
||||
s => bug!("unexpected state {:?}", s),
|
||||
};
|
||||
self.set_state(AppStateImpl::ProcessingEvents {
|
||||
|
|
@ -274,17 +253,10 @@ impl AppState {
|
|||
}
|
||||
|
||||
let (handler, event) = match (self.control_flow, self.take_state()) {
|
||||
(ControlFlow::Poll, AppStateImpl::PollFinished { waiting_handler }) => (
|
||||
waiting_handler,
|
||||
EventWrapper::StaticEvent(Event::NewEvents(StartCause::Poll)),
|
||||
),
|
||||
(
|
||||
ControlFlow::Wait,
|
||||
AppStateImpl::Waiting {
|
||||
waiting_handler,
|
||||
start,
|
||||
},
|
||||
) => (
|
||||
(ControlFlow::Poll, AppStateImpl::PollFinished { waiting_handler }) => {
|
||||
(waiting_handler, EventWrapper::StaticEvent(Event::NewEvents(StartCause::Poll)))
|
||||
},
|
||||
(ControlFlow::Wait, AppStateImpl::Waiting { waiting_handler, start }) => (
|
||||
waiting_handler,
|
||||
EventWrapper::StaticEvent(Event::NewEvents(StartCause::WaitCancelled {
|
||||
start,
|
||||
|
|
@ -293,10 +265,7 @@ impl AppState {
|
|||
),
|
||||
(
|
||||
ControlFlow::WaitUntil(requested_resume),
|
||||
AppStateImpl::Waiting {
|
||||
waiting_handler,
|
||||
start,
|
||||
},
|
||||
AppStateImpl::Waiting { waiting_handler, start },
|
||||
) => {
|
||||
let event = if Instant::now() >= requested_resume {
|
||||
EventWrapper::StaticEvent(Event::NewEvents(StartCause::ResumeTimeReached {
|
||||
|
|
@ -310,7 +279,7 @@ impl AppState {
|
|||
}))
|
||||
};
|
||||
(waiting_handler, event)
|
||||
}
|
||||
},
|
||||
s => bug!("`EventHandler` unexpectedly woke up {:?}", s),
|
||||
};
|
||||
|
||||
|
|
@ -326,18 +295,9 @@ impl AppState {
|
|||
// If we're not able to process an event due to recursion or `Init` not having been sent out
|
||||
// yet, then queue the events up.
|
||||
match self.state_mut() {
|
||||
&mut AppStateImpl::Launching {
|
||||
ref mut queued_events,
|
||||
..
|
||||
}
|
||||
| &mut AppStateImpl::NotLaunched {
|
||||
ref mut queued_events,
|
||||
..
|
||||
}
|
||||
| &mut AppStateImpl::InUserCallback {
|
||||
ref mut queued_events,
|
||||
..
|
||||
} => {
|
||||
&mut AppStateImpl::Launching { ref mut queued_events, .. }
|
||||
| &mut AppStateImpl::NotLaunched { ref mut queued_events, .. }
|
||||
| &mut AppStateImpl::InUserCallback { ref mut queued_events, .. } => {
|
||||
// A lifetime cast: early returns are not currently handled well with NLL, but
|
||||
// polonius handles them well. This transmute is a safe workaround.
|
||||
return unsafe {
|
||||
|
|
@ -348,60 +308,49 @@ impl AppState {
|
|||
queued_events,
|
||||
})
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
&mut AppStateImpl::ProcessingEvents { .. }
|
||||
| &mut AppStateImpl::ProcessingRedraws { .. } => {}
|
||||
| &mut AppStateImpl::ProcessingRedraws { .. } => {},
|
||||
|
||||
s @ &mut AppStateImpl::PollFinished { .. }
|
||||
| s @ &mut AppStateImpl::Waiting { .. }
|
||||
| s @ &mut AppStateImpl::Terminated => {
|
||||
bug!("unexpected attempted to process an event {:?}", s)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
let (handler, queued_gpu_redraws, active_control_flow, processing_redraws) =
|
||||
match self.take_state() {
|
||||
AppStateImpl::Launching { .. }
|
||||
| AppStateImpl::NotLaunched { .. }
|
||||
| AppStateImpl::InUserCallback { .. } => unreachable!(),
|
||||
AppStateImpl::ProcessingEvents {
|
||||
handler,
|
||||
queued_gpu_redraws,
|
||||
active_control_flow,
|
||||
} => (handler, queued_gpu_redraws, active_control_flow, false),
|
||||
AppStateImpl::ProcessingRedraws {
|
||||
handler,
|
||||
active_control_flow,
|
||||
} => (handler, Default::default(), active_control_flow, true),
|
||||
AppStateImpl::PollFinished { .. }
|
||||
| AppStateImpl::Waiting { .. }
|
||||
| AppStateImpl::Terminated => unreachable!(),
|
||||
};
|
||||
let (handler, queued_gpu_redraws, active_control_flow, processing_redraws) = match self
|
||||
.take_state()
|
||||
{
|
||||
AppStateImpl::Launching { .. }
|
||||
| AppStateImpl::NotLaunched { .. }
|
||||
| AppStateImpl::InUserCallback { .. } => unreachable!(),
|
||||
AppStateImpl::ProcessingEvents { handler, queued_gpu_redraws, active_control_flow } => {
|
||||
(handler, queued_gpu_redraws, active_control_flow, false)
|
||||
},
|
||||
AppStateImpl::ProcessingRedraws { handler, active_control_flow } => {
|
||||
(handler, Default::default(), active_control_flow, true)
|
||||
},
|
||||
AppStateImpl::PollFinished { .. }
|
||||
| AppStateImpl::Waiting { .. }
|
||||
| AppStateImpl::Terminated => unreachable!(),
|
||||
};
|
||||
self.set_state(AppStateImpl::InUserCallback {
|
||||
queued_events: Vec::new(),
|
||||
queued_gpu_redraws,
|
||||
});
|
||||
UserCallbackTransitionResult::Success {
|
||||
handler,
|
||||
active_control_flow,
|
||||
processing_redraws,
|
||||
}
|
||||
UserCallbackTransitionResult::Success { handler, active_control_flow, processing_redraws }
|
||||
}
|
||||
|
||||
fn main_events_cleared_transition(&mut self) -> HashSet<Id<WinitUIWindow>> {
|
||||
let (handler, queued_gpu_redraws, active_control_flow) = match self.take_state() {
|
||||
AppStateImpl::ProcessingEvents {
|
||||
handler,
|
||||
queued_gpu_redraws,
|
||||
active_control_flow,
|
||||
} => (handler, queued_gpu_redraws, active_control_flow),
|
||||
AppStateImpl::ProcessingEvents { handler, queued_gpu_redraws, active_control_flow } => {
|
||||
(handler, queued_gpu_redraws, active_control_flow)
|
||||
},
|
||||
s => bug!("unexpected state {:?}", s),
|
||||
};
|
||||
self.set_state(AppStateImpl::ProcessingRedraws {
|
||||
handler,
|
||||
active_control_flow,
|
||||
});
|
||||
self.set_state(AppStateImpl::ProcessingRedraws { handler, active_control_flow });
|
||||
queued_gpu_redraws
|
||||
}
|
||||
|
||||
|
|
@ -410,10 +359,9 @@ impl AppState {
|
|||
return;
|
||||
}
|
||||
let (waiting_handler, old) = match self.take_state() {
|
||||
AppStateImpl::ProcessingRedraws {
|
||||
handler,
|
||||
active_control_flow,
|
||||
} => (handler, active_control_flow),
|
||||
AppStateImpl::ProcessingRedraws { handler, active_control_flow } => {
|
||||
(handler, active_control_flow)
|
||||
},
|
||||
s => bug!("unexpected state {:?}", s),
|
||||
};
|
||||
|
||||
|
|
@ -421,41 +369,29 @@ impl AppState {
|
|||
match (old, new) {
|
||||
(ControlFlow::Wait, ControlFlow::Wait) => {
|
||||
let start = Instant::now();
|
||||
self.set_state(AppStateImpl::Waiting {
|
||||
waiting_handler,
|
||||
start,
|
||||
});
|
||||
}
|
||||
self.set_state(AppStateImpl::Waiting { waiting_handler, start });
|
||||
},
|
||||
(ControlFlow::WaitUntil(old_instant), ControlFlow::WaitUntil(new_instant))
|
||||
if old_instant == new_instant =>
|
||||
{
|
||||
let start = Instant::now();
|
||||
self.set_state(AppStateImpl::Waiting {
|
||||
waiting_handler,
|
||||
start,
|
||||
});
|
||||
}
|
||||
self.set_state(AppStateImpl::Waiting { waiting_handler, start });
|
||||
},
|
||||
(_, ControlFlow::Wait) => {
|
||||
let start = Instant::now();
|
||||
self.set_state(AppStateImpl::Waiting {
|
||||
waiting_handler,
|
||||
start,
|
||||
});
|
||||
self.set_state(AppStateImpl::Waiting { waiting_handler, start });
|
||||
self.waker.stop()
|
||||
}
|
||||
},
|
||||
(_, ControlFlow::WaitUntil(new_instant)) => {
|
||||
let start = Instant::now();
|
||||
self.set_state(AppStateImpl::Waiting {
|
||||
waiting_handler,
|
||||
start,
|
||||
});
|
||||
self.set_state(AppStateImpl::Waiting { waiting_handler, start });
|
||||
self.waker.start_at(new_instant)
|
||||
}
|
||||
},
|
||||
// Unlike on macOS, handle Poll to Poll transition here to call the waker
|
||||
(_, ControlFlow::Poll) => {
|
||||
self.set_state(AppStateImpl::PollFinished { waiting_handler });
|
||||
self.waker.start()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -478,19 +414,18 @@ impl AppState {
|
|||
pub(crate) fn set_key_window(mtm: MainThreadMarker, window: &Id<WinitUIWindow>) {
|
||||
let mut this = AppState::get_mut(mtm);
|
||||
match this.state_mut() {
|
||||
&mut AppStateImpl::NotLaunched {
|
||||
ref mut queued_windows,
|
||||
..
|
||||
} => return queued_windows.push(window.clone()),
|
||||
&mut AppStateImpl::NotLaunched { ref mut queued_windows, .. } => {
|
||||
return queued_windows.push(window.clone())
|
||||
},
|
||||
&mut AppStateImpl::ProcessingEvents { .. }
|
||||
| &mut AppStateImpl::InUserCallback { .. }
|
||||
| &mut AppStateImpl::ProcessingRedraws { .. } => {}
|
||||
| &mut AppStateImpl::ProcessingRedraws { .. } => {},
|
||||
s @ &mut AppStateImpl::Launching { .. }
|
||||
| s @ &mut AppStateImpl::Waiting { .. }
|
||||
| s @ &mut AppStateImpl::PollFinished { .. } => bug!("unexpected state {:?}", s),
|
||||
&mut AppStateImpl::Terminated => {
|
||||
panic!("Attempt to create a `Window` after the app has terminated")
|
||||
}
|
||||
},
|
||||
}
|
||||
drop(this);
|
||||
window.makeKeyAndVisible();
|
||||
|
|
@ -499,30 +434,18 @@ pub(crate) fn set_key_window(mtm: MainThreadMarker, window: &Id<WinitUIWindow>)
|
|||
pub(crate) fn queue_gl_or_metal_redraw(mtm: MainThreadMarker, window: Id<WinitUIWindow>) {
|
||||
let mut this = AppState::get_mut(mtm);
|
||||
match this.state_mut() {
|
||||
&mut AppStateImpl::NotLaunched {
|
||||
ref mut queued_gpu_redraws,
|
||||
..
|
||||
}
|
||||
| &mut AppStateImpl::Launching {
|
||||
ref mut queued_gpu_redraws,
|
||||
..
|
||||
}
|
||||
| &mut AppStateImpl::ProcessingEvents {
|
||||
ref mut queued_gpu_redraws,
|
||||
..
|
||||
}
|
||||
| &mut AppStateImpl::InUserCallback {
|
||||
ref mut queued_gpu_redraws,
|
||||
..
|
||||
} => {
|
||||
&mut AppStateImpl::NotLaunched { ref mut queued_gpu_redraws, .. }
|
||||
| &mut AppStateImpl::Launching { ref mut queued_gpu_redraws, .. }
|
||||
| &mut AppStateImpl::ProcessingEvents { ref mut queued_gpu_redraws, .. }
|
||||
| &mut AppStateImpl::InUserCallback { ref mut queued_gpu_redraws, .. } => {
|
||||
let _ = queued_gpu_redraws.insert(window);
|
||||
}
|
||||
},
|
||||
s @ &mut AppStateImpl::ProcessingRedraws { .. }
|
||||
| s @ &mut AppStateImpl::Waiting { .. }
|
||||
| s @ &mut AppStateImpl::PollFinished { .. } => bug!("unexpected state {:?}", s),
|
||||
&mut AppStateImpl::Terminated => {
|
||||
panic!("Attempt to create a `Window` after the app has terminated")
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -566,10 +489,8 @@ pub fn did_finish_launching(mtm: MainThreadMarker) {
|
|||
|
||||
let (windows, events) = AppState::get_mut(mtm).did_finish_launching_transition();
|
||||
|
||||
let events = std::iter::once(EventWrapper::StaticEvent(Event::NewEvents(
|
||||
StartCause::Init,
|
||||
)))
|
||||
.chain(events);
|
||||
let events = std::iter::once(EventWrapper::StaticEvent(Event::NewEvents(StartCause::Init)))
|
||||
.chain(events);
|
||||
handle_nonuser_events(mtm, events);
|
||||
|
||||
// the above window dance hack, could possibly trigger new windows to be created.
|
||||
|
|
@ -609,7 +530,7 @@ pub(crate) fn handle_nonuser_events<I: IntoIterator<Item = EventWrapper>>(
|
|||
UserCallbackTransitionResult::ReentrancyPrevented { queued_events } => {
|
||||
queued_events.extend(events);
|
||||
return;
|
||||
}
|
||||
},
|
||||
UserCallbackTransitionResult::Success {
|
||||
handler,
|
||||
active_control_flow,
|
||||
|
|
@ -630,7 +551,7 @@ pub(crate) fn handle_nonuser_events<I: IntoIterator<Item = EventWrapper>>(
|
|||
);
|
||||
}
|
||||
handler.handle_event(event)
|
||||
}
|
||||
},
|
||||
EventWrapper::ScaleFactorChanged(event) => handle_hidpi_proxy(&mut handler, event),
|
||||
}
|
||||
}
|
||||
|
|
@ -638,18 +559,16 @@ pub(crate) fn handle_nonuser_events<I: IntoIterator<Item = EventWrapper>>(
|
|||
loop {
|
||||
let mut this = AppState::get_mut(mtm);
|
||||
let queued_events = match this.state_mut() {
|
||||
&mut AppStateImpl::InUserCallback {
|
||||
ref mut queued_events,
|
||||
queued_gpu_redraws: _,
|
||||
} => mem::take(queued_events),
|
||||
&mut AppStateImpl::InUserCallback { ref mut queued_events, queued_gpu_redraws: _ } => {
|
||||
mem::take(queued_events)
|
||||
},
|
||||
s => bug!("unexpected state {:?}", s),
|
||||
};
|
||||
if queued_events.is_empty() {
|
||||
let queued_gpu_redraws = match this.take_state() {
|
||||
AppStateImpl::InUserCallback {
|
||||
queued_events: _,
|
||||
queued_gpu_redraws,
|
||||
} => queued_gpu_redraws,
|
||||
AppStateImpl::InUserCallback { queued_events: _, queued_gpu_redraws } => {
|
||||
queued_gpu_redraws
|
||||
},
|
||||
_ => unreachable!(),
|
||||
};
|
||||
this.app_state = Some(if processing_redraws {
|
||||
|
|
@ -657,16 +576,9 @@ pub(crate) fn handle_nonuser_events<I: IntoIterator<Item = EventWrapper>>(
|
|||
queued_gpu_redraws.is_empty(),
|
||||
"redraw queued while processing redraws"
|
||||
);
|
||||
AppStateImpl::ProcessingRedraws {
|
||||
handler,
|
||||
active_control_flow,
|
||||
}
|
||||
AppStateImpl::ProcessingRedraws { handler, active_control_flow }
|
||||
} else {
|
||||
AppStateImpl::ProcessingEvents {
|
||||
handler,
|
||||
queued_gpu_redraws,
|
||||
active_control_flow,
|
||||
}
|
||||
AppStateImpl::ProcessingEvents { handler, queued_gpu_redraws, active_control_flow }
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
|
@ -679,12 +591,13 @@ pub(crate) fn handle_nonuser_events<I: IntoIterator<Item = EventWrapper>>(
|
|||
tracing::info!("processing `RedrawRequested` during the main event loop");
|
||||
} else if processing_redraws && !event.is_redraw() {
|
||||
tracing::warn!(
|
||||
"processing non-`RedrawRequested` event after the main event loop: {:#?}",
|
||||
"processing non-`RedrawRequested` event after the main event loop: \
|
||||
{:#?}",
|
||||
event
|
||||
);
|
||||
}
|
||||
handler.handle_event(event)
|
||||
}
|
||||
},
|
||||
EventWrapper::ScaleFactorChanged(event) => handle_hidpi_proxy(&mut handler, event),
|
||||
}
|
||||
}
|
||||
|
|
@ -697,7 +610,7 @@ fn handle_user_events(mtm: MainThreadMarker) {
|
|||
match this.try_user_callback_transition() {
|
||||
UserCallbackTransitionResult::ReentrancyPrevented { .. } => {
|
||||
bug!("unexpected attempted to process an event")
|
||||
}
|
||||
},
|
||||
UserCallbackTransitionResult::Success {
|
||||
handler,
|
||||
active_control_flow,
|
||||
|
|
@ -714,18 +627,16 @@ fn handle_user_events(mtm: MainThreadMarker) {
|
|||
loop {
|
||||
let mut this = AppState::get_mut(mtm);
|
||||
let queued_events = match this.state_mut() {
|
||||
&mut AppStateImpl::InUserCallback {
|
||||
ref mut queued_events,
|
||||
queued_gpu_redraws: _,
|
||||
} => mem::take(queued_events),
|
||||
&mut AppStateImpl::InUserCallback { ref mut queued_events, queued_gpu_redraws: _ } => {
|
||||
mem::take(queued_events)
|
||||
},
|
||||
s => bug!("unexpected state {:?}", s),
|
||||
};
|
||||
if queued_events.is_empty() {
|
||||
let queued_gpu_redraws = match this.take_state() {
|
||||
AppStateImpl::InUserCallback {
|
||||
queued_events: _,
|
||||
queued_gpu_redraws,
|
||||
} => queued_gpu_redraws,
|
||||
AppStateImpl::InUserCallback { queued_events: _, queued_gpu_redraws } => {
|
||||
queued_gpu_redraws
|
||||
},
|
||||
_ => unreachable!(),
|
||||
};
|
||||
this.app_state = Some(AppStateImpl::ProcessingEvents {
|
||||
|
|
@ -754,7 +665,7 @@ pub fn handle_main_events_cleared(mtm: MainThreadMarker) {
|
|||
return;
|
||||
}
|
||||
match this.state_mut() {
|
||||
AppStateImpl::ProcessingEvents { .. } => {}
|
||||
AppStateImpl::ProcessingEvents { .. } => {},
|
||||
_ => bug!("`ProcessingRedraws` happened unexpectedly"),
|
||||
};
|
||||
drop(this);
|
||||
|
|
@ -791,11 +702,7 @@ pub fn terminated(mtm: MainThreadMarker) {
|
|||
}
|
||||
|
||||
fn handle_hidpi_proxy(handler: &mut EventLoopHandler, event: ScaleFactorChanged) {
|
||||
let ScaleFactorChanged {
|
||||
suggested_size,
|
||||
scale_factor,
|
||||
window,
|
||||
} = event;
|
||||
let ScaleFactorChanged { suggested_size, scale_factor, window } = event;
|
||||
let new_inner_size = Arc::new(Mutex::new(suggested_size));
|
||||
let event = Event::WindowEvent {
|
||||
window_id: RootWindowId(window.id()),
|
||||
|
|
@ -956,11 +863,12 @@ fn get_version() -> NSOperatingSystemVersion {
|
|||
&process_info,
|
||||
respondsToSelector: sel!(operatingSystemVersion)
|
||||
];
|
||||
// winit requires atleast iOS 8 because no one has put the time into supporting earlier os versions.
|
||||
// Older iOS versions are increasingly difficult to test. For example, Xcode 11 does not support
|
||||
// debugging on devices with an iOS version of less than 8. Another example, in order to use an iOS
|
||||
// simulator older than iOS 8, you must download an older version of Xcode (<9), and at least Xcode 7
|
||||
// has been tested to not even run on macOS 10.15 - Xcode 8 might?
|
||||
// winit requires atleast iOS 8 because no one has put the time into supporting earlier os
|
||||
// versions. Older iOS versions are increasingly difficult to test. For example,
|
||||
// Xcode 11 does not support debugging on devices with an iOS version of less than
|
||||
// 8. Another example, in order to use an iOS simulator older than iOS 8, you must
|
||||
// download an older version of Xcode (<9), and at least Xcode 7 has been tested to
|
||||
// not even run on macOS 10.15 - Xcode 8 might?
|
||||
//
|
||||
// The minimum required iOS version is likely to grow in the future.
|
||||
assert!(atleast_ios_8, "`winit` requires iOS version 8 or greater");
|
||||
|
|
@ -971,7 +879,5 @@ fn get_version() -> NSOperatingSystemVersion {
|
|||
pub fn os_capabilities() -> OSCapabilities {
|
||||
// Cache the version lookup for efficiency
|
||||
static OS_CAPABILITIES: OnceLock<OSCapabilities> = OnceLock::new();
|
||||
OS_CAPABILITIES
|
||||
.get_or_init(|| OSCapabilities::from_os_version(get_version()))
|
||||
.clone()
|
||||
OS_CAPABILITIES.get_or_init(|| OSCapabilities::from_os_version(get_version())).clone()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
use std::{
|
||||
collections::VecDeque,
|
||||
ffi::c_void,
|
||||
marker::PhantomData,
|
||||
ptr,
|
||||
sync::mpsc::{self, Receiver, Sender},
|
||||
};
|
||||
use std::collections::VecDeque;
|
||||
use std::ffi::c_void;
|
||||
use std::marker::PhantomData;
|
||||
use std::ptr;
|
||||
use std::sync::mpsc::{self, Receiver, Sender};
|
||||
|
||||
use core_foundation::base::{CFIndex, CFRelease};
|
||||
use core_foundation::runloop::{
|
||||
|
|
@ -16,23 +14,19 @@ use core_foundation::runloop::{
|
|||
use objc2::ClassType;
|
||||
use objc2_foundation::{MainThreadMarker, NSString};
|
||||
|
||||
use crate::{
|
||||
error::EventLoopError,
|
||||
event::Event,
|
||||
event_loop::{
|
||||
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, EventLoopClosed,
|
||||
},
|
||||
platform::ios::Idiom,
|
||||
platform_impl::platform::app_state::{EventLoopHandler, HandlePendingUserEvents},
|
||||
window::{CustomCursor, CustomCursorSource},
|
||||
use crate::error::EventLoopError;
|
||||
use crate::event::Event;
|
||||
use crate::event_loop::{
|
||||
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, EventLoopClosed,
|
||||
};
|
||||
use crate::platform::ios::Idiom;
|
||||
use crate::platform_impl::platform::app_state::{EventLoopHandler, HandlePendingUserEvents};
|
||||
use crate::window::{CustomCursor, CustomCursorSource};
|
||||
|
||||
use super::{app_delegate::AppDelegate, uikit::UIUserInterfaceIdiom};
|
||||
use super::app_delegate::AppDelegate;
|
||||
use super::app_state::AppState;
|
||||
use super::uikit::{UIApplication, UIApplicationMain, UIDevice, UIScreen, UIUserInterfaceIdiom};
|
||||
use super::{app_state, monitor, MonitorHandle};
|
||||
use super::{
|
||||
app_state::AppState,
|
||||
uikit::{UIApplication, UIApplicationMain, UIDevice, UIScreen},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ActiveEventLoop {
|
||||
|
|
@ -42,9 +36,7 @@ pub struct ActiveEventLoop {
|
|||
impl ActiveEventLoop {
|
||||
pub fn create_custom_cursor(&self, source: CustomCursorSource) -> CustomCursor {
|
||||
let _ = source.inner;
|
||||
CustomCursor {
|
||||
inner: super::PlatformCustomCursor,
|
||||
}
|
||||
CustomCursor { inner: super::PlatformCustomCursor }
|
||||
}
|
||||
|
||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
||||
|
|
@ -69,9 +61,7 @@ impl ActiveEventLoop {
|
|||
pub fn raw_display_handle_rwh_06(
|
||||
&self,
|
||||
) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
|
||||
Ok(rwh_06::RawDisplayHandle::UiKit(
|
||||
rwh_06::UiKitDisplayHandle::new(),
|
||||
))
|
||||
Ok(rwh_06::RawDisplayHandle::UiKit(rwh_06::UiKitDisplayHandle::new()))
|
||||
}
|
||||
|
||||
pub(crate) fn set_control_flow(&self, control_flow: ControlFlow) {
|
||||
|
|
@ -126,7 +116,7 @@ fn map_user_event<T: 'static>(
|
|||
for event in receiver.try_iter() {
|
||||
(handler)(Event::UserEvent(event), window_target);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -151,8 +141,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
unsafe {
|
||||
assert!(
|
||||
!SINGLETON_INIT,
|
||||
"Only one `EventLoop` is supported on iOS. \
|
||||
`EventLoopProxy` might be helpful"
|
||||
"Only one `EventLoop` is supported on iOS. `EventLoopProxy` might be helpful"
|
||||
);
|
||||
SINGLETON_INIT = true;
|
||||
}
|
||||
|
|
@ -166,10 +155,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
mtm,
|
||||
sender,
|
||||
receiver,
|
||||
window_target: RootActiveEventLoop {
|
||||
p: ActiveEventLoop { mtm },
|
||||
_marker: PhantomData,
|
||||
},
|
||||
window_target: RootActiveEventLoop { p: ActiveEventLoop { mtm }, _marker: PhantomData },
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -181,8 +167,8 @@ impl<T: 'static> EventLoop<T> {
|
|||
assert!(
|
||||
application.is_none(),
|
||||
"\
|
||||
`EventLoop` cannot be `run` after a call to `UIApplicationMain` on iOS\n\
|
||||
Note: `EventLoop::run_app` calls `UIApplicationMain` on iOS",
|
||||
`EventLoop` cannot be `run` after a call to `UIApplicationMain` on iOS\nNote: \
|
||||
`EventLoop::run_app` calls `UIApplicationMain` on iOS",
|
||||
);
|
||||
|
||||
let handler = map_user_event(handler, self.receiver);
|
||||
|
|
@ -194,10 +180,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
>(Box::new(handler))
|
||||
};
|
||||
|
||||
let handler = EventLoopHandler {
|
||||
handler,
|
||||
event_loop: self.window_target,
|
||||
};
|
||||
let handler = EventLoopHandler { handler, event_loop: self.window_target };
|
||||
|
||||
app_state::will_launch(self.mtm, handler);
|
||||
|
||||
|
|
@ -205,12 +188,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
let _ = AppDelegate::class();
|
||||
|
||||
unsafe {
|
||||
UIApplicationMain(
|
||||
0,
|
||||
ptr::null(),
|
||||
None,
|
||||
Some(&NSString::from_str(AppDelegate::NAME)),
|
||||
)
|
||||
UIApplicationMain(0, ptr::null(), None, Some(&NSString::from_str(AppDelegate::NAME)))
|
||||
};
|
||||
unreachable!()
|
||||
}
|
||||
|
|
@ -292,9 +270,7 @@ impl<T> EventLoopProxy<T> {
|
|||
}
|
||||
|
||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
||||
self.sender
|
||||
.send(event)
|
||||
.map_err(|::std::sync::mpsc::SendError(x)| EventLoopClosed(x))?;
|
||||
self.sender.send(event).map_err(|::std::sync::mpsc::SendError(x)| EventLoopClosed(x))?;
|
||||
unsafe {
|
||||
// let the main thread know there's a new event
|
||||
CFRunLoopSourceSignal(self.source);
|
||||
|
|
@ -307,7 +283,8 @@ impl<T> EventLoopProxy<T> {
|
|||
|
||||
fn setup_control_flow_observers() {
|
||||
unsafe {
|
||||
// begin is queued with the highest priority to ensure it is processed before other observers
|
||||
// begin is queued with the highest priority to ensure it is processed before other
|
||||
// observers
|
||||
extern "C" fn control_flow_begin_handler(
|
||||
_: CFRunLoopObserverRef,
|
||||
activity: CFRunLoopActivity,
|
||||
|
|
@ -341,7 +318,7 @@ fn setup_control_flow_observers() {
|
|||
#[allow(non_upper_case_globals)]
|
||||
match activity {
|
||||
kCFRunLoopBeforeWaiting => app_state::handle_main_events_cleared(mtm),
|
||||
kCFRunLoopExit => {} // may happen when running on macOS
|
||||
kCFRunLoopExit => {}, // may happen when running on macOS
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
@ -356,7 +333,7 @@ fn setup_control_flow_observers() {
|
|||
#[allow(non_upper_case_globals)]
|
||||
match activity {
|
||||
kCFRunLoopBeforeWaiting => app_state::handle_events_cleared(mtm),
|
||||
kCFRunLoopExit => {} // may happen when running on macOS
|
||||
kCFRunLoopExit => {}, // may happen when running on macOS
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,16 +14,15 @@ use std::fmt;
|
|||
|
||||
use crate::event::DeviceId as RootDeviceId;
|
||||
|
||||
pub(crate) use self::{
|
||||
event_loop::{
|
||||
ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle,
|
||||
PlatformSpecificEventLoopAttributes,
|
||||
},
|
||||
monitor::{MonitorHandle, VideoModeHandle},
|
||||
window::{PlatformSpecificWindowAttributes, Window, WindowId},
|
||||
pub(crate) use self::event_loop::{
|
||||
ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle,
|
||||
PlatformSpecificEventLoopAttributes,
|
||||
};
|
||||
pub(crate) use self::monitor::{MonitorHandle, VideoModeHandle};
|
||||
pub(crate) use self::window::{PlatformSpecificWindowAttributes, Window, WindowId};
|
||||
pub(crate) use crate::cursor::{
|
||||
NoCustomCursor as PlatformCustomCursor, NoCustomCursor as PlatformCustomCursorSource,
|
||||
};
|
||||
pub(crate) use crate::cursor::NoCustomCursor as PlatformCustomCursor;
|
||||
pub(crate) use crate::cursor::NoCustomCursor as PlatformCustomCursorSource;
|
||||
pub(crate) use crate::icon::NoIcon as PlatformIcon;
|
||||
pub(crate) use crate::platform_impl::Fullscreen;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
#![allow(clippy::unnecessary_cast)]
|
||||
|
||||
use std::{
|
||||
collections::{BTreeSet, VecDeque},
|
||||
fmt, hash, ptr,
|
||||
};
|
||||
use std::collections::{BTreeSet, VecDeque};
|
||||
use std::{fmt, hash, ptr};
|
||||
|
||||
use objc2::mutability::IsRetainable;
|
||||
use objc2::rc::Id;
|
||||
|
|
@ -11,11 +9,9 @@ use objc2::Message;
|
|||
use objc2_foundation::{run_on_main, MainThreadBound, MainThreadMarker, NSInteger};
|
||||
|
||||
use super::uikit::{UIScreen, UIScreenMode};
|
||||
use crate::{
|
||||
dpi::{PhysicalPosition, PhysicalSize},
|
||||
monitor::VideoModeHandle as RootVideoModeHandle,
|
||||
platform_impl::platform::app_state,
|
||||
};
|
||||
use crate::dpi::{PhysicalPosition, PhysicalSize};
|
||||
use crate::monitor::VideoModeHandle as RootVideoModeHandle;
|
||||
use crate::platform_impl::platform::app_state;
|
||||
|
||||
// Workaround for `MainThreadBound` implementing almost no traits
|
||||
#[derive(Debug)]
|
||||
|
|
@ -23,9 +19,7 @@ struct MainThreadBoundDelegateImpls<T>(MainThreadBound<Id<T>>);
|
|||
|
||||
impl<T: IsRetainable + Message> Clone for MainThreadBoundDelegateImpls<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(run_on_main(|mtm| {
|
||||
MainThreadBound::new(Id::clone(self.0.get(mtm)), mtm)
|
||||
}))
|
||||
Self(run_on_main(|mtm| MainThreadBound::new(Id::clone(self.0.get(mtm)), mtm)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -149,9 +143,7 @@ impl MonitorHandle {
|
|||
pub(crate) fn new(ui_screen: Id<UIScreen>) -> Self {
|
||||
// Holding `Id<UIScreen>` implies we're on the main thread.
|
||||
let mtm = MainThreadMarker::new().unwrap();
|
||||
Self {
|
||||
ui_screen: MainThreadBound::new(ui_screen, mtm),
|
||||
}
|
||||
Self { ui_screen: MainThreadBound::new(ui_screen, mtm) }
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<String> {
|
||||
|
|
@ -171,29 +163,21 @@ impl MonitorHandle {
|
|||
}
|
||||
|
||||
pub fn size(&self) -> PhysicalSize<u32> {
|
||||
let bounds = self
|
||||
.ui_screen
|
||||
.get_on_main(|ui_screen| ui_screen.nativeBounds());
|
||||
let bounds = self.ui_screen.get_on_main(|ui_screen| ui_screen.nativeBounds());
|
||||
PhysicalSize::new(bounds.size.width as u32, bounds.size.height as u32)
|
||||
}
|
||||
|
||||
pub fn position(&self) -> PhysicalPosition<i32> {
|
||||
let bounds = self
|
||||
.ui_screen
|
||||
.get_on_main(|ui_screen| ui_screen.nativeBounds());
|
||||
let bounds = self.ui_screen.get_on_main(|ui_screen| ui_screen.nativeBounds());
|
||||
(bounds.origin.x as f64, bounds.origin.y as f64).into()
|
||||
}
|
||||
|
||||
pub fn scale_factor(&self) -> f64 {
|
||||
self.ui_screen
|
||||
.get_on_main(|ui_screen| ui_screen.nativeScale()) as f64
|
||||
self.ui_screen.get_on_main(|ui_screen| ui_screen.nativeScale()) as f64
|
||||
}
|
||||
|
||||
pub fn refresh_rate_millihertz(&self) -> Option<u32> {
|
||||
Some(
|
||||
self.ui_screen
|
||||
.get_on_main(|ui_screen| refresh_rate_millihertz(ui_screen)),
|
||||
)
|
||||
Some(self.ui_screen.get_on_main(|ui_screen| refresh_rate_millihertz(ui_screen)))
|
||||
}
|
||||
|
||||
pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
|
||||
|
|
@ -253,8 +237,5 @@ fn refresh_rate_millihertz(uiscreen: &UIScreen) -> u32 {
|
|||
}
|
||||
|
||||
pub fn uiscreens(mtm: MainThreadMarker) -> VecDeque<MonitorHandle> {
|
||||
UIScreen::screens(mtm)
|
||||
.into_iter()
|
||||
.map(MonitorHandle::new)
|
||||
.collect()
|
||||
UIScreen::screens(mtm).into_iter().map(MonitorHandle::new).collect()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
use objc2::{
|
||||
encode::{Encode, Encoding},
|
||||
extern_class, extern_methods, mutability, ClassType,
|
||||
};
|
||||
use objc2::encode::{Encode, Encoding};
|
||||
use objc2::{extern_class, extern_methods, mutability, ClassType};
|
||||
use objc2_foundation::{CGFloat, NSInteger, NSObject, NSUInteger};
|
||||
|
||||
// https://developer.apple.com/documentation/uikit/uigesturerecognizer
|
||||
|
|
|
|||
|
|
@ -84,13 +84,10 @@ pub struct UIEdgeInsets {
|
|||
}
|
||||
|
||||
unsafe impl Encode for UIEdgeInsets {
|
||||
const ENCODING: Encoding = Encoding::Struct(
|
||||
"UIEdgeInsets",
|
||||
&[
|
||||
CGFloat::ENCODING,
|
||||
CGFloat::ENCODING,
|
||||
CGFloat::ENCODING,
|
||||
CGFloat::ENCODING,
|
||||
],
|
||||
);
|
||||
const ENCODING: Encoding = Encoding::Struct("UIEdgeInsets", &[
|
||||
CGFloat::ENCODING,
|
||||
CGFloat::ENCODING,
|
||||
CGFloat::ENCODING,
|
||||
CGFloat::ENCODING,
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,12 +15,10 @@ use super::uikit::{
|
|||
UITouchType, UITraitCollection, UIView,
|
||||
};
|
||||
use super::window::WinitUIWindow;
|
||||
use crate::{
|
||||
dpi::PhysicalPosition,
|
||||
event::{Event, Force, Touch, TouchPhase, WindowEvent},
|
||||
platform_impl::platform::DEVICE_ID,
|
||||
window::{WindowAttributes, WindowId as RootWindowId},
|
||||
};
|
||||
use crate::dpi::PhysicalPosition;
|
||||
use crate::event::{Event, Force, Touch, TouchPhase, WindowEvent};
|
||||
use crate::platform_impl::platform::DEVICE_ID;
|
||||
use crate::window::{WindowAttributes, WindowId as RootWindowId};
|
||||
|
||||
pub struct WinitViewState {
|
||||
pinch_gesture_recognizer: RefCell<Option<Id<UIPinchGestureRecognizer>>>,
|
||||
|
|
@ -314,9 +312,7 @@ impl WinitView {
|
|||
msg_send_id![UIRotationGestureRecognizer::alloc(), initWithTarget: self, action: sel!(rotationGesture:)]
|
||||
};
|
||||
self.addGestureRecognizer(&rotation);
|
||||
self.ivars()
|
||||
.rotation_gesture_recognizer
|
||||
.replace(Some(rotation));
|
||||
self.ivars().rotation_gesture_recognizer.replace(Some(rotation));
|
||||
}
|
||||
} else if let Some(recognizer) = self.ivars().rotation_gesture_recognizer.take() {
|
||||
self.removeGestureRecognizer(&recognizer);
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ use super::uikit::{
|
|||
UIDevice, UIInterfaceOrientationMask, UIRectEdge, UIResponder, UIStatusBarStyle,
|
||||
UIUserInterfaceIdiom, UIView, UIViewController,
|
||||
};
|
||||
use crate::platform::ios::{ScreenEdge, StatusBarStyle};
|
||||
use crate::{platform::ios::ValidOrientations, window::WindowAttributes};
|
||||
use crate::platform::ios::{ScreenEdge, StatusBarStyle, ValidOrientations};
|
||||
use crate::window::WindowAttributes;
|
||||
|
||||
pub struct ViewControllerState {
|
||||
prefers_status_bar_hidden: Cell<bool>,
|
||||
|
|
@ -97,16 +97,10 @@ impl WinitViewController {
|
|||
|
||||
pub(crate) fn set_preferred_screen_edges_deferring_system_gestures(&self, val: ScreenEdge) {
|
||||
let val = {
|
||||
assert_eq!(
|
||||
val.bits() & !ScreenEdge::ALL.bits(),
|
||||
0,
|
||||
"invalid `ScreenEdge`"
|
||||
);
|
||||
assert_eq!(val.bits() & !ScreenEdge::ALL.bits(), 0, "invalid `ScreenEdge`");
|
||||
UIRectEdge(val.bits().into())
|
||||
};
|
||||
self.ivars()
|
||||
.preferred_screen_edges_deferring_system_gestures
|
||||
.set(val);
|
||||
self.ivars().preferred_screen_edges_deferring_system_gestures.set(val);
|
||||
let os_capabilities = app_state::os_capabilities();
|
||||
if os_capabilities.defer_system_gestures {
|
||||
self.setNeedsUpdateOfScreenEdgesDeferringSystemGestures();
|
||||
|
|
@ -120,22 +114,19 @@ impl WinitViewController {
|
|||
mtm: MainThreadMarker,
|
||||
valid_orientations: ValidOrientations,
|
||||
) {
|
||||
let mask = match (
|
||||
valid_orientations,
|
||||
UIDevice::current(mtm).userInterfaceIdiom(),
|
||||
) {
|
||||
let mask = match (valid_orientations, UIDevice::current(mtm).userInterfaceIdiom()) {
|
||||
(ValidOrientations::LandscapeAndPortrait, UIUserInterfaceIdiom::Phone) => {
|
||||
UIInterfaceOrientationMask::AllButUpsideDown
|
||||
}
|
||||
},
|
||||
(ValidOrientations::LandscapeAndPortrait, _) => UIInterfaceOrientationMask::All,
|
||||
(ValidOrientations::Landscape, _) => UIInterfaceOrientationMask::Landscape,
|
||||
(ValidOrientations::Portrait, UIUserInterfaceIdiom::Phone) => {
|
||||
UIInterfaceOrientationMask::Portrait
|
||||
}
|
||||
},
|
||||
(ValidOrientations::Portrait, _) => {
|
||||
UIInterfaceOrientationMask::Portrait
|
||||
| UIInterfaceOrientationMask::PortraitUpsideDown
|
||||
}
|
||||
},
|
||||
};
|
||||
self.ivars().supported_orientations.set(mask);
|
||||
UIViewController::attemptRotationToDeviceOrientation();
|
||||
|
|
@ -157,15 +148,11 @@ impl WinitViewController {
|
|||
let this: Id<Self> = unsafe { msg_send_id![super(this), init] };
|
||||
|
||||
this.set_prefers_status_bar_hidden(
|
||||
window_attributes
|
||||
.platform_specific
|
||||
.prefers_status_bar_hidden,
|
||||
window_attributes.platform_specific.prefers_status_bar_hidden,
|
||||
);
|
||||
|
||||
this.set_preferred_status_bar_style(
|
||||
window_attributes
|
||||
.platform_specific
|
||||
.preferred_status_bar_style,
|
||||
window_attributes.platform_specific.preferred_status_bar_style,
|
||||
);
|
||||
|
||||
this.set_supported_interface_orientations(
|
||||
|
|
@ -174,15 +161,11 @@ impl WinitViewController {
|
|||
);
|
||||
|
||||
this.set_prefers_home_indicator_auto_hidden(
|
||||
window_attributes
|
||||
.platform_specific
|
||||
.prefers_home_indicator_hidden,
|
||||
window_attributes.platform_specific.prefers_home_indicator_hidden,
|
||||
);
|
||||
|
||||
this.set_preferred_screen_edges_deferring_system_gestures(
|
||||
window_attributes
|
||||
.platform_specific
|
||||
.preferred_screen_edges_deferring_system_gestures,
|
||||
window_attributes.platform_specific.preferred_screen_edges_deferring_system_gestures,
|
||||
);
|
||||
|
||||
this.setView(Some(view));
|
||||
|
|
|
|||
|
|
@ -14,18 +14,18 @@ use super::uikit::{
|
|||
};
|
||||
use super::view::WinitView;
|
||||
use super::view_controller::WinitViewController;
|
||||
use crate::{
|
||||
cursor::Cursor,
|
||||
dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size},
|
||||
error::{ExternalError, NotSupportedError, OsError as RootOsError},
|
||||
event::{Event, WindowEvent},
|
||||
icon::Icon,
|
||||
platform::ios::{ScreenEdge, StatusBarStyle, ValidOrientations},
|
||||
platform_impl::platform::{app_state, monitor, ActiveEventLoop, Fullscreen, MonitorHandle},
|
||||
window::{
|
||||
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes,
|
||||
WindowButtons, WindowId as RootWindowId, WindowLevel,
|
||||
},
|
||||
use crate::cursor::Cursor;
|
||||
use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
|
||||
use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError};
|
||||
use crate::event::{Event, WindowEvent};
|
||||
use crate::icon::Icon;
|
||||
use crate::platform::ios::{ScreenEdge, StatusBarStyle, ValidOrientations};
|
||||
use crate::platform_impl::platform::{
|
||||
app_state, monitor, ActiveEventLoop, Fullscreen, MonitorHandle,
|
||||
};
|
||||
use crate::window::{
|
||||
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes,
|
||||
WindowButtons, WindowId as RootWindowId, WindowLevel,
|
||||
};
|
||||
|
||||
declare_class!(
|
||||
|
|
@ -87,11 +87,11 @@ impl WinitUIWindow {
|
|||
let screen = monitor.ui_screen(mtm);
|
||||
screen.setCurrentMode(Some(video_mode.screen_mode(mtm)));
|
||||
this.setScreen(screen);
|
||||
}
|
||||
},
|
||||
Some(Fullscreen::Borderless(Some(ref monitor))) => {
|
||||
let screen = monitor.ui_screen(mtm);
|
||||
this.setScreen(screen);
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
|
@ -135,12 +135,13 @@ impl Inner {
|
|||
pub fn request_redraw(&self) {
|
||||
if self.gl_or_metal_backed {
|
||||
let mtm = MainThreadMarker::new().unwrap();
|
||||
// `setNeedsDisplay` does nothing on UIViews which are directly backed by CAEAGLLayer or CAMetalLayer.
|
||||
// Ordinarily the OS sets up a bunch of UIKit state before calling drawRect: on a UIView, but when using
|
||||
// raw or gl/metal for drawing this work is completely avoided.
|
||||
// `setNeedsDisplay` does nothing on UIViews which are directly backed by CAEAGLLayer or
|
||||
// CAMetalLayer. Ordinarily the OS sets up a bunch of UIKit state before
|
||||
// calling drawRect: on a UIView, but when using raw or gl/metal for drawing
|
||||
// this work is completely avoided.
|
||||
//
|
||||
// The docs for `setNeedsDisplay` don't mention `CAMetalLayer`; however, this has been confirmed via
|
||||
// testing.
|
||||
// The docs for `setNeedsDisplay` don't mention `CAMetalLayer`; however, this has been
|
||||
// confirmed via testing.
|
||||
//
|
||||
// https://developer.apple.com/documentation/uikit/uiview/1622437-setneedsdisplay?language=objc
|
||||
app_state::queue_gl_or_metal_redraw(mtm, self.window.clone());
|
||||
|
|
@ -153,20 +154,16 @@ impl Inner {
|
|||
|
||||
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
||||
let safe_area = self.safe_area_screen_space();
|
||||
let position = LogicalPosition {
|
||||
x: safe_area.origin.x as f64,
|
||||
y: safe_area.origin.y as f64,
|
||||
};
|
||||
let position =
|
||||
LogicalPosition { x: safe_area.origin.x as f64, y: safe_area.origin.y as f64 };
|
||||
let scale_factor = self.scale_factor();
|
||||
Ok(position.to_physical(scale_factor))
|
||||
}
|
||||
|
||||
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
||||
let screen_frame = self.screen_frame();
|
||||
let position = LogicalPosition {
|
||||
x: screen_frame.origin.x as f64,
|
||||
y: screen_frame.origin.y as f64,
|
||||
};
|
||||
let position =
|
||||
LogicalPosition { x: screen_frame.origin.x as f64, y: screen_frame.origin.y as f64 };
|
||||
let scale_factor = self.scale_factor();
|
||||
Ok(position.to_physical(scale_factor))
|
||||
}
|
||||
|
|
@ -176,10 +173,7 @@ impl Inner {
|
|||
let position = physical_position.to_logical::<f64>(scale_factor);
|
||||
let screen_frame = self.screen_frame();
|
||||
let new_screen_frame = CGRect {
|
||||
origin: CGPoint {
|
||||
x: position.x as _,
|
||||
y: position.y as _,
|
||||
},
|
||||
origin: CGPoint { x: position.x as _, y: position.y as _ },
|
||||
size: screen_frame.size,
|
||||
};
|
||||
let bounds = self.rect_from_screen_space(new_screen_frame);
|
||||
|
|
@ -307,15 +301,15 @@ impl Inner {
|
|||
let uiscreen = video_mode.monitor.ui_screen(mtm);
|
||||
uiscreen.setCurrentMode(Some(video_mode.screen_mode(mtm)));
|
||||
uiscreen.clone()
|
||||
}
|
||||
},
|
||||
Some(Fullscreen::Borderless(Some(monitor))) => monitor.ui_screen(mtm).clone(),
|
||||
Some(Fullscreen::Borderless(None)) => {
|
||||
self.current_monitor_inner().ui_screen(mtm).clone()
|
||||
}
|
||||
},
|
||||
None => {
|
||||
warn!("`Window::set_fullscreen(None)` ignored on iOS");
|
||||
return;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// this is pretty slow on iOS, so avoid doing it if we can
|
||||
|
|
@ -400,9 +394,7 @@ impl Inner {
|
|||
}
|
||||
|
||||
pub fn primary_monitor(&self) -> Option<MonitorHandle> {
|
||||
Some(MonitorHandle::new(UIScreen::main(
|
||||
MainThreadMarker::new().unwrap(),
|
||||
)))
|
||||
Some(MonitorHandle::new(UIScreen::main(MainThreadMarker::new().unwrap())))
|
||||
}
|
||||
|
||||
pub fn id(&self) -> WindowId {
|
||||
|
|
@ -505,12 +497,9 @@ impl Window {
|
|||
let size = dim.to_logical::<f64>(scale_factor as f64);
|
||||
CGRect {
|
||||
origin: screen_bounds.origin,
|
||||
size: CGSize {
|
||||
width: size.width as _,
|
||||
height: size.height as _,
|
||||
},
|
||||
size: CGSize { width: size.width as _, height: size.height as _ },
|
||||
}
|
||||
}
|
||||
},
|
||||
None => screen_bounds,
|
||||
};
|
||||
|
||||
|
|
@ -544,13 +533,11 @@ impl Window {
|
|||
let window_id = RootWindowId(window.id());
|
||||
app_state::handle_nonuser_events(
|
||||
mtm,
|
||||
std::iter::once(EventWrapper::ScaleFactorChanged(
|
||||
app_state::ScaleFactorChanged {
|
||||
window: window.clone(),
|
||||
scale_factor,
|
||||
suggested_size: size.to_physical(scale_factor),
|
||||
},
|
||||
))
|
||||
std::iter::once(EventWrapper::ScaleFactorChanged(app_state::ScaleFactorChanged {
|
||||
window: window.clone(),
|
||||
scale_factor,
|
||||
suggested_size: size.to_physical(scale_factor),
|
||||
}))
|
||||
.chain(std::iter::once(EventWrapper::StaticEvent(
|
||||
Event::WindowEvent {
|
||||
window_id,
|
||||
|
|
@ -560,15 +547,8 @@ impl Window {
|
|||
);
|
||||
}
|
||||
|
||||
let inner = Inner {
|
||||
window,
|
||||
view_controller,
|
||||
view,
|
||||
gl_or_metal_backed,
|
||||
};
|
||||
Ok(Window {
|
||||
inner: MainThreadBound::new(inner, mtm),
|
||||
})
|
||||
let inner = Inner { window, view_controller, view, gl_or_metal_backed };
|
||||
Ok(Window { inner: MainThreadBound::new(inner, mtm) })
|
||||
}
|
||||
|
||||
pub(crate) fn maybe_queue_on_main(&self, f: impl FnOnce(&Inner) + Send + 'static) {
|
||||
|
|
@ -597,9 +577,7 @@ impl Window {
|
|||
pub(crate) fn raw_display_handle_rwh_06(
|
||||
&self,
|
||||
) -> Result<rwh_06::RawDisplayHandle, rwh_06::HandleError> {
|
||||
Ok(rwh_06::RawDisplayHandle::UiKit(
|
||||
rwh_06::UiKitDisplayHandle::new(),
|
||||
))
|
||||
Ok(rwh_06::RawDisplayHandle::UiKit(rwh_06::UiKitDisplayHandle::new()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -622,13 +600,11 @@ impl Inner {
|
|||
}
|
||||
|
||||
pub fn set_prefers_home_indicator_hidden(&self, hidden: bool) {
|
||||
self.view_controller
|
||||
.set_prefers_home_indicator_auto_hidden(hidden);
|
||||
self.view_controller.set_prefers_home_indicator_auto_hidden(hidden);
|
||||
}
|
||||
|
||||
pub fn set_preferred_screen_edges_deferring_system_gestures(&self, edges: ScreenEdge) {
|
||||
self.view_controller
|
||||
.set_preferred_screen_edges_deferring_system_gestures(edges);
|
||||
self.view_controller.set_preferred_screen_edges_deferring_system_gestures(edges);
|
||||
}
|
||||
|
||||
pub fn set_prefers_status_bar_hidden(&self, hidden: bool) {
|
||||
|
|
@ -636,8 +612,7 @@ impl Inner {
|
|||
}
|
||||
|
||||
pub fn set_preferred_status_bar_style(&self, status_bar_style: StatusBarStyle) {
|
||||
self.view_controller
|
||||
.set_preferred_status_bar_style(status_bar_style);
|
||||
self.view_controller.set_preferred_status_bar_style(status_bar_style);
|
||||
}
|
||||
|
||||
pub fn recognize_pinch_gesture(&self, should_recognize: bool) {
|
||||
|
|
@ -660,14 +635,12 @@ impl Inner {
|
|||
|
||||
fn rect_to_screen_space(&self, rect: CGRect) -> CGRect {
|
||||
let screen_space = self.window.screen().coordinateSpace();
|
||||
self.window
|
||||
.convertRect_toCoordinateSpace(rect, &screen_space)
|
||||
self.window.convertRect_toCoordinateSpace(rect, &screen_space)
|
||||
}
|
||||
|
||||
fn rect_from_screen_space(&self, rect: CGRect) -> CGRect {
|
||||
let screen_space = self.window.screen().coordinateSpace();
|
||||
self.window
|
||||
.convertRect_fromCoordinateSpace(rect, &screen_space)
|
||||
self.window.convertRect_fromCoordinateSpace(rect, &screen_space)
|
||||
}
|
||||
|
||||
fn safe_area_screen_space(&self) -> CGRect {
|
||||
|
|
@ -689,7 +662,8 @@ impl Inner {
|
|||
let screen_frame = self.rect_to_screen_space(bounds);
|
||||
let status_bar_frame = {
|
||||
let app = UIApplication::shared(MainThreadMarker::new().unwrap()).expect(
|
||||
"`Window::get_inner_position` cannot be called before `EventLoop::run_app` on iOS",
|
||||
"`Window::get_inner_position` cannot be called before `EventLoop::run_app` on \
|
||||
iOS",
|
||||
);
|
||||
app.statusBarFrame()
|
||||
};
|
||||
|
|
@ -702,14 +676,8 @@ impl Inner {
|
|||
(y, height)
|
||||
};
|
||||
CGRect {
|
||||
origin: CGPoint {
|
||||
x: screen_frame.origin.x,
|
||||
y,
|
||||
},
|
||||
size: CGSize {
|
||||
width: screen_frame.size.width,
|
||||
height,
|
||||
},
|
||||
origin: CGPoint { x: screen_frame.origin.x, y },
|
||||
size: CGSize { width: screen_frame.size.width, height },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -722,9 +690,7 @@ pub struct WindowId {
|
|||
|
||||
impl WindowId {
|
||||
pub const unsafe fn dummy() -> Self {
|
||||
WindowId {
|
||||
window: std::ptr::null_mut(),
|
||||
}
|
||||
WindowId { window: std::ptr::null_mut() }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -736,9 +702,7 @@ impl From<WindowId> for u64 {
|
|||
|
||||
impl From<u64> for WindowId {
|
||||
fn from(raw_id: u64) -> Self {
|
||||
Self {
|
||||
window: raw_id as _,
|
||||
}
|
||||
Self { window: raw_id as _ }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -747,9 +711,7 @@ unsafe impl Sync for WindowId {}
|
|||
|
||||
impl From<&AnyObject> for WindowId {
|
||||
fn from(window: &AnyObject) -> WindowId {
|
||||
WindowId {
|
||||
window: window as *const _ as _,
|
||||
}
|
||||
WindowId { window: window as *const _ as _ }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue