diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.c | |
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.c')
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.c | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.c b/contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.c new file mode 100644 index 0000000..9967756 --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitakeyboard.c | |||
| @@ -0,0 +1,190 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | #include "SDL_internal.h" | ||
| 22 | |||
| 23 | #ifdef SDL_VIDEO_DRIVER_VITA | ||
| 24 | |||
| 25 | #include <psp2/kernel/processmgr.h> | ||
| 26 | #include <psp2/ctrl.h> | ||
| 27 | #include <psp2/hid.h> | ||
| 28 | |||
| 29 | #include "SDL_vitavideo.h" | ||
| 30 | #include "SDL_vitakeyboard.h" | ||
| 31 | #include "../../events/SDL_keyboard_c.h" | ||
| 32 | |||
| 33 | SceHidKeyboardReport k_reports[SCE_HID_MAX_REPORT]; | ||
| 34 | int keyboard_hid_handle = 0; | ||
| 35 | Uint8 prev_keys[6] = { 0 }; | ||
| 36 | Uint8 prev_modifiers = 0; | ||
| 37 | Uint8 locks = 0; | ||
| 38 | Uint8 lock_key_down = 0; | ||
| 39 | |||
| 40 | void VITA_InitKeyboard(void) | ||
| 41 | { | ||
| 42 | #ifdef SDL_VIDEO_VITA_PVR | ||
| 43 | sceSysmoduleLoadModule(SCE_SYSMODULE_IME); /** For PVR OSK Support **/ | ||
| 44 | #endif | ||
| 45 | sceHidKeyboardEnumerate(&keyboard_hid_handle, 1); | ||
| 46 | |||
| 47 | if (keyboard_hid_handle > 0) { | ||
| 48 | SDL_AddKeyboard((SDL_KeyboardID)keyboard_hid_handle, NULL, false); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | void VITA_PollKeyboard(void) | ||
| 53 | { | ||
| 54 | // We skip polling keyboard if no window is created | ||
| 55 | if (!Vita_Window) { | ||
| 56 | return; | ||
| 57 | } | ||
| 58 | |||
| 59 | if (keyboard_hid_handle > 0) { | ||
| 60 | SDL_KeyboardID keyboardID = (SDL_KeyboardID)keyboard_hid_handle; | ||
| 61 | int numReports = sceHidKeyboardRead(keyboard_hid_handle, (SceHidKeyboardReport **)&k_reports, SCE_HID_MAX_REPORT); | ||
| 62 | |||
| 63 | if (numReports < 0) { | ||
| 64 | keyboard_hid_handle = 0; | ||
| 65 | } else if (numReports) { | ||
| 66 | // Numlock and Capslock state changes only on a pressed event | ||
| 67 | // The k_report only reports the state of the LED | ||
| 68 | if (k_reports[numReports - 1].modifiers[1] & 0x1) { | ||
| 69 | if (!(locks & 0x1)) { | ||
| 70 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, true); | ||
| 71 | locks |= 0x1; | ||
| 72 | } | ||
| 73 | } else { | ||
| 74 | if (locks & 0x1) { | ||
| 75 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, false); | ||
| 76 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, true); | ||
| 77 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_NUMLOCKCLEAR, false); | ||
| 78 | locks &= ~0x1; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | if (k_reports[numReports - 1].modifiers[1] & 0x2) { | ||
| 83 | if (!(locks & 0x2)) { | ||
| 84 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, true); | ||
| 85 | locks |= 0x2; | ||
| 86 | } | ||
| 87 | } else { | ||
| 88 | if (locks & 0x2) { | ||
| 89 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, false); | ||
| 90 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, true); | ||
| 91 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_CAPSLOCK, false); | ||
| 92 | locks &= ~0x2; | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | if (k_reports[numReports - 1].modifiers[1] & 0x4) { | ||
| 97 | if (!(locks & 0x4)) { | ||
| 98 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_SCROLLLOCK, true); | ||
| 99 | locks |= 0x4; | ||
| 100 | } | ||
| 101 | } else { | ||
| 102 | if (locks & 0x4) { | ||
| 103 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_SCROLLLOCK, false); | ||
| 104 | locks &= ~0x4; | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | { | ||
| 109 | Uint8 changed_modifiers = k_reports[numReports - 1].modifiers[0] ^ prev_modifiers; | ||
| 110 | |||
| 111 | if (changed_modifiers & 0x01) { | ||
| 112 | if (prev_modifiers & 0x01) { | ||
| 113 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LCTRL, false); | ||
| 114 | } else { | ||
| 115 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LCTRL, true); | ||
| 116 | } | ||
| 117 | } | ||
| 118 | if (changed_modifiers & 0x02) { | ||
| 119 | if (prev_modifiers & 0x02) { | ||
| 120 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LSHIFT, false); | ||
| 121 | } else { | ||
| 122 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LSHIFT, true); | ||
| 123 | } | ||
| 124 | } | ||
| 125 | if (changed_modifiers & 0x04) { | ||
| 126 | if (prev_modifiers & 0x04) { | ||
| 127 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LALT, false); | ||
| 128 | } else { | ||
| 129 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LALT, true); | ||
| 130 | } | ||
| 131 | } | ||
| 132 | if (changed_modifiers & 0x08) { | ||
| 133 | if (prev_modifiers & 0x08) { | ||
| 134 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LGUI, false); | ||
| 135 | } else { | ||
| 136 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_LGUI, true); | ||
| 137 | } | ||
| 138 | } | ||
| 139 | if (changed_modifiers & 0x10) { | ||
| 140 | if (prev_modifiers & 0x10) { | ||
| 141 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RCTRL, false); | ||
| 142 | } else { | ||
| 143 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RCTRL, true); | ||
| 144 | } | ||
| 145 | } | ||
| 146 | if (changed_modifiers & 0x20) { | ||
| 147 | if (prev_modifiers & 0x20) { | ||
| 148 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RSHIFT, false); | ||
| 149 | } else { | ||
| 150 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RSHIFT, true); | ||
| 151 | } | ||
| 152 | } | ||
| 153 | if (changed_modifiers & 0x40) { | ||
| 154 | if (prev_modifiers & 0x40) { | ||
| 155 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RALT, false); | ||
| 156 | } else { | ||
| 157 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RALT, true); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | if (changed_modifiers & 0x80) { | ||
| 161 | if (prev_modifiers & 0x80) { | ||
| 162 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RGUI, false); | ||
| 163 | } else { | ||
| 164 | SDL_SendKeyboardKey(0, keyboardID, 0, SDL_SCANCODE_RGUI, true); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | prev_modifiers = k_reports[numReports - 1].modifiers[0]; | ||
| 170 | |||
| 171 | for (int i = 0; i < 6; i++) { | ||
| 172 | |||
| 173 | int keyCode = k_reports[numReports - 1].keycodes[i]; | ||
| 174 | |||
| 175 | if (keyCode != prev_keys[i]) { | ||
| 176 | |||
| 177 | if (prev_keys[i]) { | ||
| 178 | SDL_SendKeyboardKey(0, keyboardID, 0, prev_keys[i], false); | ||
| 179 | } | ||
| 180 | if (keyCode) { | ||
| 181 | SDL_SendKeyboardKey(0, keyboardID, 0, keyCode, true); | ||
| 182 | } | ||
| 183 | prev_keys[i] = keyCode; | ||
| 184 | } | ||
| 185 | } | ||
| 186 | } | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | #endif // SDL_VIDEO_DRIVER_VITA | ||
