diff --git a/api/sixtyfps-cpp/include/sixtyfps_testing.h b/api/sixtyfps-cpp/include/sixtyfps_testing.h index c52122097..2b6aa8d70 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_testing.h +++ b/api/sixtyfps-cpp/include/sixtyfps_testing.h @@ -20,16 +20,15 @@ template inline void send_mouse_click(const Component &component, float x, float y) { cbindgen_private::sixtyfps_send_mouse_click( - { &Component::component_type, const_cast(&component) }, - x, y, &component.window); + { &Component::component_type, const_cast(&component) }, x, y, + &component.window); } template -inline void send_keyboard_string_sequence(const Component &component, const sixtyfps::SharedString &str) +inline void send_keyboard_string_sequence(const Component &component, + const sixtyfps::SharedString &str) { - cbindgen_private::send_keyboard_string_sequence( - { &Component::component_type, const_cast(&component) }, - &str, &component.window); + cbindgen_private::send_keyboard_string_sequence(&str, &component.window); } #define assert_eq(A, B) \ diff --git a/api/sixtyfps-node/native/lib.rs b/api/sixtyfps-node/native/lib.rs index 34651c587..31d62e63a 100644 --- a/api/sixtyfps-node/native/lib.rs +++ b/api/sixtyfps-node/native/lib.rs @@ -454,7 +454,7 @@ declare_types! { let comp = this.borrow(&lock).0.clone(); let component = comp.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?; run_scoped(&mut cx,this.downcast().unwrap(), || { - sixtyfps_corelib::tests::send_keyboard_string_sequence(component.borrow(), &sequence.into(), &component.window()); + sixtyfps_corelib::tests::send_keyboard_string_sequence(&sequence.into(), &component.window()); Ok(()) })?; Ok(JsUndefined::new().as_value(&mut cx)) diff --git a/api/sixtyfps-rs/lib.rs b/api/sixtyfps-rs/lib.rs index 967265b9c..4f76568de 100644 --- a/api/sixtyfps-rs/lib.rs +++ b/api/sixtyfps-rs/lib.rs @@ -335,7 +335,6 @@ pub mod testing { key_codes: &[crate::re_exports::KeyCode], ) { sixtyfps_corelib::tests::sixtyfps_send_key_clicks( - vtable::VRef::new_pin(component), &crate::re_exports::Slice::from_slice(key_codes), component.component_window(), ) @@ -349,7 +348,6 @@ pub mod testing { sequence: &str, ) { sixtyfps_corelib::tests::send_keyboard_string_sequence( - vtable::VRef::new_pin(component), &super::SharedString::from(sequence), component.component_window(), ) diff --git a/sixtyfps_runtime/corelib/eventloop.rs b/sixtyfps_runtime/corelib/eventloop.rs index 3323f6263..4f94bd4d7 100644 --- a/sixtyfps_runtime/corelib/eventloop.rs +++ b/sixtyfps_runtime/corelib/eventloop.rs @@ -59,11 +59,7 @@ pub trait GenericWindow { /// Arguments: /// * `event`: The key event received by the windowing system. /// * `component`: The SixtyFPS compiled component that provides the tree of items. - fn process_key_input( - self: Rc, - event: &KeyEvent, - component: core::pin::Pin, - ); + fn process_key_input(self: Rc, event: &KeyEvent); /// Calls the `callback` function with the underlying winit::Window that this /// GenericWindow backs. fn with_platform_window(&self, callback: &dyn Fn(&winit::window::Window)); @@ -190,12 +186,8 @@ impl ComponentWindow { self.0.clone().current_keyboard_modifiers() } - pub(crate) fn process_key_input( - &self, - event: &KeyEvent, - component: core::pin::Pin, - ) { - self.0.clone().process_key_input(event, component) + pub(crate) fn process_key_input(&self, event: &KeyEvent) { + self.0.clone().process_key_input(event) } /// Clears the focus on any previously focused item and makes the provided @@ -434,7 +426,7 @@ impl EventLoop { if let Some(ref key_event) = (input, window.current_keyboard_modifiers()).try_into().ok() { - window.clone().process_key_input(key_event, component); + window.clone().process_key_input(key_event); // FIXME: remove this, it should be based on actual changes rather than this window.request_redraw(); } @@ -458,7 +450,7 @@ impl EventLoop { unicode_scalar: ch.into(), modifiers, }; - window.clone().process_key_input(&key_event, component); + window.clone().process_key_input(&key_event); // FIXME: remove this, it should be based on actual changes rather than this window.request_redraw(); } diff --git a/sixtyfps_runtime/corelib/graphics.rs b/sixtyfps_runtime/corelib/graphics.rs index 22ee47932..e2fd42d78 100644 --- a/sixtyfps_runtime/corelib/graphics.rs +++ b/sixtyfps_runtime/corelib/graphics.rs @@ -631,12 +631,11 @@ impl crate::eventloop::GenericWindow for GraphicsWindo ); } - fn process_key_input( - self: Rc, - event: &KeyEvent, - component: core::pin::Pin, - ) { - component.as_ref().key_event(event, &crate::eventloop::ComponentWindow::new(self.clone())); + fn process_key_input(self: Rc, event: &KeyEvent) { + let component = self.component.borrow().upgrade().unwrap(); + ComponentRc::borrow_pin(&component) + .as_ref() + .key_event(event, &crate::eventloop::ComponentWindow::new(self.clone())); } fn with_platform_window(&self, callback: &dyn Fn(&winit::window::Window)) { diff --git a/sixtyfps_runtime/corelib/tests.rs b/sixtyfps_runtime/corelib/tests.rs index d8262d4cd..def2828ee 100644 --- a/sixtyfps_runtime/corelib/tests.rs +++ b/sixtyfps_runtime/corelib/tests.rs @@ -65,32 +65,24 @@ pub extern "C" fn sixtyfps_set_keyboard_modifiers( /// Simulate a key down event. #[no_mangle] pub extern "C" fn sixtyfps_send_key_clicks( - component: core::pin::Pin, key_codes: &crate::slice::Slice, window: &crate::eventloop::ComponentWindow, ) { for key_code in key_codes.iter() { - window.process_key_input( - &crate::input::KeyEvent::KeyPressed { - code: *key_code, - modifiers: window.current_keyboard_modifiers(), - }, - component, - ); - window.process_key_input( - &crate::input::KeyEvent::KeyReleased { - code: *key_code, - modifiers: window.current_keyboard_modifiers(), - }, - component, - ); + window.process_key_input(&crate::input::KeyEvent::KeyPressed { + code: *key_code, + modifiers: window.current_keyboard_modifiers(), + }); + window.process_key_input(&crate::input::KeyEvent::KeyReleased { + code: *key_code, + modifiers: window.current_keyboard_modifiers(), + }); } } /// Simulate a character input event. #[no_mangle] pub extern "C" fn send_keyboard_string_sequence( - component: core::pin::Pin, sequence: &crate::SharedString, window: &crate::eventloop::ComponentWindow, ) { @@ -98,25 +90,19 @@ pub extern "C" fn send_keyboard_string_sequence( let key_down = |maybe_code: &Option| { maybe_code.clone().map(|code| { - window.process_key_input( - &crate::input::KeyEvent::KeyPressed { - code: code, - modifiers: window.current_keyboard_modifiers(), - }, - component, - ); + window.process_key_input(&crate::input::KeyEvent::KeyPressed { + code: code, + modifiers: window.current_keyboard_modifiers(), + }); }); }; let key_up = |maybe_code: &Option| { maybe_code.clone().map(|code| { - window.process_key_input( - &crate::input::KeyEvent::KeyReleased { - code: code, - modifiers: window.current_keyboard_modifiers(), - }, - component, - ); + window.process_key_input(&crate::input::KeyEvent::KeyReleased { + code: code, + modifiers: window.current_keyboard_modifiers(), + }); }); }; @@ -131,13 +117,10 @@ pub extern "C" fn send_keyboard_string_sequence( key_down(&maybe_key_code); - window.process_key_input( - &crate::input::KeyEvent::CharacterInput { - unicode_scalar: ch.into(), - modifiers: window.current_keyboard_modifiers(), - }, - component, - ); + window.process_key_input(&crate::input::KeyEvent::CharacterInput { + unicode_scalar: ch.into(), + modifiers: window.current_keyboard_modifiers(), + }); key_up(&maybe_key_code);