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

Add utils.showFloatingGamepadTextInput() #113

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dfabulich
Copy link
Contributor

This one was pretty weird, due to the callback.

Unlike all other callbacks in steamworks-rs, the show_gamepad_text_input and show_floating_gamepad_text_input functions expect a dismissed_cb callback as an argument to the function.

https://github.com/Noxime/steamworks-rs/blob/e9cdf88f1c436871e2f72d9726da6eceac0679d4/src/utils.rs#L281

    /// Opens a floating keyboard over the game content and sends OS keyboard keys directly to the game.
    ///
    /// The text field position is specified in pixels relative the origin of the game window and is used to
    /// position the floating keyboard in a way that doesn't cover the text field.
    ///
    /// Callback is triggered when user dismisses the text input
    pub fn show_floating_gamepad_text_input<F>(
        &self,
        keyboard_mode: FloatingGamepadTextInputMode,
        x: i32,
        y: i32,
        width: i32,
        height: i32,
        mut dismissed_cb: F,
    ) -> bool
    where
        F: FnMut() + 'static + Send, // TODO: Support FnOnce callbacks
    {
        unsafe {
            register_callback(&self._inner, move |_: FloatingGamepadTextInputDismissed| {
                dismissed_cb();
            });
            sys::SteamAPI_ISteamUtils_ShowFloatingGamepadTextInput(
                self.utils,
                keyboard_mode.into(),
                x,
                y,
                width,
                height,
            )
        }
    }

The FloatingGamepadTextInputDismissed struct simply doesn't have #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] as other callback structs do, so when I tried adding FloatingGamepadTextInputDismissed to callback.rs here in steamworks.js, the compile failed when I tried to register_callback::<steamworks::FloatingGamepadTextInputDismissed>(threadsafe_handler).

I guess I could investigate fixing that as a bug in steamworks-rs, but I don't actually happen to need the FloatingGamepadTextInputDismissed callback, myself, so, in this PR, I'm just passing show_floating_gamepad_text_input an empty callback, just to satisfy the compiler. Presumably, if someone needs the FloatingGamepadTextInputDismissed callback, they can implement it themselves (perhaps adding serde support to FloatingGamepadTextInputDismissed in steamworks-rs first, then getting that merged, and then adding it to callback.rs here.

@dfabulich dfabulich force-pushed the show-floating-gamepad-text-input branch from 2b4a770 to bf749a0 Compare August 2, 2023 16:48
@dfabulich
Copy link
Contributor Author

Would it be possible to implement a JS-based callback parameter in this case? It'd be awesome if the end user could write code like this:

showFloatingGamepadTextInput(FloatingGamepadTextInputMode.SingleLine, x, y, width, number, () => {
    console.log('callback, input dismissed');
});

My NAPI skills are still pretty weak. (I mostly write these PRs by copying and pasting! 🫠)

Implementing that would also be necessary in order to implement the non-floating showGamepadTextInput method, which returns the typed text in a callback as a string.

@ceifa
Copy link
Owner

ceifa commented Aug 29, 2023

Would it be possible to implement a JS-based callback parameter in this case? It'd be awesome if the end user could write code like this:

showFloatingGamepadTextInput(FloatingGamepadTextInputMode.SingleLine, x, y, width, number, () => {
    console.log('callback, input dismissed');
});

Agreed. We can do it with a threadsafe function on napi. I can work on it later

@dfabulich dfabulich force-pushed the show-floating-gamepad-text-input branch from bf749a0 to c4195e4 Compare August 31, 2023 02:33
@vsobotka
Copy link

If I understand correctly, this will enable us to open virtual keyboard on Steam Deck, when an input is clicked, is that correct? What is the current state? Is there some workaround until this is released?

@dfabulich
Copy link
Contributor Author

There's no workaround; we just have to wait. (Unless you know enough NAPI to fix callbacks in my PR…?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants