Skip to content

Commit

Permalink
MessageCallbackData doesn't need to be a struct member
Browse files Browse the repository at this point in the history
  • Loading branch information
FenrirWolf committed Feb 17, 2024
1 parent f715fc6 commit 1446583
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions ctru-rs/src/applets/swkbd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type CallbackFunction = dyn Fn(&CStr) -> (CallbackResult, Option<CString>);
pub struct SoftwareKeyboard {
state: Box<SwkbdState>,
callback: Option<Box<CallbackFunction>>,
callback_data: MessageCallbackData,
error_message: Option<CString>,
initial_text: Option<CString>,
}
Expand Down Expand Up @@ -220,15 +219,6 @@ struct MessageCallbackData {
swkbd_shared_mem_ptr: *mut libc::c_void,
}

impl MessageCallbackData {
fn new() -> Self {
Self {
extra: std::ptr::null_mut(),
swkbd_shared_mem_ptr: std::ptr::null_mut(),
}
}
}

impl SoftwareKeyboard {
/// Initialize a new configuration for the Software Keyboard applet depending on how many "exit" buttons are available to the user (1, 2 or 3).
///
Expand Down Expand Up @@ -257,7 +247,6 @@ impl SoftwareKeyboard {
callback: None,
error_message: None,
initial_text: None,
callback_data: MessageCallbackData::new(),
}
}
}
Expand Down Expand Up @@ -788,13 +777,15 @@ impl SoftwareKeyboard {
unsafe {
swkbd.__bindgen_anon_1.reserved.fill(0);

if extra.callback.is_some() {
self.callback_data.extra = std::ptr::addr_of_mut!(extra);
self.callback_data.swkbd_shared_mem_ptr = swkbd_shared_mem_ptr;
let mut callback_data = MessageCallbackData {
extra: std::ptr::addr_of_mut!(extra),
swkbd_shared_mem_ptr,
};

if extra.callback.is_some() {
aptSetMessageCallback(
Some(Self::swkbd_message_callback),
std::ptr::addr_of_mut!(self.callback_data).cast(),
std::ptr::addr_of_mut!(callback_data).cast(),
);
}

Expand Down

0 comments on commit 1446583

Please sign in to comment.