swkbd.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/common_funcs.h"
  6. #include "common/common_types.h"
  7. #include "core/hle/applets/applet.h"
  8. #include "core/hle/kernel/kernel.h"
  9. #include "core/hle/kernel/shared_memory.h"
  10. #include "core/hle/result.h"
  11. #include "core/hle/service/apt/apt.h"
  12. namespace HLE {
  13. namespace Applets {
  14. struct SoftwareKeyboardConfig {
  15. INSERT_PADDING_WORDS(0x8);
  16. u16 max_text_length; ///< Maximum length of the input text
  17. INSERT_PADDING_BYTES(0x6E);
  18. char16_t display_text[65]; ///< Text to display when asking the user for input
  19. INSERT_PADDING_BYTES(0xE);
  20. u32 default_text_offset; ///< Offset of the default text in the output SharedMemory
  21. INSERT_PADDING_WORDS(0x3);
  22. u32 shared_memory_size; ///< Size of the SharedMemory
  23. INSERT_PADDING_WORDS(0x1);
  24. u32 return_code; ///< Return code of the SoftwareKeyboard, usually 2, other values are unknown
  25. INSERT_PADDING_WORDS(0x2);
  26. u32 text_offset; ///< Offset in the SharedMemory where the output text starts
  27. u16 text_length; ///< Length in characters of the output text
  28. INSERT_PADDING_BYTES(0x2B6);
  29. };
  30. /**
  31. * The size of this structure (0x400) has been verified via reverse engineering of multiple games
  32. * that use the software keyboard.
  33. */
  34. static_assert(sizeof(SoftwareKeyboardConfig) == 0x400, "Software Keyboard Config size is wrong");
  35. class SoftwareKeyboard final : public Applet {
  36. public:
  37. SoftwareKeyboard(Service::APT::AppletId id) : Applet(id) {}
  38. ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override;
  39. ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override;
  40. void Update() override;
  41. /**
  42. * Draws a keyboard to the current bottom screen framebuffer.
  43. */
  44. void DrawScreenKeyboard();
  45. /**
  46. * Sends the LibAppletClosing signal to the application,
  47. * along with the relevant data buffers.
  48. */
  49. void Finalize();
  50. private:
  51. /// This SharedMemory will be created when we receive the LibAppJustStarted message.
  52. /// It holds the framebuffer info retrieved by the application with
  53. /// GSPGPU::ImportDisplayCaptureInfo
  54. Kernel::SharedPtr<Kernel::SharedMemory> framebuffer_memory;
  55. /// SharedMemory where the output text will be stored
  56. Kernel::SharedPtr<Kernel::SharedMemory> text_memory;
  57. /// Configuration of this instance of the SoftwareKeyboard, as received from the application
  58. SoftwareKeyboardConfig config;
  59. };
  60. }
  61. } // namespace