Skip to content

Commit

Permalink
SDL_GetKeyboards() follows the SDL_GetStringRule
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 19, 2024
1 parent 945154d commit c58bad8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 deletions.
9 changes: 5 additions & 4 deletions include/SDL3/SDL_keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasKeyboard(void);
* power buttons, etc. You should wait for input from a device before you
* consider it actively in use.
*
* \param count a pointer filled in with the number of keyboards returned.
* \returns a 0 terminated array of keyboards instance IDs which should be
* freed with SDL_free(), or NULL on failure; call SDL_GetError() for
* The returned array follows the SDL_GetStringRule, and will be automatically freed later.
*
* \param count a pointer filled in with the number of keyboards returned, may be NULL.
* \returns a 0 terminated array of keyboards instance IDs or NULL on failure; call SDL_GetError() for
* more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetKeyboardNameForID
* \sa SDL_HasKeyboard
*/
extern SDL_DECLSPEC SDL_KeyboardID * SDLCALL SDL_GetKeyboards(int *count);
extern SDL_DECLSPEC const SDL_KeyboardID * SDLCALL SDL_GetKeyboards(int *count);

/**
* Get the name of a keyboard.
Expand Down
2 changes: 1 addition & 1 deletion src/dynapi/SDL_dynapi_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ SDL_DYNAPI_PROC(const char*,SDL_GetKeyName,(SDL_Keycode a),(a),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetKeyboardFocus,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetKeyboardNameForID,(SDL_KeyboardID a),(a),return)
SDL_DYNAPI_PROC(const Uint8*,SDL_GetKeyboardState,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_KeyboardID*,SDL_GetKeyboards,(int *a),(a),return)
SDL_DYNAPI_PROC(const SDL_KeyboardID*,SDL_GetKeyboards,(int *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_GetLogOutputFunction,(SDL_LogOutputFunction *a, void **b),(a,b),)
SDL_DYNAPI_PROC(SDL_LogPriority,SDL_GetLogPriority,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetMasksForPixelFormat,(SDL_PixelFormat a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return)
Expand Down
4 changes: 2 additions & 2 deletions src/events/SDL_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ SDL_bool SDL_HasKeyboard(void)
return (SDL_keyboard_count > 0);
}

SDL_KeyboardID *SDL_GetKeyboards(int *count)
const SDL_KeyboardID *SDL_GetKeyboards(int *count)
{
int i;
SDL_KeyboardID *keyboards;
Expand All @@ -198,7 +198,7 @@ SDL_KeyboardID *SDL_GetKeyboards(int *count)
}
}

return keyboards;
return SDL_FreeLater(keyboards);
}

const char *SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id)
Expand Down
5 changes: 2 additions & 3 deletions src/video/windows/SDL_windowsevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ static void AddDeviceID(Uint32 deviceID, Uint32 **list, int *count)
*list = new_list;
}

static SDL_bool HasDeviceID(Uint32 deviceID, Uint32 *list, int count)
static SDL_bool HasDeviceID(Uint32 deviceID, const Uint32 *list, int count)
{
for (int i = 0; i < count; ++i) {
if (deviceID == list[i]) {
Expand Down Expand Up @@ -867,7 +867,7 @@ void WIN_CheckKeyboardAndMouseHotplug(SDL_VideoDevice *_this, SDL_bool initial_c
PRAWINPUTDEVICELIST raw_devices = NULL;
UINT raw_device_count = 0;
int old_keyboard_count = 0;
SDL_KeyboardID *old_keyboards = NULL;
const SDL_KeyboardID *old_keyboards = NULL;
int new_keyboard_count = 0;
SDL_KeyboardID *new_keyboards = NULL;
int old_mouse_count = 0;
Expand Down Expand Up @@ -982,7 +982,6 @@ void WIN_CheckKeyboardAndMouseHotplug(SDL_VideoDevice *_this, SDL_bool initial_c
}
}

SDL_free(old_keyboards);
SDL_free(new_keyboards);
SDL_free(old_mice);
SDL_free(new_mice);
Expand Down
3 changes: 1 addition & 2 deletions src/video/x11/SDL_x11xinput2.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, SDL_bool initial_check)
XIDeviceInfo *info;
int ndevices;
int old_keyboard_count = 0;
SDL_KeyboardID *old_keyboards = NULL;
const SDL_KeyboardID *old_keyboards = NULL;
int new_keyboard_count = 0;
SDL_KeyboardID *new_keyboards = NULL;
int old_mouse_count = 0;
Expand Down Expand Up @@ -839,7 +839,6 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, SDL_bool initial_check)
}
}

SDL_free(old_keyboards);
SDL_free(new_keyboards);
SDL_free(old_mice);
SDL_free(new_mice);
Expand Down
2 changes: 1 addition & 1 deletion test/testhotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int main(int argc, char *argv[])
//SDL_CreateWindow("Dummy", 128, 128, 0);
*/

SDL_free(SDL_GetKeyboards(&num_keyboards));
SDL_GetKeyboards(&num_keyboards);
SDL_Log("There are %d keyboards at startup\n", num_keyboards);

SDL_free(SDL_GetMice(&num_mice));
Expand Down

0 comments on commit c58bad8

Please sign in to comment.