Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Sep 2, 2022
1 parent 8c6b43f commit ebe1fcc
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 254 deletions.
26 changes: 10 additions & 16 deletions src/platform_impl/ios/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
time::Instant,
};

use objc::runtime::{Object, BOOL, YES};
use objc::runtime::Object;
use once_cell::sync::Lazy;

use crate::{
Expand Down Expand Up @@ -472,10 +472,7 @@ impl AppState {
// retains window
pub unsafe fn set_key_window(window: id) {
bug_assert!(
{
let is_window: BOOL = msg_send![window, isKindOfClass: class!(UIWindow)];
is_window == YES
},
msg_send![window, isKindOfClass: class!(UIWindow)],
"set_key_window called with an incorrect type"
);
let mut this = AppState::get_mut();
Expand All @@ -502,10 +499,7 @@ pub unsafe fn set_key_window(window: id) {
// retains window
pub unsafe fn queue_gl_or_metal_redraw(window: id) {
bug_assert!(
{
let is_window: BOOL = msg_send![window, isKindOfClass: class!(UIWindow)];
is_window == YES
},
msg_send![window, isKindOfClass: class!(UIWindow)],
"set_key_window called with an incorrect type"
);
let mut this = AppState::get_mut();
Expand Down Expand Up @@ -886,8 +880,11 @@ fn get_view_and_screen_frame(window_id: id) -> (id, CGRect) {
let bounds: CGRect = msg_send![window_id, bounds];
let screen: id = msg_send![window_id, screen];
let screen_space: id = msg_send![screen, coordinateSpace];
let screen_frame: CGRect =
msg_send![window_id, convertRect:bounds toCoordinateSpace:screen_space];
let screen_frame: CGRect = msg_send![
window_id,
convertRect: bounds,
toCoordinateSpace: screen_space,
];
(view, screen_frame)
}
}
Expand Down Expand Up @@ -1019,7 +1016,7 @@ pub fn os_capabilities() -> OSCapabilities {
static OS_CAPABILITIES: Lazy<OSCapabilities> = Lazy::new(|| {
let version: NSOperatingSystemVersion = unsafe {
let process_info: id = msg_send![class!(NSProcessInfo), processInfo];
let atleast_ios_8: BOOL = msg_send![
let atleast_ios_8: bool = msg_send![
process_info,
respondsToSelector: sel!(operatingSystemVersion)
];
Expand All @@ -1030,10 +1027,7 @@ pub fn os_capabilities() -> OSCapabilities {
// 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 == YES,
"`winit` requires iOS version 8 or greater"
);
assert!(atleast_ios_8, "`winit` requires iOS version 8 or greater");
msg_send![process_info, operatingSystemVersion]
};
version.into()
Expand Down
3 changes: 2 additions & 1 deletion src/platform_impl/ios/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ pub(crate) struct PlatformSpecificEventLoopAttributes {}

impl<T: 'static> EventLoop<T> {
pub(crate) fn new(_: &PlatformSpecificEventLoopAttributes) -> EventLoop<T> {
assert_main_thread!("`EventLoop` can only be created on the main thread on iOS");

static mut SINGLETON_INIT: bool = false;
unsafe {
assert_main_thread!("`EventLoop` can only be created on the main thread on iOS");
assert!(
!SINGLETON_INIT,
"Only one `EventLoop` is supported on iOS. \
Expand Down
3 changes: 1 addition & 2 deletions src/platform_impl/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@
// window size/position.
macro_rules! assert_main_thread {
($($t:tt)*) => {
let is_main_thread: ::objc::runtime::BOOL = msg_send!(class!(NSThread), isMainThread);
if is_main_thread == ::objc::runtime::NO {
if !::objc::foundation::is_main_thread() {
panic!($($t)*);
}
};
Expand Down
18 changes: 4 additions & 14 deletions src/platform_impl/ios/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,14 @@ impl Deref for MonitorHandle {
type Target = Inner;

fn deref(&self) -> &Inner {
unsafe {
assert_main_thread!(
"`MonitorHandle` methods can only be run on the main thread on iOS"
);
}
assert_main_thread!("`MonitorHandle` methods can only be run on the main thread on iOS");
&self.inner
}
}

impl DerefMut for MonitorHandle {
fn deref_mut(&mut self) -> &mut Inner {
unsafe {
assert_main_thread!(
"`MonitorHandle` methods can only be run on the main thread on iOS"
);
}
assert_main_thread!("`MonitorHandle` methods can only be run on the main thread on iOS");
&mut self.inner
}
}
Expand All @@ -144,9 +136,7 @@ impl Clone for MonitorHandle {

impl Drop for MonitorHandle {
fn drop(&mut self) {
unsafe {
assert_main_thread!("`MonitorHandle` can only be dropped on the main thread on iOS");
}
assert_main_thread!("`MonitorHandle` can only be dropped on the main thread on iOS");
}
}

Expand Down Expand Up @@ -175,8 +165,8 @@ impl fmt::Debug for MonitorHandle {

impl MonitorHandle {
pub fn retained_new(uiscreen: id) -> MonitorHandle {
assert_main_thread!("`MonitorHandle` can only be cloned on the main thread on iOS");
unsafe {
assert_main_thread!("`MonitorHandle` can only be cloned on the main thread on iOS");
let _: id = msg_send![uiscreen, retain];
}
MonitorHandle {
Expand Down
63 changes: 28 additions & 35 deletions src/platform_impl/ios/view.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::HashMap;

use objc::{
declare::ClassDecl,
runtime::{Class, Object, Sel, BOOL, NO, YES},
declare::ClassBuilder,
runtime::{Bool, Class, Object, Sel},
};

use crate::{
Expand Down Expand Up @@ -66,7 +66,7 @@ macro_rules! add_property {
};
#[allow(non_snake_case)]
extern "C" fn $getter_name($object: &Object, _: Sel) -> $t {
unsafe { *$object.get_ivar::<$t>(VAR_NAME) }
unsafe { *$object.ivar::<$t>(VAR_NAME) }
}
$decl.add_method(
sel!($setter_name:),
Expand All @@ -93,11 +93,8 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class {

classes.entry(root_view_class).or_insert_with(move || {
let uiview_class = class!(UIView);
let is_uiview: BOOL = msg_send![root_view_class, isSubclassOfClass: uiview_class];
assert_eq!(
is_uiview, YES,
"`root_view_class` must inherit from `UIView`"
);
let is_uiview: bool = msg_send![root_view_class, isSubclassOfClass: uiview_class];
assert!(is_uiview, "`root_view_class` must inherit from `UIView`");

extern "C" fn draw_rect(object: &Object, _: Sel, rect: CGRect) {
unsafe {
Expand Down Expand Up @@ -126,8 +123,11 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class {
let window_bounds: CGRect = msg_send![window, bounds];
let screen: id = msg_send![window, screen];
let screen_space: id = msg_send![screen, coordinateSpace];
let screen_frame: CGRect =
msg_send![object, convertRect:window_bounds toCoordinateSpace:screen_space];
let screen_frame: CGRect = msg_send![
object,
convertRect: window_bounds,
toCoordinateSpace: screen_space,
];
let scale_factor: CGFloat = msg_send![screen, scale];
let size = crate::dpi::LogicalSize {
width: screen_frame.size.width as f64,
Expand Down Expand Up @@ -186,7 +186,7 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class {
let screen: id = msg_send![window, screen];
let screen_space: id = msg_send![screen, coordinateSpace];
let screen_frame: CGRect =
msg_send![object, convertRect:bounds toCoordinateSpace:screen_space];
msg_send![object, convertRect: bounds, toCoordinateSpace: screen_space];
let size = crate::dpi::LogicalSize {
width: screen_frame.size.width as _,
height: screen_frame.size.height as _,
Expand Down Expand Up @@ -281,7 +281,7 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class {
}
}

let mut decl = ClassDecl::new(&format!("WinitUIView{}", ID), root_view_class)
let mut decl = ClassBuilder::new(&format!("WinitUIView{}", ID), root_view_class)
.expect("Failed to declare class `WinitUIView`");
ID += 1;
decl.add_method(sel!(drawRect:), draw_rect as extern "C" fn(_, _, _));
Expand Down Expand Up @@ -320,19 +320,19 @@ unsafe fn get_view_controller_class() -> &'static Class {

let uiviewcontroller_class = class!(UIViewController);

extern "C" fn should_autorotate(_: &Object, _: Sel) -> BOOL {
YES
extern "C" fn should_autorotate(_: &Object, _: Sel) -> Bool {
Bool::YES
}

let mut decl = ClassDecl::new("WinitUIViewController", uiviewcontroller_class)
let mut decl = ClassBuilder::new("WinitUIViewController", uiviewcontroller_class)
.expect("Failed to declare class `WinitUIViewController`");
decl.add_method(
sel!(shouldAutorotate),
should_autorotate as extern "C" fn(_, _) -> _,
);
add_property! {
decl,
prefers_status_bar_hidden: BOOL,
prefers_status_bar_hidden: Bool,
setPrefersStatusBarHidden: |object| {
unsafe {
let _: () = msg_send![object, setNeedsStatusBarAppearanceUpdate];
Expand All @@ -342,7 +342,7 @@ unsafe fn get_view_controller_class() -> &'static Class {
}
add_property! {
decl,
prefers_home_indicator_auto_hidden: BOOL,
prefers_home_indicator_auto_hidden: Bool,
setPrefersHomeIndicatorAutoHidden:
os_capabilities.home_indicator_hidden,
OSCapabilities::home_indicator_hidden_err_msg;
Expand Down Expand Up @@ -407,7 +407,7 @@ unsafe fn get_window_class() -> &'static Class {
}
}

let mut decl = ClassDecl::new("WinitUIWindow", uiwindow_class)
let mut decl = ClassBuilder::new("WinitUIWindow", uiwindow_class)
.expect("Failed to declare class `WinitUIWindow`");
decl.add_method(
sel!(becomeKeyWindow),
Expand Down Expand Up @@ -435,7 +435,7 @@ pub(crate) unsafe fn create_view(
assert!(!view.is_null(), "Failed to create `UIView` instance");
let view: id = msg_send![view, initWithFrame: frame];
assert!(!view.is_null(), "Failed to initialize `UIView` instance");
let _: () = msg_send![view, setMultipleTouchEnabled: YES];
let _: () = msg_send![view, setMultipleTouchEnabled: Bool::YES];
if let Some(scale_factor) = platform_attributes.scale_factor {
let _: () = msg_send![view, setContentScaleFactor: scale_factor as CGFloat];
}
Expand All @@ -461,21 +461,14 @@ pub(crate) unsafe fn create_view_controller(
!view_controller.is_null(),
"Failed to initialize `UIViewController` instance"
);
let status_bar_hidden = if platform_attributes.prefers_status_bar_hidden {
YES
} else {
NO
};
let status_bar_hidden = Bool::new(platform_attributes.prefers_status_bar_hidden);
let idiom = event_loop::get_idiom();
let supported_orientations = UIInterfaceOrientationMask::from_valid_orientations_idiom(
platform_attributes.valid_orientations,
idiom,
);
let prefers_home_indicator_hidden = if platform_attributes.prefers_home_indicator_hidden {
YES
} else {
NO
};
let prefers_home_indicator_hidden =
Bool::new(platform_attributes.prefers_home_indicator_hidden);
let edges: UIRectEdge = platform_attributes
.preferred_screen_edges_deferring_system_gestures
.into();
Expand Down Expand Up @@ -540,11 +533,11 @@ pub(crate) unsafe fn create_window(
}

pub fn create_delegate_class() {
extern "C" fn did_finish_launching(_: &mut Object, _: Sel, _: id, _: id) -> BOOL {
extern "C" fn did_finish_launching(_: &mut Object, _: Sel, _: id, _: id) -> Bool {
unsafe {
app_state::did_finish_launching();
}
YES
Bool::YES
}

extern "C" fn did_become_active(_: &Object, _: Sel, _: id) {
Expand All @@ -569,8 +562,8 @@ pub fn create_delegate_class() {
if window == nil {
break;
}
let is_winit_window: BOOL = msg_send![window, isKindOfClass: class!(WinitUIWindow)];
if is_winit_window == YES {
let is_winit_window = msg_send![window, isKindOfClass: class!(WinitUIWindow)];
if is_winit_window {
events.push(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: RootWindowId(window.into()),
event: WindowEvent::Destroyed,
Expand All @@ -583,8 +576,8 @@ pub fn create_delegate_class() {
}

let ui_responder = class!(UIResponder);
let mut decl =
ClassDecl::new("AppDelegate", ui_responder).expect("Failed to declare class `AppDelegate`");
let mut decl = ClassBuilder::new("AppDelegate", ui_responder)
.expect("Failed to declare class `AppDelegate`");

unsafe {
decl.add_method(
Expand Down
Loading

0 comments on commit ebe1fcc

Please sign in to comment.