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 wrapper for global GUI keyboard support. #1253

Merged
merged 7 commits into from
Dec 12, 2023
Merged

Conversation

XK9274
Copy link
Member

@XK9274 XK9274 commented Oct 30, 2023

Adds a keyboard wrapper library

We're now at the point where we need some level of graphical keyboard within our own bins (for example, tweaks for tGeckos new menus for about/wifi).

This PR will include the library for allow this, built from Aemii's C++ search filter source (Which means it's separate, PR for that repo to follow).

The keyboard has to be a library as it's C++ but the wrapper works well, it's fast and it returns the value cleanly, returning you back to the tweaks menu stack once complete.

As part of this it also releases the A button in Tweaks event loop, if you do not release this it stays pressed. When you return out of the wrapper the button is still pressed, take this into account in your event loops.

How to use it in your feature (If it's in tweaks):

  1. #include "components/kbinput_wrapper.h"
  2. Call the wrapper function from actions.h that will return the keyboards output, eg:
const char* action_LaunchKeyboardWrapper(const char *initial_value, const char *title) {
    const char* result = launch_keyboard(initial_value, title);
    all_changed = true;
    return result;
}
  1. On your menu item you'll need a void function so create a function to call the wrapper:
void getInputFromKeyboard() {
    const char *initial_value = "Enter here";  // The default entry in the textbox
    const char *title = "WiFi Key"; // The default title of the window
    const char* result = action_LaunchKeyboardWrapper(initial_value, title); // Call the keyboard 
    printf("RESULT = %s\n", result); //Set result to your variable or whatever
    free((void*)result); // Free the result whenever (but don't forget)
}
  1. Call it at your chosen location, for example on a tweaks menu stack item:
 list_addItem(&_menu_main,
                     (ListItem){
                         .label = "Keyboard",
                         .description = "noice",
                         .action = getInputFromKeyboard,
                         .icon_ptr = _get_menu_icon("tweaks_tools")
                     });

How to use it in your feature (If it's not in tweaks):

  1. Link the library in your makefile:
    image
  2. Steps 1 -> 3 above but define your own functions. When calling the keyboard, the function is:
    image

Example of keyboard called from menu item and output printed to terminal:

image
image

20231030212844.mp4

@XK9274 XK9274 added the enhancement New or improved feature label Oct 30, 2023
@XK9274 XK9274 added this to the v4.3 milestone Oct 30, 2023
@XK9274 XK9274 requested a review from tGecko October 30, 2023 20:08
@XK9274 XK9274 self-assigned this Oct 30, 2023
Copy link
Member

@schmurtzm schmurtzm left a comment

Choose a reason for hiding this comment

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

It will be very useful, thank you !

@schmurtzm schmurtzm enabled auto-merge December 11, 2023 23:05
@schmurtzm schmurtzm added this pull request to the merge queue Dec 12, 2023
Merged via the queue into main with commit 828c263 Dec 12, 2023
3 checks passed
@schmurtzm schmurtzm deleted the feat-add-keyboard-wrapper branch December 12, 2023 00:57
@XK9274 XK9274 changed the title FEAT: Add wrapper for global GUI keyboard support. Add wrapper for global GUI keyboard support. Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New or improved feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants