|
| 1 | +/* |
| 2 | + Simple DirectMedia Layer |
| 3 | + Copyright (C) 1997-2023 Sam Lantinga <[email protected]> |
| 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 | + |
| 22 | +#include "SDL_internal.h" |
| 23 | +#include "../SDL_sysactionset.h" |
| 24 | +#include "SDL_sdlinput.h" |
| 25 | + |
| 26 | +static ActionSetDeviceMask sdlinput_mask = ACTIONSET_DEVICE_NONE; |
| 27 | + |
| 28 | +static int SDLINPUT_EventWatch(void *userdata, SDL_Event *event) |
| 29 | +{ |
| 30 | + /* TODO: Handle keyboard, mouse, and controller events, based on mask */ |
| 31 | + /* FIXME: Can we get keyboard/mouse hotplugging? */ |
| 32 | + return 0; |
| 33 | +} |
| 34 | + |
| 35 | +static ActionSetDeviceMask SDLINPUT_Init(ActionSetDeviceMask current_mask) |
| 36 | +{ |
| 37 | + if (!(current_mask & ACTIONSET_DEVICE_KEYBOARDMOUSE)) { |
| 38 | + sdlinput_mask |= ACTIONSET_DEVICE_KEYBOARDMOUSE; |
| 39 | + } |
| 40 | + if (!(current_mask & ACTIONSET_DEVICE_CONTROLLER)) { |
| 41 | + sdlinput_mask |= ACTIONSET_DEVICE_CONTROLLER; |
| 42 | + } |
| 43 | + if (!(current_mask & ACTIONSET_DEVICE_TOUCH)) { |
| 44 | + sdlinput_mask |= ACTIONSET_DEVICE_TOUCH; |
| 45 | + } |
| 46 | + |
| 47 | + if (sdlinput_mask == ACTIONSET_DEVICE_NONE) { |
| 48 | + return current_mask; |
| 49 | + } |
| 50 | + |
| 51 | + /* Do NOT open devices here! Let the event watcher do that! */ |
| 52 | + SDL_AddEventWatch(SDLINPUT_EventWatch, NULL); |
| 53 | + |
| 54 | + return current_mask |
| 55 | + | ACTIONSET_DEVICE_KEYBOARDMOUSE |
| 56 | + | ACTIONSET_DEVICE_CONTROLLER |
| 57 | + | ACTIONSET_DEVICE_TOUCH; |
| 58 | +} |
| 59 | + |
| 60 | +static void SDLINPUT_Quit(void) |
| 61 | +{ |
| 62 | + SDL_DelEventWatch(SDLINPUT_EventWatch, NULL); |
| 63 | + sdlinput_mask = ACTIONSET_DEVICE_NONE; |
| 64 | +} |
| 65 | + |
| 66 | +static void SDLINPUT_Update(void) |
| 67 | +{ |
| 68 | + /* Nothing to do, the event watch handles everything for us */ |
| 69 | +} |
| 70 | + |
| 71 | +SDL_ActionSetProvider SDLINPUT_provider = { |
| 72 | + SDLINPUT_Init, |
| 73 | + SDLINPUT_Quit, |
| 74 | + SDLINPUT_Update |
| 75 | +}; |
0 commit comments