Update for SDL3 coding style (#6717)

I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594
This commit is contained in:
Sam Lantinga 2022-11-30 12:51:59 -08:00 committed by GitHub
parent 14b902faca
commit 5750bcb174
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
781 changed files with 51659 additions and 55763 deletions

View file

@ -32,7 +32,6 @@
#endif
#include <SDL3/SDL_syswm.h>
#define FCITX_DBUS_SERVICE "org.freedesktop.portal.Fcitx"
#define FCITX_IM_DBUS_PATH "/org/freedesktop/portal/inputmethod"
@ -55,8 +54,7 @@ typedef struct _FcitxClient
static FcitxClient fcitx_client;
static char*
GetAppName()
static char *GetAppName()
{
#if defined(__LINUX__) || defined(__FREEBSD__)
char *spot;
@ -86,10 +84,10 @@ GetAppName()
static size_t
Fcitx_GetPreeditString(SDL_DBusContext *dbus,
DBusMessage *msg,
char **ret,
Sint32 *start_pos,
Sint32 *end_pos)
DBusMessage *msg,
char **ret,
Sint32 *start_pos,
Sint32 *end_pos)
{
char *text = NULL, *subtext;
size_t text_bytes = 0;
@ -141,7 +139,7 @@ Fcitx_GetPreeditString(SDL_DBusContext *dbus,
}
if (text) {
char* pivot = text;
char *pivot = text;
/* Second pass: join all the sub string */
dbus->message_iter_recurse(&iter, &array);
while (dbus->message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
@ -167,8 +165,7 @@ Fcitx_GetPreeditString(SDL_DBusContext *dbus,
return text_bytes;
}
static Sint32
Fcitx_GetPreeditCursorByte(SDL_DBusContext *dbus, DBusMessage *msg)
static Sint32 Fcitx_GetPreeditCursorByte(SDL_DBusContext *dbus, DBusMessage *msg)
{
Sint32 byte = -1;
DBusMessageIter iter;
@ -186,8 +183,7 @@ Fcitx_GetPreeditCursorByte(SDL_DBusContext *dbus, DBusMessage *msg)
return byte;
}
static DBusHandlerResult
DBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *data)
static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *data)
{
SDL_DBusContext *dbus = (SDL_DBusContext *)data;
@ -203,7 +199,7 @@ DBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *data)
size_t text_bytes = SDL_strlen(text), i = 0;
while (i < text_bytes) {
size_t sz = SDL_utf8strlcpy(buf, text+i, sizeof(buf));
size_t sz = SDL_utf8strlcpy(buf, text + i, sizeof(buf));
SDL_SendKeyboardText(buf);
i += sz;
@ -250,8 +246,7 @@ DBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *data)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
static void
FcitxClientICCallMethod(FcitxClient *client, const char *method)
static void FcitxClientICCallMethod(FcitxClient *client, const char *method)
{
if (!client->ic_path) {
return;
@ -259,11 +254,10 @@ FcitxClientICCallMethod(FcitxClient *client, const char *method)
SDL_DBus_CallVoidMethod(FCITX_DBUS_SERVICE, client->ic_path, FCITX_IC_DBUS_INTERFACE, method, DBUS_TYPE_INVALID);
}
static void SDLCALL
Fcitx_SetCapabilities(void *data,
const char *name,
const char *old_val,
const char *internal_editing)
static void SDLCALL Fcitx_SetCapabilities(void *data,
const char *name,
const char *old_val,
const char *internal_editing)
{
FcitxClient *client = (FcitxClient *)data;
Uint64 caps = 0;
@ -279,8 +273,8 @@ Fcitx_SetCapabilities(void *data,
SDL_DBus_CallVoidMethod(FCITX_DBUS_SERVICE, client->ic_path, FCITX_IC_DBUS_INTERFACE, "SetCapability", DBUS_TYPE_UINT64, &caps, DBUS_TYPE_INVALID);
}
static SDL_bool
FcitxCreateInputContext(SDL_DBusContext* dbus, const char *appname, char **ic_path) {
static SDL_bool FcitxCreateInputContext(SDL_DBusContext *dbus, const char *appname, char **ic_path)
{
const char *program = "program";
SDL_bool retval = SDL_FALSE;
if (dbus->session_conn) {
@ -308,8 +302,7 @@ FcitxCreateInputContext(SDL_DBusContext* dbus, const char *appname, char **ic_pa
return retval;
}
static SDL_bool
FcitxClientCreateIC(FcitxClient *client)
static SDL_bool FcitxClientCreateIC(FcitxClient *client)
{
char *appname = GetAppName();
char *ic_path = NULL;
@ -317,7 +310,7 @@ FcitxClientCreateIC(FcitxClient *client)
/* SDL_DBus_CallMethod cannot handle a(ss) type, call dbus function directly */
if (!FcitxCreateInputContext(dbus, appname, &ic_path)) {
ic_path = NULL; /* just in case. */
ic_path = NULL; /* just in case. */
}
SDL_free(appname);
@ -327,11 +320,11 @@ FcitxClientCreateIC(FcitxClient *client)
client->ic_path = SDL_strdup(ic_path);
dbus->bus_add_match(dbus->session_conn,
"type='signal', interface='org.fcitx.Fcitx.InputContext1'",
NULL);
"type='signal', interface='org.fcitx.Fcitx.InputContext1'",
NULL);
dbus->connection_add_filter(dbus->session_conn,
&DBus_MessageFilter, dbus,
NULL);
&DBus_MessageFilter, dbus,
NULL);
dbus->connection_flush(dbus->session_conn);
SDL_AddHintCallback(SDL_HINT_IME_INTERNAL_EDITING, Fcitx_SetCapabilities, client);
@ -341,8 +334,7 @@ FcitxClientCreateIC(FcitxClient *client)
return SDL_FALSE;
}
static Uint32
Fcitx_ModState(void)
static Uint32 Fcitx_ModState(void)
{
Uint32 fcitx_mods = 0;
SDL_Keymod sdl_mods = SDL_GetModState();
@ -388,8 +380,7 @@ SDL_Fcitx_Init()
return FcitxClientCreateIC(&fcitx_client);
}
void
SDL_Fcitx_Quit()
void SDL_Fcitx_Quit()
{
FcitxClientICCallMethod(&fcitx_client, "DestroyIC");
if (fcitx_client.ic_path) {
@ -398,8 +389,7 @@ SDL_Fcitx_Quit()
}
}
void
SDL_Fcitx_SetFocus(SDL_bool focused)
void SDL_Fcitx_SetFocus(SDL_bool focused)
{
if (focused) {
FcitxClientICCallMethod(&fcitx_client, "FocusIn");
@ -408,8 +398,7 @@ SDL_Fcitx_SetFocus(SDL_bool focused)
}
}
void
SDL_Fcitx_Reset(void)
void SDL_Fcitx_Reset(void)
{
FcitxClientICCallMethod(&fcitx_client, "Reset");
FcitxClientICCallMethod(&fcitx_client, "CloseIC");
@ -428,8 +417,8 @@ SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
}
if (SDL_DBus_CallMethod(FCITX_DBUS_SERVICE, fcitx_client.ic_path, FCITX_IC_DBUS_INTERFACE, "ProcessKeyEvent",
DBUS_TYPE_UINT32, &keysym, DBUS_TYPE_UINT32, &keycode, DBUS_TYPE_UINT32, &mod_state, DBUS_TYPE_BOOLEAN, &is_release, DBUS_TYPE_UINT32, &event_time, DBUS_TYPE_INVALID,
DBUS_TYPE_BOOLEAN, &handled, DBUS_TYPE_INVALID)) {
DBUS_TYPE_UINT32, &keysym, DBUS_TYPE_UINT32, &keycode, DBUS_TYPE_UINT32, &mod_state, DBUS_TYPE_BOOLEAN, &is_release, DBUS_TYPE_UINT32, &event_time, DBUS_TYPE_INVALID,
DBUS_TYPE_BOOLEAN, &handled, DBUS_TYPE_INVALID)) {
if (handled) {
SDL_Fcitx_UpdateTextRect(NULL);
return SDL_TRUE;
@ -439,8 +428,7 @@ SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
return SDL_FALSE;
}
void
SDL_Fcitx_UpdateTextRect(const SDL_Rect *rect)
void SDL_Fcitx_UpdateTextRect(const SDL_Rect *rect)
{
SDL_Window *focused_win = NULL;
SDL_SysWMinfo info;
@ -453,7 +441,7 @@ SDL_Fcitx_UpdateTextRect(const SDL_Rect *rect)
focused_win = SDL_GetKeyboardFocus();
if (focused_win == NULL) {
return ;
return;
}
SDL_GetWindowPosition(focused_win, &x, &y);
@ -482,11 +470,10 @@ SDL_Fcitx_UpdateTextRect(const SDL_Rect *rect)
y += cursor->y;
SDL_DBus_CallVoidMethod(FCITX_DBUS_SERVICE, fcitx_client.ic_path, FCITX_IC_DBUS_INTERFACE, "SetCursorRect",
DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y, DBUS_TYPE_INT32, &cursor->w, DBUS_TYPE_INT32, &cursor->h, DBUS_TYPE_INVALID);
DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y, DBUS_TYPE_INT32, &cursor->w, DBUS_TYPE_INT32, &cursor->h, DBUS_TYPE_INVALID);
}
void
SDL_Fcitx_PumpEvents(void)
void SDL_Fcitx_PumpEvents(void)
{
SDL_DBusContext *dbus = fcitx_client.dbus;
DBusConnection *conn = dbus->session_conn;