Skip to content

OGC: virtual keyboard support #53

Open
@mardy

Description

@mardy

The WIi and GameCube port of SDL 2 does not offer a virtual keyboard.

I'm opening this issue to propose a solution and reach at least some vague consensus before rushing to implementing something that might not get accepted.

In bullet points:

  • The Wii/GameCube do not offer a virtual keyboard, each game/application needs to implement its own
  • SDL has an API to handle virtual keyboards
  • SDL has an internal API for backends to implement/invoke a virtual keyboard
  • Writing a generic VK is not trivial:
    • How many keymaps/languages do we want to support?
    • Games probably want it to be themable
    • It will inevitably eat up some resources (RAM, disk) just for the code, let alone for fonts, graphics, sounds
  • Not all applications need a VK, it would be nice not to waste resources for the VK in their case

In light of the above, I would suggest this solution:

  1. We define a public structure which contains the method callbacks that a VK module needs to implement (very similar to the internal SDL API, linked above, but not necessarily identical); let's call it OgcVkFunctions for the time being.
  2. We augment the SDL module with an OGC-specific API which allows the application to register its own VK implementation. Something like:
    /* Registers a virtual keyboard implementation, described by the vk_functions structure.
     * Return the previously registered module, if any (this can be used to chain up to the
     * previous implementation) */
    const OgcVkFunctions *OGC_SDL_RegisterVKModule(const OgcVkFunctions *vk_functions);
  3. In the SDL OGC video module, we implement the SDL VK internal APIs by simply checking if the application registered a VK backend: if it does, we call the corresponding function. Something like:
    static OgcVkFunctions *ogc_vk_functions = NULL;
    
    /* This is the OGC implementation of StartTextInput */
    void OGC_StartTextInput(_THIS)
    {
        SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
    
        if (!ogc_vk_functions) return;
        ogc_vk_functions->start_text_input(videodata->current_window,
                                           videodata->input_rect);
    }
  4. We create a separate project, OGC_SDL_keyboard, where we develop a (simple?) keyboard shipped as a static library. The static library will export a function const OgcVkFunctions *ogc_sdl_get_vk_functions() that returns a pointer to the OgcVkFunctions structure.
  5. The application can then enable the virtual keyboard by linking to the OGC_SDL_keyboard library and calling
    OGC_SDL_RegisterVKModule(ogc_sdl_get_vk_functions());
    somewhere in its initialization code (or even later).

This solution has the benefit that applications who don't need a virtual keyboard will basically not have to pay for it, in term of resources. Applications who just need a basic keyboard can have it by just adding a line of code (which can easily be #ifdef'd out when building for other platforms), and applications who need more advanced or customized keyboards can pass their own OgcVkFunctions structure and have full control over the VK keyboard.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions