Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions src/native/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,32 +326,27 @@
payload.init_event_handler();
}

let main_screen: ObjcId = unsafe { msg_send![class!(UIScreen), mainScreen] };
let screen_rect: NSRect = unsafe { msg_send![main_screen, bounds] };
let high_dpi = native_display().lock().unwrap().high_dpi;

let (screen_width, screen_height) = if high_dpi {
let scale: f64 = unsafe { msg_send![main_screen, scale] };

(
(screen_rect.size.width * scale) as i32,
(screen_rect.size.height * scale) as i32,
)
} else {
let content_scale_factor: f64 = unsafe { msg_send![payload.view, contentScaleFactor] };
(
(screen_rect.size.width * content_scale_factor) as i32,
(screen_rect.size.height * content_scale_factor) as i32,
)
// Measure the view, not the device screen — iOS-on-Mac
// windowed mode has view < UIScreen.
let view_bounds: NSRect = unsafe { msg_send![payload.view, bounds] };
let content_scale_factor: f64 =
unsafe { msg_send![payload.view, contentScaleFactor] };
let screen_width = (view_bounds.size.width * content_scale_factor) as i32;
let screen_height = (view_bounds.size.height * content_scale_factor) as i32;
let dpi_scale = content_scale_factor as f32;

let needs_update = {
let d = native_display().lock().unwrap();
d.screen_width != screen_width
|| d.screen_height != screen_height
|| d.dpi_scale != dpi_scale
};

if native_display().lock().unwrap().screen_width != screen_width
|| native_display().lock().unwrap().screen_height != screen_height
{
if needs_update {
{
let mut d = native_display().lock().unwrap();
d.screen_width = screen_width;
d.screen_height = screen_height;
d.dpi_scale = dpi_scale;
}
send_message(Message::Resize {
width: screen_width,
Expand Down Expand Up @@ -499,7 +494,7 @@
_: ObjcId,
) -> BOOL {
unsafe {
let (f, conf) = RUN_ARGS.take().unwrap();

Check warning on line 497 in src/native/ios.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

creating a mutable reference to mutable static

Check warning on line 497 in src/native/ios.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

creating a mutable reference to mutable static

let main_screen: ObjcId = msg_send![class!(UIScreen), mainScreen];
let screen_rect: NSRect = msg_send![main_screen, bounds];
Expand Down
Loading