Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native/macos: Fixes setNeedsDisplay call on arm macs #476

Merged
merged 1 commit into from
Aug 12, 2024
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
23 changes: 19 additions & 4 deletions src/native/macos.rs
Original file line number Diff line number Diff line change
@@ -612,7 +612,6 @@ unsafe fn view_base_decl(decl: &mut ClassDecl) {
payload.modifiers = new_modifiers;
}


decl.add_method(
sel!(canBecomeKey),
yes as extern "C" fn(&Object, Sel) -> BOOL,
@@ -712,6 +711,18 @@ pub fn define_opengl_view_class() -> *const Class {
}
}

// apparently, its impossible to use performSelectorOnMainThread
// with primitive type argument, so the only way to pass
// YES to setNeedsDisplay - send a no argument message
// https://stackoverflow.com/questions/6120614/passing-primitives-through-performselectoronmainthread
// It seems that the same thing applies to [NSTimer timerWithTimeInterval:...]
extern "C" fn set_needs_display_hack(this: &Object, _: Sel) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shame on you, apple, I wish we did not need to do this :(

unsafe {
msg_send_![this, setNeedsDisplay: YES];
}
}


let superclass = class!(NSView);
let mut decl: ClassDecl = ClassDecl::new("RenderViewClass", superclass).unwrap();
unsafe {
@@ -720,6 +731,10 @@ pub fn define_opengl_view_class() -> *const Class {
sel!(drawRect:),
draw_rect as extern "C" fn(&Object, Sel, ObjcId),
);
decl.add_method(
sel!(setNeedsDisplayHack),
set_needs_display_hack as extern "C" fn(&Object, Sel),
);

view_base_decl(&mut decl);
}
@@ -1118,13 +1133,13 @@ where
let timer = match conf.platform.apple_gfx_api {
AppleGfxApi::OpenGl => msg_send_![class!(NSTimer), timerWithTimeInterval:0.016 // ~60FPS
target:view
selector:sel!(setNeedsDisplay:)
userInfo:YES
selector:sel!(setNeedsDisplayHack)
userInfo:nil
repeats:YES],
AppleGfxApi::Metal => msg_send_![class!(NSTimer), timerWithTimeInterval:0.016 // ~60FPS
target:view
selector:sel!(draw)
userInfo:YES
userInfo:nil
repeats:YES],
};
msg_send_![current_runloop, addTimer:timer forMode:NSEventTrackingRunLoopMode];

Unchanged files with check annotations Beta

let d = native_display().lock().unwrap();
d.view
}
#[cfg(target_ios = "ios")]

Check warning on line 312 in src/lib.rs

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

unexpected `cfg` condition name: `target_ios`

Check warning on line 312 in src/lib.rs

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

unexpected `cfg` condition name: `target_ios`

Check warning on line 312 in src/lib.rs

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

unexpected `cfg` condition name: `target_ios`

Check warning on line 312 in src/lib.rs

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu)

unexpected `cfg` condition name: `target_ios`

Check warning on line 312 in src/lib.rs

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

unexpected `cfg` condition name: `target_ios`

Check warning on line 312 in src/lib.rs

GitHub Actions / Build (ubuntu-latest, wasm32-unknown-unknown)

unexpected `cfg` condition name: `target_ios`

Check warning on line 312 in src/lib.rs

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

unexpected `cfg` condition name: `target_ios`

Check warning on line 312 in src/lib.rs

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu)

unexpected `cfg` condition name: `target_ios`

Check warning on line 312 in src/lib.rs

GitHub Actions / Build (ubuntu-latest, armv7-unknown-linux-gnueabihf)

unexpected `cfg` condition name: `target_ios`
pub fn apple_view_ctrl() -> crate::native::apple::frameworks::ObjcId {
let d = native_display().lock().unwrap();
d.view_ctrl
unsafe {
#[cfg(target_arch = "x86_64")]
SetWindowLongPtrA(self.wnd, GWL_STYLE, win_style as _);
#[cfg(target_arch = "i686")]

Check warning on line 163 in src/native/windows.rs

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

unexpected `cfg` condition value: `i686`

Check warning on line 163 in src/native/windows.rs

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

unexpected `cfg` condition value: `i686`
SetWindowLong(self.wnd, GWL_STYLE, win_style as _);
if self.fullscreen {
fn process_request(&mut self, request: Request) {
use Request::*;
unsafe {

Check warning on line 827 in src/native/windows.rs

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

unnecessary `unsafe` block

Check warning on line 827 in src/native/windows.rs

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

unnecessary `unsafe` block
match request {
ScheduleUpdate => {
self.update_requested = true;
} => self.set_window_size(new_width as _, new_height as _),
SetWindowPosition { new_x, new_y } => self.set_window_position(new_x, new_y),
SetFullscreen(fullscreen) => self.set_fullscreen(fullscreen),
ShowKeyboard(show) => {

Check warning on line 841 in src/native/windows.rs

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

unused variable: `show`

Check warning on line 841 in src/native/windows.rs

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

unused variable: `show`
eprintln!("Not implemented for windows")
}
}
#[cfg(target_arch = "x86_64")]
SetWindowLongPtrA(wnd, GWLP_USERDATA, &mut display as *mut _ as isize);
#[cfg(target_arch = "i686")]

Check warning on line 920 in src/native/windows.rs

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

unexpected `cfg` condition value: `i686`

Check warning on line 920 in src/native/windows.rs

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

unexpected `cfg` condition value: `i686`
SetWindowLong(wnd, GWLP_USERDATA, &mut display as *mut _ as isize);
let mut done = false;