Skip to content

Commit 623cb7c

Browse files
authored
Merge branch 'libsdl-org:main' into br_location
2 parents 9caffbe + 4339113 commit 623cb7c

File tree

14 files changed

+378
-149
lines changed

14 files changed

+378
-149
lines changed

android-project/app/build.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ android {
2020
externalNativeBuild {
2121
ndkBuild {
2222
arguments "APP_PLATFORM=android-16"
23-
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
23+
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
24+
abiFilters 'arm64-v8a'
25+
}
26+
cmake {
27+
arguments "-DANDROID_APP_PLATFORM=android-16", "-DANDROID_STL=c++_static"
28+
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
29+
abiFilters 'arm64-v8a'
2430
}
25-
// cmake {
26-
// arguments "-DANDROID_APP_PLATFORM=android-16", "-DANDROID_STL=c++_static"
27-
// // abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
28-
// abiFilters 'arm64-v8a'
29-
// }
3031
}
3132
}
3233
buildTypes {

build-scripts/androidbuildlibs.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,27 @@ cd $srcdir
2525

2626
build=build
2727
buildandroid=$build/android
28+
platform=android-16
29+
abi="arm64-v8a" # "armeabi-v7a arm64-v8a x86 x86_64"
2830
obj=
2931
lib=
3032
ndk_args=
3133

32-
# Allow an external caller to specify locations.
33-
for arg in $*; do
34+
# Allow an external caller to specify locations and platform.
35+
while [ $# -gt 0 ]; do
36+
arg=$1
3437
if [ "${arg:0:8}" == "NDK_OUT=" ]; then
3538
obj=${arg#NDK_OUT=}
3639
elif [ "${arg:0:13}" == "NDK_LIBS_OUT=" ]; then
3740
lib=${arg#NDK_LIBS_OUT=}
41+
elif [ "${arg:0:13}" == "APP_PLATFORM=" ]; then
42+
platform=${arg#APP_PLATFORM=}
43+
elif [ "${arg:0:8}" == "APP_ABI=" ]; then
44+
abi=${arg#APP_ABI=}
3845
else
3946
ndk_args="$ndk_args $arg"
4047
fi
48+
shift
4149
done
4250

4351
if [ -z $obj ]; then
@@ -64,7 +72,7 @@ ndk-build \
6472
NDK_OUT=$obj \
6573
NDK_LIBS_OUT=$lib \
6674
APP_BUILD_SCRIPT=Android.mk \
67-
APP_ABI="armeabi-v7a arm64-v8a x86 x86_64" \
68-
APP_PLATFORM=android-16 \
75+
APP_ABI="$abi" \
76+
APP_PLATFORM="$platform" \
6977
APP_MODULES="SDL3" \
7078
$ndk_args

include/SDL3/SDL_events.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ typedef enum
151151
SDL_EVENT_JOYSTICK_ADDED, /**< A new joystick has been inserted into the system */
152152
SDL_EVENT_JOYSTICK_REMOVED, /**< An opened joystick has been removed */
153153
SDL_EVENT_JOYSTICK_BATTERY_UPDATED, /**< Joystick battery level change */
154+
SDL_EVENT_JOYSTICK_UPDATE_COMPLETE, /**< Joystick update is complete (disabled by default) */
154155

155156
/* Gamepad events */
156157
SDL_EVENT_GAMEPAD_AXIS_MOTION = 0x650, /**< Gamepad axis motion */
@@ -163,6 +164,7 @@ typedef enum
163164
SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION, /**< Gamepad touchpad finger was moved */
164165
SDL_EVENT_GAMEPAD_TOUCHPAD_UP, /**< Gamepad touchpad finger was lifted */
165166
SDL_EVENT_GAMEPAD_SENSOR_UPDATE, /**< Gamepad sensor was updated */
167+
SDL_EVENT_GAMEPAD_UPDATE_COMPLETE, /**< Gamepad update is complete (disabled by default) */
166168

167169
/* Touch events */
168170
SDL_EVENT_FINGER_DOWN = 0x700,
@@ -401,7 +403,7 @@ typedef struct SDL_JoyButtonEvent
401403
*/
402404
typedef struct SDL_JoyDeviceEvent
403405
{
404-
Uint32 type; /**< ::SDL_EVENT_JOYSTICK_ADDED or ::SDL_EVENT_JOYSTICK_REMOVED */
406+
Uint32 type; /**< ::SDL_EVENT_JOYSTICK_ADDED or ::SDL_EVENT_JOYSTICK_REMOVED or ::SDL_EVENT_JOYSTICK_UPDATE_COMPLETE */
405407
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
406408
SDL_JoystickID which; /**< The joystick instance id */
407409
} SDL_JoyDeviceEvent;
@@ -454,7 +456,7 @@ typedef struct SDL_GamepadButtonEvent
454456
*/
455457
typedef struct SDL_GamepadDeviceEvent
456458
{
457-
Uint32 type; /**< ::SDL_EVENT_GAMEPAD_ADDED, ::SDL_EVENT_GAMEPAD_REMOVED, or ::SDL_EVENT_GAMEPAD_REMAPPED */
459+
Uint32 type; /**< ::SDL_EVENT_GAMEPAD_ADDED, ::SDL_EVENT_GAMEPAD_REMOVED, or ::SDL_EVENT_GAMEPAD_REMAPPED or ::SDL_EVENT_GAMEPAD_UPDATE_COMPLETE */
458460
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
459461
SDL_JoystickID which; /**< The joystick instance id */
460462
} SDL_GamepadDeviceEvent;

src/core/linux/SDL_dbus.c

Lines changed: 76 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ static SDL_DBusContext dbus;
3333

3434
static int LoadDBUSSyms(void)
3535
{
36+
#define SDL_DBUS_SYM2_OPTIONAL(TYPE, x, y) \
37+
dbus.x = (TYPE)SDL_LoadFunction(dbus_handle, #y)
38+
3639
#define SDL_DBUS_SYM2(TYPE, x, y) \
3740
if (!(dbus.x = (TYPE)SDL_LoadFunction(dbus_handle, #y))) \
3841
return -1
3942

43+
#define SDL_DBUS_SYM_OPTIONAL(TYPE, x) \
44+
SDL_DBUS_SYM2_OPTIONAL(TYPE, x, dbus_##x)
45+
4046
#define SDL_DBUS_SYM(TYPE, x) \
4147
SDL_DBUS_SYM2(TYPE, x, dbus_##x)
4248

@@ -77,6 +83,7 @@ static int LoadDBUSSyms(void)
7783
SDL_DBUS_SYM(dbus_bool_t (*)(const DBusError *), error_is_set);
7884
SDL_DBUS_SYM(void (*)(DBusError *), error_free);
7985
SDL_DBUS_SYM(char *(*)(void), get_local_machine_id);
86+
SDL_DBUS_SYM_OPTIONAL(char *(*)(DBusError *), try_get_local_machine_id);
8087
SDL_DBUS_SYM(void (*)(void *), free);
8188
SDL_DBUS_SYM(void (*)(char **), free_string_array);
8289
SDL_DBUS_SYM(void (*)(void), shutdown);
@@ -360,31 +367,41 @@ void SDL_DBus_ScreensaverTickle(void)
360367
}
361368
}
362369

363-
static SDL_bool SDL_DBus_AppendDictWithKeyValue(DBusMessageIter *iterInit, const char *key, const char *value)
370+
static SDL_bool SDL_DBus_AppendDictWithKeysValues(DBusMessageIter *iterInit, const char **keys, const char **values, int count)
364371
{
365-
DBusMessageIter iterDict, iterEntry, iterValue;
372+
DBusMessageIter iterDict;
366373

367374
if (!dbus.message_iter_open_container(iterInit, DBUS_TYPE_ARRAY, "{sv}", &iterDict)) {
368375
goto failed;
369376
}
370377

371-
if (!dbus.message_iter_open_container(&iterDict, DBUS_TYPE_DICT_ENTRY, NULL, &iterEntry)) {
372-
goto failed;
373-
}
378+
for (int i = 0; i < count; i++) {
379+
DBusMessageIter iterEntry, iterValue;
380+
const char *key = keys[i];
381+
const char *value = values[i];
374382

375-
if (!dbus.message_iter_append_basic(&iterEntry, DBUS_TYPE_STRING, &key)) {
376-
goto failed;
377-
}
383+
if (!dbus.message_iter_open_container(&iterDict, DBUS_TYPE_DICT_ENTRY, NULL, &iterEntry)) {
384+
goto failed;
385+
}
378386

379-
if (!dbus.message_iter_open_container(&iterEntry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &iterValue)) {
380-
goto failed;
381-
}
387+
if (!dbus.message_iter_append_basic(&iterEntry, DBUS_TYPE_STRING, &key)) {
388+
goto failed;
389+
}
382390

383-
if (!dbus.message_iter_append_basic(&iterValue, DBUS_TYPE_STRING, &value)) {
384-
goto failed;
391+
if (!dbus.message_iter_open_container(&iterEntry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &iterValue)) {
392+
goto failed;
393+
}
394+
395+
if (!dbus.message_iter_append_basic(&iterValue, DBUS_TYPE_STRING, &value)) {
396+
goto failed;
397+
}
398+
399+
if (!dbus.message_iter_close_container(&iterEntry, &iterValue) || !dbus.message_iter_close_container(&iterDict, &iterEntry)) {
400+
goto failed;
401+
}
385402
}
386403

387-
if (!dbus.message_iter_close_container(&iterEntry, &iterValue) || !dbus.message_iter_close_container(&iterDict, &iterEntry) || !dbus.message_iter_close_container(iterInit, &iterDict)) {
404+
if (!dbus.message_iter_close_container(iterInit, &iterDict)) {
388405
goto failed;
389406
}
390407

@@ -440,9 +457,17 @@ SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
440457
}
441458

442459
dbus.message_iter_init_append(msg, &iterInit);
443-
if (!SDL_DBus_AppendDictWithKeyValue(&iterInit, key, reason)) {
444-
dbus.message_unref(msg);
445-
return SDL_FALSE;
460+
461+
/* a{sv} */
462+
{
463+
const char *keys[1];
464+
const char *values[1];
465+
keys[0] = key;
466+
values[0] = reason;
467+
if (!SDL_DBus_AppendDictWithKeysValues(&iterInit, keys, values, 1)) {
468+
dbus.message_unref(msg);
469+
return SDL_FALSE;
470+
}
446471
}
447472

448473
if (SDL_DBus_CallWithBasicReply(dbus.session_conn, msg, DBUS_TYPE_OBJECT_PATH, &reply)) {
@@ -726,4 +751,38 @@ void SDL_DBus_PumpEvents(void)
726751
}
727752
}
728753
}
754+
755+
/*
756+
* Get the machine ID if possible. Result must be freed with dbus->free().
757+
*/
758+
char *SDL_DBus_GetLocalMachineId(void)
759+
{
760+
DBusError err;
761+
char *result;
762+
763+
dbus.error_init(&err);
764+
765+
if (dbus.try_get_local_machine_id) {
766+
/* Available since dbus 1.12.0, has proper error-handling */
767+
result = dbus.try_get_local_machine_id(&err);
768+
} else {
769+
/* Available since time immemorial, but has no error-handling:
770+
* if the machine ID can't be read, many versions of libdbus will
771+
* treat that as a fatal mis-installation and abort() */
772+
result = dbus.get_local_machine_id();
773+
}
774+
775+
if (result) {
776+
return result;
777+
}
778+
779+
if (dbus.error_is_set(&err)) {
780+
SDL_SetError("%s: %s", err.name, err.message);
781+
dbus.error_free(&err);
782+
} else {
783+
SDL_SetError("Error getting D-Bus machine ID");
784+
}
785+
786+
return NULL;
787+
}
729788
#endif

src/core/linux/SDL_dbus.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ typedef struct SDL_DBusContext
7575
dbus_bool_t (*error_is_set)(const DBusError *);
7676
void (*error_free)(DBusError *);
7777
char *(*get_local_machine_id)(void);
78+
char *(*try_get_local_machine_id)(DBusError *);
7879
void (*free)(void *);
7980
void (*free_string_array)(char **);
8081
void (*shutdown)(void);
@@ -102,6 +103,7 @@ extern int SDL_DBus_StartLocation(void);
102103
extern void SDL_DBus_StopLocation(void);
103104

104105
extern void SDL_DBus_PumpEvents(void);
106+
extern char *SDL_DBus_GetLocalMachineId(void);
105107

106108
#endif /* HAVE_DBUS_DBUS_H */
107109

src/core/linux/SDL_ibus.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,12 @@ static char *IBus_GetDBusAddressFilename(void)
411411
(void)SDL_snprintf(config_dir, sizeof(config_dir), "%s/.config", home_env);
412412
}
413413

414-
key = dbus->get_local_machine_id();
414+
key = SDL_DBus_GetLocalMachineId();
415+
416+
if (key == NULL) {
417+
SDL_free(display);
418+
return NULL;
419+
}
415420

416421
SDL_memset(file_path, 0, sizeof(file_path));
417422
(void)SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s",

src/events/SDL_events.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ int SDL_StartEventLoop(void)
584584
SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, SDL_FALSE);
585585
SDL_SetEventEnabled(SDL_EVENT_DROP_TEXT, SDL_FALSE);
586586
#endif
587+
SDL_SetEventEnabled(SDL_EVENT_JOYSTICK_UPDATE_COMPLETE, SDL_FALSE);
588+
SDL_SetEventEnabled(SDL_EVENT_GAMEPAD_UPDATE_COMPLETE, SDL_FALSE);
587589

588590
SDL_EventQ.active = SDL_TRUE;
589591
SDL_UnlockMutex(SDL_EventQ.lock);
@@ -1269,6 +1271,29 @@ void SDL_SetEventEnabled(Uint32 type, SDL_bool enabled)
12691271
if (enabled != current_state) {
12701272
if (enabled) {
12711273
SDL_disabled_events[hi]->bits[lo / 32] &= ~(1 << (lo & 31));
1274+
1275+
/* Gamepad events depend on joystick events */
1276+
switch (type) {
1277+
case SDL_EVENT_GAMEPAD_ADDED:
1278+
SDL_SetEventEnabled(SDL_EVENT_JOYSTICK_ADDED, SDL_TRUE);
1279+
break;
1280+
case SDL_EVENT_GAMEPAD_REMOVED:
1281+
SDL_SetEventEnabled(SDL_EVENT_JOYSTICK_REMOVED, SDL_TRUE);
1282+
break;
1283+
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
1284+
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
1285+
case SDL_EVENT_GAMEPAD_BUTTON_UP:
1286+
SDL_SetEventEnabled(SDL_EVENT_JOYSTICK_AXIS_MOTION, SDL_TRUE);
1287+
SDL_SetEventEnabled(SDL_EVENT_JOYSTICK_HAT_MOTION, SDL_TRUE);
1288+
SDL_SetEventEnabled(SDL_EVENT_JOYSTICK_BUTTON_DOWN, SDL_TRUE);
1289+
SDL_SetEventEnabled(SDL_EVENT_JOYSTICK_BUTTON_UP, SDL_TRUE);
1290+
break;
1291+
case SDL_EVENT_GAMEPAD_UPDATE_COMPLETE:
1292+
SDL_SetEventEnabled(SDL_EVENT_JOYSTICK_UPDATE_COMPLETE, SDL_TRUE);
1293+
break;
1294+
default:
1295+
break;
1296+
}
12721297
} else {
12731298
/* Disable this event type and discard pending events */
12741299
if (!SDL_disabled_events[hi]) {

src/joystick/SDL_gamepad.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,22 @@ static int SDLCALL SDL_GamepadEventWatcher(void *userdata, SDL_Event *event)
392392
SDL_PushEvent(&deviceevent);
393393
}
394394
} break;
395+
case SDL_EVENT_JOYSTICK_UPDATE_COMPLETE:
396+
{
397+
SDL_AssertJoysticksLocked();
398+
399+
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
400+
if (gamepad->joystick->instance_id == event->jdevice.which) {
401+
SDL_Event deviceevent;
402+
403+
deviceevent.type = SDL_EVENT_GAMEPAD_UPDATE_COMPLETE;
404+
deviceevent.common.timestamp = event->jdevice.timestamp;
405+
deviceevent.gdevice.which = event->jdevice.which;
406+
SDL_PushEvent(&deviceevent);
407+
break;
408+
}
409+
}
410+
} break;
395411
default:
396412
break;
397413
}
@@ -3195,6 +3211,11 @@ void SDL_GamepadHandleDelayedGuideButton(SDL_Joystick *joystick)
31953211
for (gamepad = SDL_gamepads; gamepad; gamepad = gamepad->next) {
31963212
if (gamepad->joystick == joystick) {
31973213
SDL_SendGamepadButton(0, gamepad, SDL_GAMEPAD_BUTTON_GUIDE, SDL_RELEASED);
3214+
3215+
/* Make sure we send an update complete event for this change */
3216+
if (!gamepad->joystick->update_complete) {
3217+
gamepad->joystick->update_complete = SDL_GetTicksNS();
3218+
}
31983219
break;
31993220
}
32003221
}

0 commit comments

Comments
 (0)