From 99fdbff4e2a91a7ebb8b076edd53f381d21f911a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sun, 29 Nov 2020 16:23:58 +0100 Subject: [PATCH] macOS: remove runtime timer, use frame timer instead --- src/macos/view.rs | 28 ++-------------------------- src/macos/window.rs | 22 ---------------------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/src/macos/view.rs b/src/macos/view.rs index e5278cc..293fc04 100644 --- a/src/macos/view.rs +++ b/src/macos/view.rs @@ -21,8 +21,7 @@ use crate::{ use crate::MouseEvent::{ButtonPressed, ButtonReleased}; use super::window::{ - WindowState, WINDOW_STATE_IVAR_NAME, FRAME_TIMER_IVAR_NAME, - RUNTIME_TIMER_IVAR_NAME + WindowState, WINDOW_STATE_IVAR_NAME, FRAME_TIMER_IVAR_NAME }; @@ -70,10 +69,6 @@ unsafe fn create_view_class() -> &'static Class { accepts_first_mouse:: as extern "C" fn(&Object, Sel, id) -> BOOL ); - class.add_method( - sel!(runtimeTick:), - runtime_tick:: as extern "C" fn(&Object, Sel, id) - ); class.add_method( sel!(triggerOnFrame:), trigger_on_frame:: as extern "C" fn(&Object, Sel, id) @@ -157,7 +152,6 @@ unsafe fn create_view_class() -> &'static Class { class.add_ivar::<*mut c_void>(WINDOW_STATE_IVAR_NAME); class.add_ivar::<*mut c_void>(FRAME_TIMER_IVAR_NAME); - class.add_ivar::<*mut c_void>(RUNTIME_TIMER_IVAR_NAME); class.register() } @@ -197,20 +191,8 @@ extern "C" fn trigger_on_frame( WindowState::from_field(this) }; - state.trigger_frame(); -} - - -extern "C" fn runtime_tick( - this: &Object, - _sel: Sel, - _event: id -){ - let state: &mut WindowState = unsafe { - WindowState::from_field(this) - }; - state.handle_messages(); + state.trigger_frame(); } @@ -231,12 +213,6 @@ extern "C" fn release(this: &Object, _sel: Sel) { ); let _: () = msg_send![frame_timer_ptr as id, invalidate]; - // Invalidate runtime timer - let frame_timer_ptr: *mut c_void = *this.get_ivar( - RUNTIME_TIMER_IVAR_NAME - ); - let _: () = msg_send![frame_timer_ptr as id, invalidate]; - // Drop WindowState let state_ptr: *mut c_void = *this.get_ivar( WINDOW_STATE_IVAR_NAME diff --git a/src/macos/window.rs b/src/macos/window.rs index 11c42fc..5e35a8f 100644 --- a/src/macos/window.rs +++ b/src/macos/window.rs @@ -31,7 +31,6 @@ use super::keyboard::KeyboardState; pub(super) const WINDOW_STATE_IVAR_NAME: &str = "WINDOW_STATE_IVAR_NAME"; pub(super) const FRAME_TIMER_IVAR_NAME: &str = "FRAME_TIMER"; -pub(super) const RUNTIME_TIMER_IVAR_NAME: &str = "RUNTIME_TIMER"; pub struct Window { @@ -222,27 +221,6 @@ impl Window { ) } - // Setup runtime timer once window state is stored - unsafe { - let timer_interval = 0.01; - let selector = sel!(runtimeTick:); - - let timer: id = msg_send![ - ::objc::class!(NSTimer), - scheduledTimerWithTimeInterval:timer_interval - target:window_state_arc.window.ns_view - selector:selector - userInfo:nil - repeats:YES - ]; - - // Store pointer to timer for invalidation when view is released - (*window_state_arc.window.ns_view).set_ivar( - RUNTIME_TIMER_IVAR_NAME, - timer as *mut c_void, - ) - } - crate::WindowHandle(WindowHandle { message_tx })