mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-04 21:14:43 +00:00
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
(cherry picked from commit 5750bcb174)
This commit is contained in:
@@ -34,14 +34,14 @@ static char *inhibit_handle = NULL;
|
||||
static unsigned int screensaver_cookie = 0;
|
||||
static SDL_DBusContext dbus;
|
||||
|
||||
static int
|
||||
LoadDBUSSyms(void)
|
||||
static int LoadDBUSSyms(void)
|
||||
{
|
||||
#define SDL_DBUS_SYM2(x, y) \
|
||||
if (!(dbus.x = SDL_LoadFunction(dbus_handle, #y))) return -1
|
||||
|
||||
#define SDL_DBUS_SYM(x) \
|
||||
SDL_DBUS_SYM2(x, dbus_##x)
|
||||
#define SDL_DBUS_SYM2(x, y) \
|
||||
if (!(dbus.x = SDL_LoadFunction(dbus_handle, #y))) \
|
||||
return -1
|
||||
|
||||
#define SDL_DBUS_SYM(x) \
|
||||
SDL_DBUS_SYM2(x, dbus_##x)
|
||||
|
||||
SDL_DBUS_SYM(bus_get_private);
|
||||
SDL_DBUS_SYM(bus_register);
|
||||
@@ -83,14 +83,13 @@ LoadDBUSSyms(void)
|
||||
SDL_DBUS_SYM(free_string_array);
|
||||
SDL_DBUS_SYM(shutdown);
|
||||
|
||||
#undef SDL_DBUS_SYM
|
||||
#undef SDL_DBUS_SYM2
|
||||
#undef SDL_DBUS_SYM
|
||||
#undef SDL_DBUS_SYM2
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
UnloadDBUSLibrary(void)
|
||||
static void UnloadDBUSLibrary(void)
|
||||
{
|
||||
if (dbus_handle != NULL) {
|
||||
SDL_UnloadObject(dbus_handle);
|
||||
@@ -98,8 +97,7 @@ UnloadDBUSLibrary(void)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
LoadDBUSLibrary(void)
|
||||
static int LoadDBUSLibrary(void)
|
||||
{
|
||||
int retval = 0;
|
||||
if (dbus_handle == NULL) {
|
||||
@@ -118,24 +116,22 @@ LoadDBUSLibrary(void)
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
static SDL_SpinLock spinlock_dbus_init = 0;
|
||||
|
||||
/* you must hold spinlock_dbus_init before calling this! */
|
||||
static void
|
||||
SDL_DBus_Init_Spinlocked(void)
|
||||
static void SDL_DBus_Init_Spinlocked(void)
|
||||
{
|
||||
static SDL_bool is_dbus_available = SDL_TRUE;
|
||||
if (!is_dbus_available) {
|
||||
return; /* don't keep trying if this fails. */
|
||||
return; /* don't keep trying if this fails. */
|
||||
}
|
||||
|
||||
if (!dbus.session_conn) {
|
||||
DBusError err;
|
||||
|
||||
if (LoadDBUSLibrary() == -1) {
|
||||
is_dbus_available = SDL_FALSE; /* can't load at all? Don't keep trying. */
|
||||
return; /* oh well */
|
||||
is_dbus_available = SDL_FALSE; /* can't load at all? Don't keep trying. */
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dbus.threads_init_default()) {
|
||||
@@ -151,7 +147,7 @@ SDL_DBus_Init_Spinlocked(void)
|
||||
dbus.error_free(&err);
|
||||
SDL_DBus_Quit();
|
||||
is_dbus_available = SDL_FALSE;
|
||||
return; /* oh well */
|
||||
return; /* oh well */
|
||||
}
|
||||
dbus.connection_set_exit_on_disconnect(dbus.session_conn, 0);
|
||||
|
||||
@@ -165,16 +161,14 @@ SDL_DBus_Init_Spinlocked(void)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DBus_Init(void)
|
||||
void SDL_DBus_Init(void)
|
||||
{
|
||||
SDL_AtomicLock(&spinlock_dbus_init); /* make sure two threads can't init at same time, since this can happen before SDL_Init. */
|
||||
SDL_AtomicLock(&spinlock_dbus_init); /* make sure two threads can't init at same time, since this can happen before SDL_Init. */
|
||||
SDL_DBus_Init_Spinlocked();
|
||||
SDL_AtomicUnlock(&spinlock_dbus_init);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DBus_Quit(void)
|
||||
void SDL_DBus_Quit(void)
|
||||
{
|
||||
if (dbus.system_conn) {
|
||||
dbus.connection_close(dbus.system_conn);
|
||||
@@ -204,12 +198,11 @@ SDL_DBus_GetContext(void)
|
||||
if (dbus_handle == NULL || !dbus.session_conn) {
|
||||
SDL_DBus_Init();
|
||||
}
|
||||
|
||||
|
||||
return (dbus_handle && dbus.session_conn) ? &dbus : NULL;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, va_list ap)
|
||||
static SDL_bool SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, va_list ap)
|
||||
{
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
|
||||
@@ -218,7 +211,7 @@ SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node, const char *
|
||||
if (msg) {
|
||||
int firstarg;
|
||||
va_list ap_reply;
|
||||
va_copy(ap_reply, ap); /* copy the arg list so we don't compete with D-Bus for it */
|
||||
va_copy(ap_reply, ap); /* copy the arg list so we don't compete with D-Bus for it */
|
||||
firstarg = va_arg(ap, int);
|
||||
if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_append_args_valist(msg, firstarg, ap)) {
|
||||
DBusMessage *reply = dbus.connection_send_with_reply_and_block(conn, msg, 300, NULL);
|
||||
@@ -226,9 +219,15 @@ SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node, const char *
|
||||
/* skip any input args, get to output args. */
|
||||
while ((firstarg = va_arg(ap_reply, int)) != DBUS_TYPE_INVALID) {
|
||||
/* we assume D-Bus already validated all this. */
|
||||
{ void *dumpptr = va_arg(ap_reply, void*); (void) dumpptr; }
|
||||
{
|
||||
void *dumpptr = va_arg(ap_reply, void *);
|
||||
(void)dumpptr;
|
||||
}
|
||||
if (firstarg == DBUS_TYPE_ARRAY) {
|
||||
{ const int dumpint = va_arg(ap_reply, int); (void) dumpint; }
|
||||
{
|
||||
const int dumpint = va_arg(ap_reply, int);
|
||||
(void)dumpint;
|
||||
}
|
||||
}
|
||||
}
|
||||
firstarg = va_arg(ap_reply, int);
|
||||
@@ -268,8 +267,7 @@ SDL_DBus_CallMethod(const char *node, const char *path, const char *interface, c
|
||||
return retval;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
SDL_DBus_CallVoidMethodInternal(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, va_list ap)
|
||||
static SDL_bool SDL_DBus_CallVoidMethodInternal(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, va_list ap)
|
||||
{
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
|
||||
@@ -291,8 +289,7 @@ SDL_DBus_CallVoidMethodInternal(DBusConnection *conn, const char *node, const ch
|
||||
return retval;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
SDL_DBus_CallWithBasicReply(DBusConnection *conn, DBusMessage *msg, const int expectedtype, void *result)
|
||||
static SDL_bool SDL_DBus_CallWithBasicReply(DBusConnection *conn, DBusMessage *msg, const int expectedtype, void *result)
|
||||
{
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
|
||||
@@ -363,19 +360,16 @@ SDL_DBus_QueryProperty(const char *node, const char *path, const char *interface
|
||||
return SDL_DBus_QueryPropertyOnConnection(dbus.session_conn, node, path, interface, property, expectedtype, result);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SDL_DBus_ScreensaverTickle(void)
|
||||
void SDL_DBus_ScreensaverTickle(void)
|
||||
{
|
||||
if (screensaver_cookie == 0 && inhibit_handle == NULL) { /* no need to tickle if we're inhibiting. */
|
||||
if (screensaver_cookie == 0 && inhibit_handle == NULL) { /* no need to tickle if we're inhibiting. */
|
||||
/* org.gnome.ScreenSaver is the legacy interface, but it'll either do nothing or just be a second harmless tickle on newer systems, so we leave it for now. */
|
||||
SDL_DBus_CallVoidMethod("org.gnome.ScreenSaver", "/org/gnome/ScreenSaver", "org.gnome.ScreenSaver", "SimulateUserActivity", DBUS_TYPE_INVALID);
|
||||
SDL_DBus_CallVoidMethod("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver", "org.freedesktop.ScreenSaver", "SimulateUserActivity", DBUS_TYPE_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
SDL_DBus_AppendDictWithKeyValue(DBusMessageIter *iterInit, const char *key, const char *value)
|
||||
static SDL_bool SDL_DBus_AppendDictWithKeyValue(DBusMessageIter *iterInit, const char *key, const char *value)
|
||||
{
|
||||
DBusMessageIter iterDict, iterEntry, iterValue;
|
||||
|
||||
@@ -399,9 +393,7 @@ SDL_DBus_AppendDictWithKeyValue(DBusMessageIter *iterInit, const char *key, cons
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (!dbus.message_iter_close_container(&iterEntry, &iterValue)
|
||||
|| !dbus.message_iter_close_container(&iterDict, &iterEntry)
|
||||
|| !dbus.message_iter_close_container(iterInit, &iterDict)) {
|
||||
if (!dbus.message_iter_close_container(&iterEntry, &iterValue) || !dbus.message_iter_close_container(&iterDict, &iterEntry) || !dbus.message_iter_close_container(iterInit, &iterDict)) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
@@ -419,8 +411,7 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
|
||||
{
|
||||
const char *default_inhibit_reason = "Playing a game";
|
||||
|
||||
if ( (inhibit && (screensaver_cookie != 0 || inhibit_handle != NULL))
|
||||
|| (!inhibit && (screensaver_cookie == 0 && inhibit_handle == NULL)) ) {
|
||||
if ((inhibit && (screensaver_cookie != 0 || inhibit_handle != NULL)) || (!inhibit && (screensaver_cookie == 0 && inhibit_handle == NULL))) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -434,7 +425,7 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
|
||||
const char *bus_name = "org.freedesktop.portal.Desktop";
|
||||
const char *path = "/org/freedesktop/portal/desktop";
|
||||
const char *interface = "org.freedesktop.portal.Inhibit";
|
||||
const char *window = ""; /* As a future improvement we could gather the X11 XID or Wayland surface identifier */
|
||||
const char *window = ""; /* As a future improvement we could gather the X11 XID or Wayland surface identifier */
|
||||
static const unsigned int INHIBIT_IDLE = 8; /* Taken from the portal API reference */
|
||||
DBusMessageIter iterInit;
|
||||
|
||||
@@ -487,15 +478,15 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
|
||||
const char *app = SDL_GetHint(SDL_HINT_APP_NAME);
|
||||
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
|
||||
if (app == NULL || !app[0]) {
|
||||
app = "My SDL application";
|
||||
app = "My SDL application";
|
||||
}
|
||||
if (reason == NULL || !reason[0]) {
|
||||
reason = default_inhibit_reason;
|
||||
}
|
||||
|
||||
if (!SDL_DBus_CallMethod(bus_name, path, interface, "Inhibit",
|
||||
DBUS_TYPE_STRING, &app, DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID,
|
||||
DBUS_TYPE_UINT32, &screensaver_cookie, DBUS_TYPE_INVALID)) {
|
||||
DBUS_TYPE_STRING, &app, DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID,
|
||||
DBUS_TYPE_UINT32, &screensaver_cookie, DBUS_TYPE_INVALID)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return (screensaver_cookie != 0) ? SDL_TRUE : SDL_FALSE;
|
||||
|
||||
@@ -29,20 +29,20 @@
|
||||
#include "SDL_stdinc.h"
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
|
||||
typedef struct SDL_DBusContext {
|
||||
typedef struct SDL_DBusContext
|
||||
{
|
||||
DBusConnection *session_conn;
|
||||
DBusConnection *system_conn;
|
||||
|
||||
DBusConnection *(*bus_get_private)(DBusBusType, DBusError *);
|
||||
dbus_bool_t (*bus_register)(DBusConnection *, DBusError *);
|
||||
void (*bus_add_match)(DBusConnection *, const char *, DBusError *);
|
||||
DBusConnection * (*connection_open_private)(const char *, DBusError *);
|
||||
DBusConnection *(*connection_open_private)(const char *, DBusError *);
|
||||
void (*connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t);
|
||||
dbus_bool_t (*connection_get_is_connected)(DBusConnection *);
|
||||
dbus_bool_t (*connection_add_filter)(DBusConnection *, DBusHandleMessageFunction, void *, DBusFreeFunction);
|
||||
dbus_bool_t (*connection_try_register_object_path)(DBusConnection *, const char *,
|
||||
const DBusObjectPathVTable *, void *, DBusError *);
|
||||
const DBusObjectPathVTable *, void *, DBusError *);
|
||||
dbus_bool_t (*connection_send)(DBusConnection *, DBusMessage *, dbus_uint32_t *);
|
||||
DBusMessage *(*connection_send_with_reply_and_block)(DBusConnection *, DBusMessage *, int, DBusError *);
|
||||
void (*connection_close)(DBusConnection *);
|
||||
@@ -50,7 +50,7 @@ typedef struct SDL_DBusContext {
|
||||
void (*connection_flush)(DBusConnection *);
|
||||
dbus_bool_t (*connection_read_write)(DBusConnection *, int);
|
||||
DBusDispatchStatus (*connection_dispatch)(DBusConnection *);
|
||||
dbus_bool_t (*message_is_signal)(DBusMessage *, const char *, const char *);
|
||||
dbus_bool_t (*message_is_signal)(DBusMessage *, const char *, const char *);
|
||||
DBusMessage *(*message_new_method_call)(const char *, const char *, const char *, const char *);
|
||||
dbus_bool_t (*message_append_args)(DBusMessage *, int, ...);
|
||||
dbus_bool_t (*message_append_args_valist)(DBusMessage *, int, va_list);
|
||||
@@ -64,7 +64,7 @@ typedef struct SDL_DBusContext {
|
||||
dbus_bool_t (*message_iter_next)(DBusMessageIter *);
|
||||
void (*message_iter_get_basic)(DBusMessageIter *, void *);
|
||||
int (*message_iter_get_arg_type)(DBusMessageIter *);
|
||||
void (*message_iter_recurse)(DBusMessageIter *, DBusMessageIter *);
|
||||
void (*message_iter_recurse)(DBusMessageIter *, DBusMessageIter *);
|
||||
void (*message_unref)(DBusMessage *);
|
||||
dbus_bool_t (*threads_init_default)(void);
|
||||
void (*error_init)(DBusError *);
|
||||
@@ -79,7 +79,7 @@ typedef struct SDL_DBusContext {
|
||||
|
||||
extern void SDL_DBus_Init(void);
|
||||
extern void SDL_DBus_Quit(void);
|
||||
extern SDL_DBusContext * SDL_DBus_GetContext(void);
|
||||
extern SDL_DBusContext *SDL_DBus_GetContext(void);
|
||||
|
||||
/* These use the built-in Session connection. */
|
||||
extern SDL_bool SDL_DBus_CallMethod(const char *node, const char *path, const char *interface, const char *method, ...);
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#ifdef SDL_INPUT_LINUXEV
|
||||
|
||||
/* This is based on the linux joystick driver */
|
||||
/* References: https://www.kernel.org/doc/Documentation/input/input.txt
|
||||
/* References: https://www.kernel.org/doc/Documentation/input/input.txt
|
||||
* https://www.kernel.org/doc/Documentation/input/event-codes.txt
|
||||
* /usr/include/linux/input.h
|
||||
* The evtest application is also useful to debug the protocol
|
||||
@@ -51,15 +51,15 @@
|
||||
#define SYN_DROPPED 3
|
||||
#endif
|
||||
#ifndef ABS_MT_SLOT
|
||||
#define ABS_MT_SLOT 0x2f
|
||||
#define ABS_MT_POSITION_X 0x35
|
||||
#define ABS_MT_POSITION_Y 0x36
|
||||
#define ABS_MT_TRACKING_ID 0x39
|
||||
#define ABS_MT_PRESSURE 0x3a
|
||||
#define ABS_MT_SLOT 0x2f
|
||||
#define ABS_MT_POSITION_X 0x35
|
||||
#define ABS_MT_POSITION_Y 0x36
|
||||
#define ABS_MT_TRACKING_ID 0x39
|
||||
#define ABS_MT_PRESSURE 0x3a
|
||||
#endif
|
||||
#ifndef REL_WHEEL_HI_RES
|
||||
#define REL_WHEEL_HI_RES 0x0b
|
||||
#define REL_HWHEEL_HI_RES 0x0c
|
||||
#define REL_WHEEL_HI_RES 0x0b
|
||||
#define REL_HWHEEL_HI_RES 0x0c
|
||||
#endif
|
||||
|
||||
typedef struct SDL_evdevlist_item
|
||||
@@ -74,8 +74,9 @@ typedef struct SDL_evdevlist_item
|
||||
keyboard, touchpad, etc.). Also there's probably some things in here we
|
||||
can pull out to the SDL_evdevlist_item i.e. name */
|
||||
SDL_bool is_touchscreen;
|
||||
struct {
|
||||
char* name;
|
||||
struct
|
||||
{
|
||||
char *name;
|
||||
|
||||
int min_x, max_x, range_x;
|
||||
int min_y, max_y, range_y;
|
||||
@@ -83,8 +84,10 @@ typedef struct SDL_evdevlist_item
|
||||
|
||||
int max_slots;
|
||||
int current_slot;
|
||||
struct {
|
||||
enum {
|
||||
struct
|
||||
{
|
||||
enum
|
||||
{
|
||||
EVDEV_TOUCH_SLOTDELTA_NONE = 0,
|
||||
EVDEV_TOUCH_SLOTDELTA_DOWN,
|
||||
EVDEV_TOUCH_SLOTDELTA_UP,
|
||||
@@ -126,33 +129,30 @@ static int SDL_EVDEV_device_removed(const char *dev_path);
|
||||
static int SDL_EVDEV_device_added(const char *dev_path, int udev_class);
|
||||
#if SDL_USE_LIBUDEV
|
||||
static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class,
|
||||
const char *dev_path);
|
||||
const char *dev_path);
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
|
||||
static Uint8 EVDEV_MouseButtons[] = {
|
||||
SDL_BUTTON_LEFT, /* BTN_LEFT 0x110 */
|
||||
SDL_BUTTON_RIGHT, /* BTN_RIGHT 0x111 */
|
||||
SDL_BUTTON_MIDDLE, /* BTN_MIDDLE 0x112 */
|
||||
SDL_BUTTON_X1, /* BTN_SIDE 0x113 */
|
||||
SDL_BUTTON_X2, /* BTN_EXTRA 0x114 */
|
||||
SDL_BUTTON_X2 + 1, /* BTN_FORWARD 0x115 */
|
||||
SDL_BUTTON_X2 + 2, /* BTN_BACK 0x116 */
|
||||
SDL_BUTTON_X2 + 3 /* BTN_TASK 0x117 */
|
||||
SDL_BUTTON_LEFT, /* BTN_LEFT 0x110 */
|
||||
SDL_BUTTON_RIGHT, /* BTN_RIGHT 0x111 */
|
||||
SDL_BUTTON_MIDDLE, /* BTN_MIDDLE 0x112 */
|
||||
SDL_BUTTON_X1, /* BTN_SIDE 0x113 */
|
||||
SDL_BUTTON_X2, /* BTN_EXTRA 0x114 */
|
||||
SDL_BUTTON_X2 + 1, /* BTN_FORWARD 0x115 */
|
||||
SDL_BUTTON_X2 + 2, /* BTN_BACK 0x116 */
|
||||
SDL_BUTTON_X2 + 3 /* BTN_TASK 0x117 */
|
||||
};
|
||||
|
||||
static int
|
||||
SDL_EVDEV_SetRelativeMouseMode(SDL_bool enabled)
|
||||
static int SDL_EVDEV_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
/* Mice already send relative events through this interface */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_EVDEV_Init(void)
|
||||
int SDL_EVDEV_Init(void)
|
||||
{
|
||||
if (_this == NULL) {
|
||||
_this = (SDL_EVDEV_PrivateData*)SDL_calloc(1, sizeof(*_this));
|
||||
_this = (SDL_EVDEV_PrivateData *)SDL_calloc(1, sizeof(*_this));
|
||||
if (_this == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -182,14 +182,14 @@ SDL_EVDEV_Init(void)
|
||||
where device class is an integer representing the
|
||||
SDL_UDEV_deviceclass and path is the full path to
|
||||
the event device. */
|
||||
const char* devices = SDL_getenv("SDL_EVDEV_DEVICES");
|
||||
const char *devices = SDL_getenv("SDL_EVDEV_DEVICES");
|
||||
if (devices) {
|
||||
/* Assume this is the old use of the env var and it is not in
|
||||
ROM. */
|
||||
char* rest = (char*) devices;
|
||||
char* spec;
|
||||
char *rest = (char *)devices;
|
||||
char *spec;
|
||||
while ((spec = SDL_strtokr(rest, ",", &rest))) {
|
||||
char* endofcls = 0;
|
||||
char *endofcls = 0;
|
||||
long cls = SDL_strtol(spec, &endofcls, 0);
|
||||
if (endofcls) {
|
||||
SDL_EVDEV_device_added(endofcls + 1, cls);
|
||||
@@ -211,8 +211,7 @@ SDL_EVDEV_Init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_EVDEV_Quit(void)
|
||||
void SDL_EVDEV_Quit(void)
|
||||
{
|
||||
if (_this == NULL) {
|
||||
return;
|
||||
@@ -244,13 +243,13 @@ SDL_EVDEV_Quit(void)
|
||||
|
||||
#if SDL_USE_LIBUDEV
|
||||
static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_class,
|
||||
const char* dev_path)
|
||||
const char *dev_path)
|
||||
{
|
||||
if (dev_path == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch(udev_event) {
|
||||
switch (udev_event) {
|
||||
case SDL_UDEV_DEVICEADDED:
|
||||
if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD | SDL_UDEV_DEVICE_TOUCHSCREEN | SDL_UDEV_DEVICE_TOUCHPAD))) {
|
||||
return;
|
||||
@@ -261,7 +260,7 @@ static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_cl
|
||||
}
|
||||
|
||||
SDL_EVDEV_device_added(dev_path, udev_class);
|
||||
break;
|
||||
break;
|
||||
case SDL_UDEV_DEVICEREMOVED:
|
||||
SDL_EVDEV_device_removed(dev_path);
|
||||
break;
|
||||
@@ -271,8 +270,7 @@ static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_cl
|
||||
}
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
|
||||
void
|
||||
SDL_EVDEV_Poll(void)
|
||||
void SDL_EVDEV_Poll(void)
|
||||
{
|
||||
struct input_event events[32];
|
||||
int i, j, len;
|
||||
@@ -341,11 +339,11 @@ SDL_EVDEV_Poll(void)
|
||||
SDL_EVDEV_kbd_keycode(_this->kbd, events[i].code, events[i].value);
|
||||
break;
|
||||
case EV_ABS:
|
||||
switch(events[i].code) {
|
||||
switch (events[i].code) {
|
||||
case ABS_MT_SLOT:
|
||||
if (!item->is_touchscreen) { /* FIXME: temp hack */
|
||||
break;
|
||||
}
|
||||
}
|
||||
item->touchscreen_data->current_slot = events[i].value;
|
||||
break;
|
||||
case ABS_MT_TRACKING_ID:
|
||||
@@ -413,7 +411,7 @@ SDL_EVDEV_Poll(void)
|
||||
}
|
||||
break;
|
||||
case EV_REL:
|
||||
switch(events[i].code) {
|
||||
switch (events[i].code) {
|
||||
case REL_X:
|
||||
if (item->relative_mouse) {
|
||||
item->mouse_x += events[i].value;
|
||||
@@ -468,13 +466,13 @@ SDL_EVDEV_Poll(void)
|
||||
|
||||
for (j = 0; j < item->touchscreen_data->max_slots; j++) {
|
||||
norm_x = (float)(item->touchscreen_data->slots[j].x - item->touchscreen_data->min_x) /
|
||||
(float)item->touchscreen_data->range_x;
|
||||
(float)item->touchscreen_data->range_x;
|
||||
norm_y = (float)(item->touchscreen_data->slots[j].y - item->touchscreen_data->min_y) /
|
||||
(float)item->touchscreen_data->range_y;
|
||||
(float)item->touchscreen_data->range_y;
|
||||
|
||||
if (item->touchscreen_data->range_pressure > 0) {
|
||||
norm_pressure = (float)(item->touchscreen_data->slots[j].pressure - item->touchscreen_data->min_pressure) /
|
||||
(float)item->touchscreen_data->range_pressure;
|
||||
(float)item->touchscreen_data->range_pressure;
|
||||
} else {
|
||||
/* This touchscreen does not support pressure */
|
||||
norm_pressure = 1.0f;
|
||||
@@ -483,7 +481,7 @@ SDL_EVDEV_Poll(void)
|
||||
/* FIXME: the touch's window shouldn't be null, but
|
||||
* the coordinate space of touch positions needs to
|
||||
* be window-relative in that case. */
|
||||
switch(item->touchscreen_data->slots[j].delta) {
|
||||
switch (item->touchscreen_data->slots[j].delta) {
|
||||
case EVDEV_TOUCH_SLOTDELTA_DOWN:
|
||||
SDL_SendTouch(item->fd, item->touchscreen_data->slots[j].tracking_id, NULL, SDL_TRUE, norm_x, norm_y, norm_pressure);
|
||||
item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
|
||||
@@ -518,12 +516,11 @@ SDL_EVDEV_Poll(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_Scancode
|
||||
SDL_EVDEV_translate_keycode(int keycode)
|
||||
static SDL_Scancode SDL_EVDEV_translate_keycode(int keycode)
|
||||
{
|
||||
SDL_Scancode scancode = SDL_GetScancodeFromTable(SDL_SCANCODE_TABLE_LINUX, keycode);
|
||||
|
||||
@@ -535,8 +532,9 @@ SDL_EVDEV_translate_keycode(int keycode)
|
||||
SDL_Log message about an unknown key. */
|
||||
if (keycode != BTN_TOUCH) {
|
||||
SDL_Log("The key you just pressed is not recognized by SDL. To help "
|
||||
"get this fixed, please report this to the SDL forums/mailing list "
|
||||
"<https://discourse.libsdl.org/> EVDEV KeyCode %d", keycode);
|
||||
"get this fixed, please report this to the SDL forums/mailing list "
|
||||
"<https://discourse.libsdl.org/> EVDEV KeyCode %d",
|
||||
keycode);
|
||||
}
|
||||
}
|
||||
#endif /* DEBUG_SCANCODES */
|
||||
@@ -544,8 +542,7 @@ SDL_EVDEV_translate_keycode(int keycode)
|
||||
return scancode;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
|
||||
static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
|
||||
{
|
||||
int ret, i;
|
||||
unsigned long xreq, yreq;
|
||||
@@ -634,8 +631,8 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
|
||||
}
|
||||
|
||||
ret = SDL_AddTouch(item->fd, /* I guess our fd is unique enough */
|
||||
(udev_class & SDL_UDEV_DEVICE_TOUCHPAD) ? SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE : SDL_TOUCH_DEVICE_DIRECT,
|
||||
item->touchscreen_data->name);
|
||||
(udev_class & SDL_UDEV_DEVICE_TOUCHPAD) ? SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE : SDL_TOUCH_DEVICE_DIRECT,
|
||||
item->touchscreen_data->name);
|
||||
if (ret < 0) {
|
||||
SDL_free(item->touchscreen_data->slots);
|
||||
SDL_free(item->touchscreen_data->name);
|
||||
@@ -646,8 +643,8 @@ SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item, int udev_class)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item* item) {
|
||||
static void SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item *item)
|
||||
{
|
||||
if (!item->is_touchscreen) {
|
||||
return;
|
||||
}
|
||||
@@ -658,8 +655,7 @@ SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item* item) {
|
||||
SDL_free(item->touchscreen_data);
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
|
||||
static void SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
|
||||
{
|
||||
#ifdef EVIOCGMTSLOTS
|
||||
int i, ret;
|
||||
@@ -672,8 +668,8 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
|
||||
*
|
||||
* this is the structure we're trying to emulate
|
||||
*/
|
||||
Uint32* mt_req_code;
|
||||
Sint32* mt_req_values;
|
||||
Uint32 *mt_req_code;
|
||||
Sint32 *mt_req_values;
|
||||
size_t mt_req_size;
|
||||
|
||||
/* TODO: sync devices other than touchscreen */
|
||||
@@ -682,14 +678,14 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
|
||||
}
|
||||
|
||||
mt_req_size = sizeof(*mt_req_code) +
|
||||
sizeof(*mt_req_values) * item->touchscreen_data->max_slots;
|
||||
sizeof(*mt_req_values) * item->touchscreen_data->max_slots;
|
||||
|
||||
mt_req_code = SDL_calloc(1, mt_req_size);
|
||||
if (mt_req_code == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
mt_req_values = (Sint32*)mt_req_code + 1;
|
||||
mt_req_values = (Sint32 *)mt_req_code + 1;
|
||||
|
||||
*mt_req_code = ABS_MT_TRACKING_ID;
|
||||
ret = ioctl(item->fd, EVIOCGMTSLOTS(mt_req_size), mt_req_code);
|
||||
@@ -712,7 +708,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
|
||||
item->touchscreen_data->slots[i].tracking_id = mt_req_values[i];
|
||||
item->touchscreen_data->slots[i].delta = EVDEV_TOUCH_SLOTDELTA_DOWN;
|
||||
} else if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
|
||||
mt_req_values[i] < 0) {
|
||||
mt_req_values[i] < 0) {
|
||||
item->touchscreen_data->slots[i].tracking_id = -1;
|
||||
item->touchscreen_data->slots[i].delta = EVDEV_TOUCH_SLOTDELTA_UP;
|
||||
}
|
||||
@@ -784,8 +780,7 @@ SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
|
||||
#endif /* EVIOCGMTSLOTS */
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_EVDEV_device_added(const char *dev_path, int udev_class)
|
||||
static int SDL_EVDEV_device_added(const char *dev_path, int udev_class)
|
||||
{
|
||||
int ret;
|
||||
SDL_evdevlist_item *item;
|
||||
@@ -794,11 +789,11 @@ SDL_EVDEV_device_added(const char *dev_path, int udev_class)
|
||||
/* Check to make sure it's not already in list. */
|
||||
for (item = _this->first; item != NULL; item = item->next) {
|
||||
if (SDL_strcmp(dev_path, item->path) == 0) {
|
||||
return -1; /* already have this one */
|
||||
return -1; /* already have this one */
|
||||
}
|
||||
}
|
||||
|
||||
item = (SDL_evdevlist_item *) SDL_calloc(1, sizeof (SDL_evdevlist_item));
|
||||
item = (SDL_evdevlist_item *)SDL_calloc(1, sizeof(SDL_evdevlist_item));
|
||||
if (item == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -846,8 +841,7 @@ SDL_EVDEV_device_added(const char *dev_path, int udev_class)
|
||||
return _this->num_devices++;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_EVDEV_device_removed(const char *dev_path)
|
||||
static int SDL_EVDEV_device_removed(const char *dev_path)
|
||||
{
|
||||
SDL_evdevlist_item *item;
|
||||
SDL_evdevlist_item *prev = NULL;
|
||||
@@ -879,7 +873,6 @@ SDL_EVDEV_device_removed(const char *dev_path)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#endif /* SDL_INPUT_LINUXEV */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include "SDL_evdev_capabilities.h"
|
||||
|
||||
|
||||
#if HAVE_LINUX_INPUT_H
|
||||
|
||||
/* missing defines in older Linux kernel headers */
|
||||
@@ -31,10 +30,10 @@
|
||||
#define BTN_TRIGGER_HAPPY 0x2c0
|
||||
#endif
|
||||
#ifndef BTN_DPAD_UP
|
||||
#define BTN_DPAD_UP 0x220
|
||||
#define BTN_DPAD_UP 0x220
|
||||
#endif
|
||||
#ifndef KEY_ALS_TOGGLE
|
||||
#define KEY_ALS_TOGGLE 0x230
|
||||
#define KEY_ALS_TOGGLE 0x230
|
||||
#endif
|
||||
|
||||
extern int
|
||||
@@ -43,7 +42,8 @@ SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
|
||||
unsigned long bitmask_key[NBITS(KEY_MAX)],
|
||||
unsigned long bitmask_rel[NBITS(REL_MAX)])
|
||||
{
|
||||
struct range {
|
||||
struct range
|
||||
{
|
||||
unsigned start;
|
||||
unsigned end;
|
||||
};
|
||||
@@ -114,7 +114,7 @@ SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
|
||||
unsigned i;
|
||||
unsigned long found = 0;
|
||||
|
||||
for (i = 0; i < BTN_MISC/BITS_PER_LONG; ++i) {
|
||||
for (i = 0; i < BTN_MISC / BITS_PER_LONG; ++i) {
|
||||
found |= bitmask_key[i];
|
||||
}
|
||||
/* If there are no keys in the lower block, check the higher blocks */
|
||||
|
||||
@@ -31,21 +31,21 @@
|
||||
/* A device can be any combination of these classes */
|
||||
typedef enum
|
||||
{
|
||||
SDL_UDEV_DEVICE_UNKNOWN = 0x0000,
|
||||
SDL_UDEV_DEVICE_MOUSE = 0x0001,
|
||||
SDL_UDEV_DEVICE_KEYBOARD = 0x0002,
|
||||
SDL_UDEV_DEVICE_JOYSTICK = 0x0004,
|
||||
SDL_UDEV_DEVICE_SOUND = 0x0008,
|
||||
SDL_UDEV_DEVICE_UNKNOWN = 0x0000,
|
||||
SDL_UDEV_DEVICE_MOUSE = 0x0001,
|
||||
SDL_UDEV_DEVICE_KEYBOARD = 0x0002,
|
||||
SDL_UDEV_DEVICE_JOYSTICK = 0x0004,
|
||||
SDL_UDEV_DEVICE_SOUND = 0x0008,
|
||||
SDL_UDEV_DEVICE_TOUCHSCREEN = 0x0010,
|
||||
SDL_UDEV_DEVICE_ACCELEROMETER = 0x0020,
|
||||
SDL_UDEV_DEVICE_TOUCHPAD = 0x0040
|
||||
SDL_UDEV_DEVICE_TOUCHPAD = 0x0040
|
||||
} SDL_UDEV_deviceclass;
|
||||
|
||||
#define BITS_PER_LONG (sizeof(unsigned long) * 8)
|
||||
#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
|
||||
#define EVDEV_OFF(x) ((x)%BITS_PER_LONG)
|
||||
#define EVDEV_LONG(x) ((x)/BITS_PER_LONG)
|
||||
#define test_bit(bit, array) ((array[EVDEV_LONG(bit)] >> EVDEV_OFF(bit)) & 1)
|
||||
#define BITS_PER_LONG (sizeof(unsigned long) * 8)
|
||||
#define NBITS(x) ((((x)-1) / BITS_PER_LONG) + 1)
|
||||
#define EVDEV_OFF(x) ((x) % BITS_PER_LONG)
|
||||
#define EVDEV_LONG(x) ((x) / BITS_PER_LONG)
|
||||
#define test_bit(bit, array) ((array[EVDEV_LONG(bit)] >> EVDEV_OFF(bit)) & 1)
|
||||
|
||||
extern int SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
|
||||
unsigned long bitmask_abs[NBITS(ABS_MAX)],
|
||||
|
||||
@@ -53,33 +53,31 @@
|
||||
* Handler Tables.
|
||||
*/
|
||||
|
||||
#define K_HANDLERS\
|
||||
k_self, k_fn, k_spec, k_pad,\
|
||||
k_dead, k_cons, k_cur, k_shift,\
|
||||
k_meta, k_ascii, k_lock, k_lowercase,\
|
||||
k_slock, k_dead2, k_brl, k_ignore
|
||||
#define K_HANDLERS \
|
||||
k_self, k_fn, k_spec, k_pad, \
|
||||
k_dead, k_cons, k_cur, k_shift, \
|
||||
k_meta, k_ascii, k_lock, k_lowercase, \
|
||||
k_slock, k_dead2, k_brl, k_ignore
|
||||
|
||||
typedef void (k_handler_fn)(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag);
|
||||
typedef void(k_handler_fn)(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag);
|
||||
static k_handler_fn K_HANDLERS;
|
||||
static k_handler_fn *k_handler[16] = { K_HANDLERS };
|
||||
|
||||
typedef void (fn_handler_fn)(SDL_EVDEV_keyboard_state *kbd);
|
||||
typedef void(fn_handler_fn)(SDL_EVDEV_keyboard_state *kbd);
|
||||
static void fn_enter(SDL_EVDEV_keyboard_state *kbd);
|
||||
static void fn_caps_toggle(SDL_EVDEV_keyboard_state *kbd);
|
||||
static void fn_caps_on(SDL_EVDEV_keyboard_state *kbd);
|
||||
static void fn_num(SDL_EVDEV_keyboard_state *kbd);
|
||||
static void fn_compose(SDL_EVDEV_keyboard_state *kbd);
|
||||
|
||||
static fn_handler_fn *fn_handler[] =
|
||||
{
|
||||
NULL, fn_enter, NULL, NULL,
|
||||
NULL, NULL, NULL, fn_caps_toggle,
|
||||
fn_num, NULL, NULL, NULL,
|
||||
NULL, fn_caps_on, fn_compose, NULL,
|
||||
NULL, NULL, NULL, fn_num
|
||||
static fn_handler_fn *fn_handler[] = {
|
||||
NULL, fn_enter, NULL, NULL,
|
||||
NULL, NULL, NULL, fn_caps_toggle,
|
||||
fn_num, NULL, NULL, NULL,
|
||||
NULL, fn_caps_on, fn_compose, NULL,
|
||||
NULL, NULL, NULL, fn_num
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Keyboard State
|
||||
*/
|
||||
@@ -89,12 +87,12 @@ struct SDL_EVDEV_keyboard_state
|
||||
int console_fd;
|
||||
int old_kbd_mode;
|
||||
unsigned short **key_maps;
|
||||
unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */
|
||||
unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */
|
||||
SDL_bool dead_key_next;
|
||||
int npadch; /* -1 or number assembled on pad */
|
||||
int npadch; /* -1 or number assembled on pad */
|
||||
struct kbdiacrs *accents;
|
||||
unsigned int diacr;
|
||||
SDL_bool rep; /* flag telling character repeat */
|
||||
SDL_bool rep; /* flag telling character repeat */
|
||||
unsigned char lockstate;
|
||||
unsigned char slockstate;
|
||||
unsigned char ledflagstate;
|
||||
@@ -114,7 +112,7 @@ static void SDL_EVDEV_dump_accents(SDL_EVDEV_keyboard_state *kbd)
|
||||
for (i = 0; i < kbd->accents->kb_cnt; ++i) {
|
||||
struct kbdiacr *diacr = &kbd->accents->kbdiacr[i];
|
||||
printf(" { 0x%.2x, 0x%.2x, 0x%.2x },\n",
|
||||
diacr->diacr, diacr->base, diacr->result);
|
||||
diacr->diacr, diacr->base, diacr->result);
|
||||
}
|
||||
while (i < 256) {
|
||||
printf(" { 0x00, 0x00, 0x00 },\n");
|
||||
@@ -134,7 +132,7 @@ static void SDL_EVDEV_dump_keymap(SDL_EVDEV_keyboard_state *kbd)
|
||||
if (kbd->key_maps[i]) {
|
||||
printf("static unsigned short default_key_map_%d[NR_KEYS] = {", i);
|
||||
for (j = 0; j < NR_KEYS; ++j) {
|
||||
if ((j%8) == 0) {
|
||||
if ((j % 8) == 0) {
|
||||
printf("\n ");
|
||||
}
|
||||
printf("0x%.4x, ", kbd->key_maps[i][j]);
|
||||
@@ -194,23 +192,22 @@ static int SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SDL_EVDEV_keyboard_state * kbd_cleanup_state = NULL;
|
||||
static SDL_EVDEV_keyboard_state *kbd_cleanup_state = NULL;
|
||||
static int kbd_cleanup_sigactions_installed = 0;
|
||||
static int kbd_cleanup_atexit_installed = 0;
|
||||
|
||||
static struct sigaction old_sigaction[NSIG];
|
||||
|
||||
static int fatal_signals[] =
|
||||
{
|
||||
static int fatal_signals[] = {
|
||||
/* Handlers for SIGTERM and SIGINT are installed in SDL_QuitInit. */
|
||||
SIGHUP, SIGQUIT, SIGILL, SIGABRT,
|
||||
SIGFPE, SIGSEGV, SIGPIPE, SIGBUS,
|
||||
SIGHUP, SIGQUIT, SIGILL, SIGABRT,
|
||||
SIGFPE, SIGSEGV, SIGPIPE, SIGBUS,
|
||||
SIGSYS
|
||||
};
|
||||
|
||||
static void kbd_cleanup(void)
|
||||
{
|
||||
SDL_EVDEV_keyboard_state* kbd = kbd_cleanup_state;
|
||||
SDL_EVDEV_keyboard_state *kbd = kbd_cleanup_state;
|
||||
if (kbd == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -219,18 +216,17 @@ static void kbd_cleanup(void)
|
||||
ioctl(kbd->console_fd, KDSKBMODE, kbd->old_kbd_mode);
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_EVDEV_kbd_reraise_signal(int sig)
|
||||
static void SDL_EVDEV_kbd_reraise_signal(int sig)
|
||||
{
|
||||
raise(sig);
|
||||
}
|
||||
|
||||
siginfo_t* SDL_EVDEV_kdb_cleanup_siginfo = NULL;
|
||||
void* SDL_EVDEV_kdb_cleanup_ucontext = NULL;
|
||||
siginfo_t *SDL_EVDEV_kdb_cleanup_siginfo = NULL;
|
||||
void *SDL_EVDEV_kdb_cleanup_ucontext = NULL;
|
||||
|
||||
static void kbd_cleanup_signal_action(int signum, siginfo_t* info, void* ucontext)
|
||||
static void kbd_cleanup_signal_action(int signum, siginfo_t *info, void *ucontext)
|
||||
{
|
||||
struct sigaction* old_action_p = &(old_sigaction[signum]);
|
||||
struct sigaction *old_action_p = &(old_sigaction[signum]);
|
||||
sigset_t sigset;
|
||||
|
||||
/* Restore original signal handler before going any further. */
|
||||
@@ -264,7 +260,7 @@ static void kbd_unregister_emerg_cleanup()
|
||||
kbd_cleanup_sigactions_installed = 0;
|
||||
|
||||
for (tabidx = 0; tabidx < sizeof(fatal_signals) / sizeof(fatal_signals[0]); ++tabidx) {
|
||||
struct sigaction* old_action_p;
|
||||
struct sigaction *old_action_p;
|
||||
struct sigaction cur_action;
|
||||
signum = fatal_signals[tabidx];
|
||||
old_action_p = &(old_sigaction[signum]);
|
||||
@@ -293,7 +289,7 @@ static void kbd_cleanup_atexit(void)
|
||||
kbd_unregister_emerg_cleanup();
|
||||
}
|
||||
|
||||
static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd)
|
||||
static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state *kbd)
|
||||
{
|
||||
int tabidx, signum;
|
||||
|
||||
@@ -317,9 +313,9 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd)
|
||||
kbd_cleanup_sigactions_installed = 1;
|
||||
|
||||
for (tabidx = 0; tabidx < sizeof(fatal_signals) / sizeof(fatal_signals[0]); ++tabidx) {
|
||||
struct sigaction* old_action_p;
|
||||
struct sigaction *old_action_p;
|
||||
struct sigaction new_action;
|
||||
signum = fatal_signals[tabidx];
|
||||
signum = fatal_signals[tabidx];
|
||||
old_action_p = &(old_sigaction[signum]);
|
||||
if (sigaction(signum, NULL, old_action_p)) {
|
||||
continue;
|
||||
@@ -328,7 +324,7 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd)
|
||||
/* Skip SIGHUP and SIGPIPE if handler is already installed
|
||||
* - assume the handler will do the cleanup
|
||||
*/
|
||||
if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) {
|
||||
if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void (*)(int))old_action_p->sa_sigaction != SIG_DFL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -345,7 +341,7 @@ SDL_EVDEV_kbd_init(void)
|
||||
SDL_EVDEV_keyboard_state *kbd;
|
||||
int i;
|
||||
char flag_state;
|
||||
char shift_state[ sizeof (long) ] = {TIOCL_GETSHIFTSTATE, 0};
|
||||
char shift_state[sizeof(long)] = { TIOCL_GETSHIFTSTATE, 0 };
|
||||
|
||||
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd));
|
||||
if (kbd == NULL) {
|
||||
@@ -411,8 +407,7 @@ SDL_EVDEV_kbd_init(void)
|
||||
return kbd;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
|
||||
void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
|
||||
{
|
||||
if (kbd == NULL) {
|
||||
return;
|
||||
@@ -447,7 +442,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
|
||||
static void put_queue(SDL_EVDEV_keyboard_state *kbd, uint c)
|
||||
{
|
||||
/* c is already part of a UTF-8 sequence and safe to add as a character */
|
||||
if (kbd->text_len < (sizeof(kbd->text)-1)) {
|
||||
if (kbd->text_len < (sizeof(kbd->text) - 1)) {
|
||||
kbd->text[kbd->text_len++] = (char)c;
|
||||
}
|
||||
}
|
||||
@@ -615,7 +610,7 @@ static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_f
|
||||
{
|
||||
if (up_flag) {
|
||||
return; /* no action, if this is a key release */
|
||||
}
|
||||
}
|
||||
|
||||
if (kbd->diacr) {
|
||||
value = handle_diacr(kbd, value);
|
||||
@@ -639,7 +634,7 @@ static void k_deadunicode(SDL_EVDEV_keyboard_state *kbd, unsigned int value, cha
|
||||
|
||||
static void k_dead(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
|
||||
{
|
||||
const unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' };
|
||||
const unsigned char ret_diacr[NR_DEAD] = { '`', '\'', '^', '~', '"', ',' };
|
||||
|
||||
k_deadunicode(kbd, ret_diacr[value], up_flag);
|
||||
}
|
||||
@@ -666,7 +661,7 @@ static void k_pad(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_fl
|
||||
static const char pad_chars[] = "0123456789+-*/\015,.?()#";
|
||||
|
||||
if (up_flag)
|
||||
return; /* no action, if this is a key release */
|
||||
return; /* no action, if this is a key release */
|
||||
|
||||
if (!vc_kbd_led(kbd, K_NUMLOCK)) {
|
||||
/* unprintable action */
|
||||
@@ -768,8 +763,7 @@ static void k_brl(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_fl
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int down)
|
||||
void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int down)
|
||||
{
|
||||
unsigned char shift_final;
|
||||
unsigned char type;
|
||||
@@ -841,13 +835,11 @@ SDL_EVDEV_kbd_init(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down)
|
||||
void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state)
|
||||
void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* *INDENT-OFF* */ /* clang-format off */
|
||||
|
||||
static unsigned short default_key_map_0[NR_KEYS] = {
|
||||
0xf200, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
|
||||
0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
|
||||
@@ -4374,6 +4376,8 @@ static unsigned short default_key_map_127[NR_KEYS] = {
|
||||
};
|
||||
#endif /* INCLUDE_EXTENDED_KEYMAP */
|
||||
|
||||
/* *INDENT-ON* */ /* clang-format on */
|
||||
|
||||
static unsigned short *default_key_maps[MAX_NR_KEYMAPS] = {
|
||||
default_key_map_0,
|
||||
default_key_map_1,
|
||||
@@ -4504,7 +4508,7 @@ static unsigned short *default_key_maps[MAX_NR_KEYMAPS] = {
|
||||
default_key_map_125,
|
||||
default_key_map_126,
|
||||
default_key_map_127,
|
||||
#else /* !INCLUDE_EXTENDED_KEYMAP */
|
||||
#else /* !INCLUDE_EXTENDED_KEYMAP */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
@@ -55,8 +55,7 @@ typedef struct _FcitxClient
|
||||
|
||||
static FcitxClient fcitx_client;
|
||||
|
||||
static char*
|
||||
GetAppName()
|
||||
static char *GetAppName()
|
||||
{
|
||||
#if defined(__LINUX__) || defined(__FREEBSD__)
|
||||
char *spot;
|
||||
@@ -86,10 +85,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 +140,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 +166,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 +184,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 +200,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 +247,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 +255,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 +274,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 +303,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 +311,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 +321,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 +335,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 +381,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 +390,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 +399,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 +418,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 +429,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 +442,7 @@ SDL_Fcitx_UpdateTextRect(const SDL_Rect *rect)
|
||||
|
||||
focused_win = SDL_GetKeyboardFocus();
|
||||
if (focused_win == NULL) {
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_VERSION(&info.version);
|
||||
@@ -487,11 +476,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;
|
||||
|
||||
@@ -37,14 +37,14 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
static const char IBUS_PATH[] = "/org/freedesktop/IBus";
|
||||
static const char IBUS_PATH[] = "/org/freedesktop/IBus";
|
||||
|
||||
static const char IBUS_SERVICE[] = "org.freedesktop.IBus";
|
||||
static const char IBUS_INTERFACE[] = "org.freedesktop.IBus";
|
||||
static const char IBUS_SERVICE[] = "org.freedesktop.IBus";
|
||||
static const char IBUS_INTERFACE[] = "org.freedesktop.IBus";
|
||||
static const char IBUS_INPUT_INTERFACE[] = "org.freedesktop.IBus.InputContext";
|
||||
|
||||
static const char IBUS_PORTAL_SERVICE[] = "org.freedesktop.portal.IBus";
|
||||
static const char IBUS_PORTAL_INTERFACE[] = "org.freedesktop.IBus.Portal";
|
||||
static const char IBUS_PORTAL_SERVICE[] = "org.freedesktop.portal.IBus";
|
||||
static const char IBUS_PORTAL_INTERFACE[] = "org.freedesktop.IBus.Portal";
|
||||
static const char IBUS_PORTAL_INPUT_INTERFACE[] = "org.freedesktop.IBus.InputContext";
|
||||
|
||||
static const char *ibus_service = NULL;
|
||||
@@ -57,13 +57,11 @@ static SDL_bool ibus_is_portal_interface = SDL_FALSE;
|
||||
static char *ibus_addr_file = NULL;
|
||||
static int inotify_fd = -1, inotify_wd = -1;
|
||||
|
||||
|
||||
static Uint32
|
||||
IBus_ModState(void)
|
||||
static Uint32 IBus_ModState(void)
|
||||
{
|
||||
Uint32 ibus_mods = 0;
|
||||
SDL_Keymod sdl_mods = SDL_GetModState();
|
||||
|
||||
|
||||
/* Not sure about MOD3, MOD4 and HYPER mappings */
|
||||
if (sdl_mods & KMOD_LSHIFT) {
|
||||
ibus_mods |= IBUS_SHIFT_MASK;
|
||||
@@ -93,9 +91,8 @@ IBus_ModState(void)
|
||||
return ibus_mods;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
IBus_EnterVariant(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *dbus,
|
||||
DBusMessageIter *inside, const char * struct_id, size_t id_size)
|
||||
static SDL_bool IBus_EnterVariant(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *dbus,
|
||||
DBusMessageIter *inside, const char *struct_id, size_t id_size)
|
||||
{
|
||||
DBusMessageIter sub;
|
||||
if (dbus->message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT) {
|
||||
@@ -121,9 +118,8 @@ IBus_EnterVariant(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
IBus_GetDecorationPosition(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *dbus,
|
||||
Uint32 *start_pos, Uint32 *end_pos)
|
||||
static SDL_bool IBus_GetDecorationPosition(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *dbus,
|
||||
Uint32 *start_pos, Uint32 *end_pos)
|
||||
{
|
||||
DBusMessageIter sub1, sub2, array;
|
||||
|
||||
@@ -186,8 +182,7 @@ IBus_GetDecorationPosition(DBusConnection *conn, DBusMessageIter *iter, SDL_DBus
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static const char *
|
||||
IBus_GetVariantText(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *dbus)
|
||||
static const char *IBus_GetVariantText(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *dbus)
|
||||
{
|
||||
/* The text we need is nested weirdly, use dbus-monitor to see the structure better */
|
||||
const char *text = NULL;
|
||||
@@ -208,9 +203,8 @@ IBus_GetVariantText(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext
|
||||
return text;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
IBus_GetVariantCursorPos(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *dbus,
|
||||
Uint32 *pos)
|
||||
static SDL_bool IBus_GetVariantCursorPos(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *dbus,
|
||||
Uint32 *pos)
|
||||
{
|
||||
dbus->message_iter_next(iter);
|
||||
|
||||
@@ -223,8 +217,7 @@ IBus_GetVariantCursorPos(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusCo
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static DBusHandlerResult
|
||||
IBus_MessageHandler(DBusConnection *conn, DBusMessage *msg, void *user_data)
|
||||
static DBusHandlerResult IBus_MessageHandler(DBusConnection *conn, DBusMessage *msg, void *user_data)
|
||||
{
|
||||
SDL_DBusContext *dbus = (SDL_DBusContext *)user_data;
|
||||
|
||||
@@ -240,7 +233,7 @@ IBus_MessageHandler(DBusConnection *conn, DBusMessage *msg, void *user_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;
|
||||
@@ -283,7 +276,7 @@ IBus_MessageHandler(DBusConnection *conn, DBusMessage *msg, void *user_data)
|
||||
size_t cursor = 0;
|
||||
|
||||
do {
|
||||
const size_t sz = SDL_utf8strlcpy(buf, text+i, sizeof(buf));
|
||||
const size_t sz = SDL_utf8strlcpy(buf, text + i, sizeof(buf));
|
||||
const size_t chars = SDL_utf8strlen(buf);
|
||||
|
||||
SDL_SendEditingText(buf, cursor, chars);
|
||||
@@ -306,8 +299,7 @@ IBus_MessageHandler(DBusConnection *conn, DBusMessage *msg, void *user_data)
|
||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||
}
|
||||
|
||||
static char *
|
||||
IBus_ReadAddressFromFile(const char *file_path)
|
||||
static char *IBus_ReadAddressFromFile(const char *file_path)
|
||||
{
|
||||
char addr_buf[1024];
|
||||
SDL_bool success = SDL_FALSE;
|
||||
@@ -319,7 +311,7 @@ IBus_ReadAddressFromFile(const char *file_path)
|
||||
}
|
||||
|
||||
while (fgets(addr_buf, sizeof(addr_buf), addr_file)) {
|
||||
if (SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=")-1) == 0) {
|
||||
if (SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=") - 1) == 0) {
|
||||
size_t sz = SDL_strlen(addr_buf);
|
||||
if (addr_buf[sz - 1] == '\n') {
|
||||
addr_buf[sz - 1] = 0;
|
||||
@@ -341,8 +333,7 @@ IBus_ReadAddressFromFile(const char *file_path)
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
IBus_GetDBusAddressFilename(void)
|
||||
static char *IBus_GetDBusAddressFilename(void)
|
||||
{
|
||||
SDL_DBusContext *dbus;
|
||||
const char *disp_env;
|
||||
@@ -358,18 +349,18 @@ IBus_GetDBusAddressFilename(void)
|
||||
if (ibus_addr_file) {
|
||||
return SDL_strdup(ibus_addr_file);
|
||||
}
|
||||
|
||||
|
||||
dbus = SDL_DBus_GetContext();
|
||||
if (dbus == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Use this environment variable if it exists. */
|
||||
addr = SDL_getenv("IBUS_ADDRESS");
|
||||
if (addr && *addr) {
|
||||
return SDL_strdup(addr);
|
||||
}
|
||||
|
||||
|
||||
/* Otherwise, we have to get the hostname, display, machine id, config dir
|
||||
and look up the address from a filepath using all those bits, eek. */
|
||||
disp_env = SDL_getenv("DISPLAY");
|
||||
@@ -379,23 +370,23 @@ IBus_GetDBusAddressFilename(void)
|
||||
} else {
|
||||
display = SDL_strdup(disp_env);
|
||||
}
|
||||
|
||||
|
||||
host = display;
|
||||
disp_num = SDL_strrchr(display, ':');
|
||||
disp_num = SDL_strrchr(display, ':');
|
||||
screen_num = SDL_strrchr(display, '.');
|
||||
|
||||
|
||||
if (disp_num == NULL) {
|
||||
SDL_free(display);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
*disp_num = 0;
|
||||
disp_num++;
|
||||
|
||||
|
||||
if (screen_num) {
|
||||
*screen_num = 0;
|
||||
}
|
||||
|
||||
|
||||
if (!*host) {
|
||||
const char *session = SDL_getenv("XDG_SESSION_TYPE");
|
||||
if (session != NULL && SDL_strcmp(session, "wayland") == 0) {
|
||||
@@ -404,9 +395,9 @@ IBus_GetDBusAddressFilename(void)
|
||||
host = "unix";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SDL_memset(config_dir, 0, sizeof(config_dir));
|
||||
|
||||
|
||||
conf_env = SDL_getenv("XDG_CONFIG_HOME");
|
||||
if (conf_env && *conf_env) {
|
||||
SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
|
||||
@@ -418,26 +409,25 @@ IBus_GetDBusAddressFilename(void)
|
||||
}
|
||||
SDL_snprintf(config_dir, sizeof(config_dir), "%s/.config", home_env);
|
||||
}
|
||||
|
||||
|
||||
key = dbus->get_local_machine_id();
|
||||
|
||||
SDL_memset(file_path, 0, sizeof(file_path));
|
||||
SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s",
|
||||
config_dir, key, host, disp_num);
|
||||
SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s",
|
||||
config_dir, key, host, disp_num);
|
||||
dbus->free(key);
|
||||
SDL_free(display);
|
||||
|
||||
|
||||
return SDL_strdup(file_path);
|
||||
}
|
||||
|
||||
static SDL_bool IBus_CheckConnection(SDL_DBusContext *dbus);
|
||||
|
||||
static void SDLCALL
|
||||
IBus_SetCapabilities(void *data, const char *name, const char *old_val,
|
||||
const char *internal_editing)
|
||||
static void SDLCALL IBus_SetCapabilities(void *data, const char *name, const char *old_val,
|
||||
const char *internal_editing)
|
||||
{
|
||||
SDL_DBusContext *dbus = SDL_DBus_GetContext();
|
||||
|
||||
|
||||
if (IBus_CheckConnection(dbus)) {
|
||||
Uint32 caps = IBUS_CAP_FOCUS;
|
||||
if (!(internal_editing && *internal_editing == '1')) {
|
||||
@@ -445,19 +435,17 @@ IBus_SetCapabilities(void *data, const char *name, const char *old_val,
|
||||
}
|
||||
|
||||
SDL_DBus_CallVoidMethodOnConnection(ibus_conn, ibus_service, input_ctx_path, ibus_input_interface, "SetCapabilities",
|
||||
DBUS_TYPE_UINT32, &caps, DBUS_TYPE_INVALID);
|
||||
DBUS_TYPE_UINT32, &caps, DBUS_TYPE_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static SDL_bool
|
||||
IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
|
||||
static SDL_bool IBus_SetupConnection(SDL_DBusContext *dbus, const char *addr)
|
||||
{
|
||||
const char *client_name = "SDL2_Application";
|
||||
const char *path = NULL;
|
||||
SDL_bool result = SDL_FALSE;
|
||||
DBusObjectPathVTable ibus_vtable;
|
||||
|
||||
|
||||
SDL_zero(ibus_vtable);
|
||||
ibus_vtable.message_function = &IBus_MessageHandler;
|
||||
|
||||
@@ -481,16 +469,16 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
|
||||
ibus_conn = dbus->connection_open_private(addr, NULL);
|
||||
|
||||
if (ibus_conn == NULL) {
|
||||
return SDL_FALSE; /* oh well. */
|
||||
return SDL_FALSE; /* oh well. */
|
||||
}
|
||||
|
||||
dbus->connection_flush(ibus_conn);
|
||||
|
||||
|
||||
if (!dbus->bus_register(ibus_conn, NULL)) {
|
||||
ibus_conn = NULL;
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
dbus->connection_flush(ibus_conn);
|
||||
|
||||
result = SDL_DBus_CallMethodOnConnection(ibus_conn, ibus_service, IBUS_PATH, ibus_interface, "CreateInputContext",
|
||||
@@ -500,7 +488,7 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
|
||||
|
||||
if (result) {
|
||||
char matchstr[128];
|
||||
SDL_snprintf(matchstr, sizeof (matchstr), "type='signal',interface='%s'", ibus_input_interface);
|
||||
SDL_snprintf(matchstr, sizeof(matchstr), "type='signal',interface='%s'", ibus_input_interface);
|
||||
SDL_free(input_ctx_path);
|
||||
input_ctx_path = SDL_strdup(path);
|
||||
SDL_AddHintCallback(SDL_HINT_IME_INTERNAL_EDITING, IBus_SetCapabilities, NULL);
|
||||
@@ -511,46 +499,45 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
|
||||
|
||||
SDL_IBus_SetFocus(SDL_GetKeyboardFocus() != NULL);
|
||||
SDL_IBus_UpdateTextRect(NULL);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
IBus_CheckConnection(SDL_DBusContext *dbus)
|
||||
static SDL_bool IBus_CheckConnection(SDL_DBusContext *dbus)
|
||||
{
|
||||
if (dbus == NULL) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
if (ibus_conn && dbus->connection_get_is_connected(ibus_conn)) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (inotify_fd > 0 && inotify_wd > 0) {
|
||||
char buf[1024];
|
||||
ssize_t readsize = read(inotify_fd, buf, sizeof(buf));
|
||||
if (readsize > 0) {
|
||||
|
||||
|
||||
char *p;
|
||||
SDL_bool file_updated = SDL_FALSE;
|
||||
|
||||
|
||||
for (p = buf; p < buf + readsize; /**/) {
|
||||
struct inotify_event *event = (struct inotify_event*) p;
|
||||
struct inotify_event *event = (struct inotify_event *)p;
|
||||
if (event->len > 0) {
|
||||
char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/');
|
||||
if (addr_file_no_path == NULL) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
if (SDL_strcmp(addr_file_no_path + 1, event->name) == 0) {
|
||||
file_updated = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
p += sizeof(struct inotify_event) + event->len;
|
||||
}
|
||||
|
||||
|
||||
if (file_updated) {
|
||||
char *addr = IBus_ReadAddressFromFile(ibus_addr_file);
|
||||
if (addr) {
|
||||
@@ -561,7 +548,7 @@ IBus_CheckConnection(SDL_DBusContext *dbus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -570,7 +557,7 @@ SDL_IBus_Init(void)
|
||||
{
|
||||
SDL_bool result = SDL_FALSE;
|
||||
SDL_DBusContext *dbus = SDL_DBus_GetContext();
|
||||
|
||||
|
||||
if (dbus) {
|
||||
char *addr_file = IBus_GetDBusAddressFilename();
|
||||
char *addr;
|
||||
@@ -579,29 +566,29 @@ SDL_IBus_Init(void)
|
||||
if (addr_file == NULL) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
/* !!! FIXME: if ibus_addr_file != NULL, this will overwrite it and leak (twice!) */
|
||||
ibus_addr_file = SDL_strdup(addr_file);
|
||||
|
||||
|
||||
addr = IBus_ReadAddressFromFile(addr_file);
|
||||
if (addr == NULL) {
|
||||
SDL_free(addr_file);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
if (inotify_fd < 0) {
|
||||
inotify_fd = inotify_init();
|
||||
fcntl(inotify_fd, F_SETFL, O_NONBLOCK);
|
||||
}
|
||||
|
||||
|
||||
addr_file_dir = SDL_strrchr(addr_file, '/');
|
||||
if (addr_file_dir) {
|
||||
*addr_file_dir = 0;
|
||||
}
|
||||
|
||||
|
||||
inotify_wd = inotify_add_watch(inotify_fd, addr_file, IN_CREATE | IN_MODIFY);
|
||||
SDL_free(addr_file);
|
||||
|
||||
|
||||
result = IBus_SetupConnection(dbus, addr);
|
||||
SDL_free(addr);
|
||||
|
||||
@@ -617,27 +604,26 @@ SDL_IBus_Init(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IBus_Quit(void)
|
||||
{
|
||||
void SDL_IBus_Quit(void)
|
||||
{
|
||||
SDL_DBusContext *dbus;
|
||||
|
||||
if (input_ctx_path) {
|
||||
SDL_free(input_ctx_path);
|
||||
input_ctx_path = NULL;
|
||||
}
|
||||
|
||||
|
||||
if (ibus_addr_file) {
|
||||
SDL_free(ibus_addr_file);
|
||||
ibus_addr_file = NULL;
|
||||
}
|
||||
|
||||
|
||||
dbus = SDL_DBus_GetContext();
|
||||
|
||||
|
||||
/* if using portal, ibus_conn == session_conn; don't release it here. */
|
||||
if (dbus && ibus_conn && !ibus_is_portal_interface) {
|
||||
dbus->connection_close(ibus_conn);
|
||||
@@ -658,40 +644,36 @@ SDL_IBus_Quit(void)
|
||||
/* !!! FIXME: should we close(inotify_fd) here? */
|
||||
|
||||
SDL_DelHintCallback(SDL_HINT_IME_INTERNAL_EDITING, IBus_SetCapabilities, NULL);
|
||||
|
||||
|
||||
SDL_memset(&ibus_cursor_rect, 0, sizeof(ibus_cursor_rect));
|
||||
}
|
||||
|
||||
static void
|
||||
IBus_SimpleMessage(const char *method)
|
||||
{
|
||||
static void IBus_SimpleMessage(const char *method)
|
||||
{
|
||||
SDL_DBusContext *dbus = SDL_DBus_GetContext();
|
||||
|
||||
|
||||
if ((input_ctx_path != NULL) && (IBus_CheckConnection(dbus))) {
|
||||
SDL_DBus_CallVoidMethodOnConnection(ibus_conn, ibus_service, input_ctx_path, ibus_input_interface, method, DBUS_TYPE_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IBus_SetFocus(SDL_bool focused)
|
||||
{
|
||||
void SDL_IBus_SetFocus(SDL_bool focused)
|
||||
{
|
||||
const char *method = focused ? "FocusIn" : "FocusOut";
|
||||
IBus_SimpleMessage(method);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IBus_Reset(void)
|
||||
void SDL_IBus_Reset(void)
|
||||
{
|
||||
IBus_SimpleMessage("Reset");
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
|
||||
{
|
||||
{
|
||||
Uint32 result = 0;
|
||||
SDL_DBusContext *dbus = SDL_DBus_GetContext();
|
||||
|
||||
|
||||
if (IBus_CheckConnection(dbus)) {
|
||||
Uint32 mods = IBus_ModState();
|
||||
Uint32 ibus_keycode = keycode - 8;
|
||||
@@ -699,19 +681,18 @@ SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
|
||||
mods |= (1 << 30); // IBUS_RELEASE_MASK
|
||||
}
|
||||
if (!SDL_DBus_CallMethodOnConnection(ibus_conn, ibus_service, input_ctx_path, ibus_input_interface, "ProcessKeyEvent",
|
||||
DBUS_TYPE_UINT32, &keysym, DBUS_TYPE_UINT32, &ibus_keycode, DBUS_TYPE_UINT32, &mods, DBUS_TYPE_INVALID,
|
||||
DBUS_TYPE_BOOLEAN, &result, DBUS_TYPE_INVALID)) {
|
||||
DBUS_TYPE_UINT32, &keysym, DBUS_TYPE_UINT32, &ibus_keycode, DBUS_TYPE_UINT32, &mods, DBUS_TYPE_INVALID,
|
||||
DBUS_TYPE_BOOLEAN, &result, DBUS_TYPE_INVALID)) {
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SDL_IBus_UpdateTextRect(NULL);
|
||||
|
||||
return result ? SDL_TRUE : SDL_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IBus_UpdateTextRect(const SDL_Rect *rect)
|
||||
void SDL_IBus_UpdateTextRect(const SDL_Rect *rect)
|
||||
{
|
||||
SDL_Window *focused_win;
|
||||
SDL_SysWMinfo info;
|
||||
@@ -749,23 +730,22 @@ SDL_IBus_UpdateTextRect(const SDL_Rect *rect)
|
||||
|
||||
x += ibus_cursor_rect.x;
|
||||
y += ibus_cursor_rect.y;
|
||||
|
||||
|
||||
dbus = SDL_DBus_GetContext();
|
||||
|
||||
|
||||
if (IBus_CheckConnection(dbus)) {
|
||||
SDL_DBus_CallVoidMethodOnConnection(ibus_conn, ibus_service, input_ctx_path, ibus_input_interface, "SetCursorLocation",
|
||||
DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y, DBUS_TYPE_INT32, &ibus_cursor_rect.w, DBUS_TYPE_INT32, &ibus_cursor_rect.h, DBUS_TYPE_INVALID);
|
||||
DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y, DBUS_TYPE_INT32, &ibus_cursor_rect.w, DBUS_TYPE_INT32, &ibus_cursor_rect.h, DBUS_TYPE_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IBus_PumpEvents(void)
|
||||
void SDL_IBus_PumpEvents(void)
|
||||
{
|
||||
SDL_DBusContext *dbus = SDL_DBus_GetContext();
|
||||
|
||||
|
||||
if (IBus_CheckConnection(dbus)) {
|
||||
dbus->connection_read_write(ibus_conn, 0);
|
||||
|
||||
|
||||
while (dbus->connection_dispatch(ibus_conn) == DBUS_DISPATCH_DATA_REMAINS) {
|
||||
/* Do nothing, actual work happens in IBus_MessageHandler */
|
||||
}
|
||||
|
||||
@@ -43,11 +43,11 @@ extern void SDL_IBus_Reset(void);
|
||||
called some time after this, to receive the TextInput / TextEditing event back. */
|
||||
extern SDL_bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state);
|
||||
|
||||
/* Update the position of IBus' candidate list. If rect is NULL then this will
|
||||
/* Update the position of IBus' candidate list. If rect is NULL then this will
|
||||
just reposition it relative to the focused window's new position. */
|
||||
extern void SDL_IBus_UpdateTextRect(const SDL_Rect *window_relative_rect);
|
||||
|
||||
/* Checks DBus for new IBus events, and calls SDL_SendKeyboardText /
|
||||
/* Checks DBus for new IBus events, and calls SDL_SendKeyboardText /
|
||||
SDL_SendEditingText for each event it finds */
|
||||
extern void SDL_IBus_PumpEvents(void);
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ static _SDL_IME_ProcessKeyEvent SDL_IME_ProcessKeyEvent_Real = NULL;
|
||||
static _SDL_IME_UpdateTextRect SDL_IME_UpdateTextRect_Real = NULL;
|
||||
static _SDL_IME_PumpEvents SDL_IME_PumpEvents_Real = NULL;
|
||||
|
||||
static void
|
||||
InitIME()
|
||||
static void InitIME()
|
||||
{
|
||||
static SDL_bool inited = SDL_FALSE;
|
||||
#ifdef HAVE_FCITX
|
||||
@@ -107,24 +106,21 @@ SDL_IME_Init(void)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IME_Quit(void)
|
||||
void SDL_IME_Quit(void)
|
||||
{
|
||||
if (SDL_IME_Quit_Real) {
|
||||
SDL_IME_Quit_Real();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IME_SetFocus(SDL_bool focused)
|
||||
void SDL_IME_SetFocus(SDL_bool focused)
|
||||
{
|
||||
if (SDL_IME_SetFocus_Real) {
|
||||
SDL_IME_SetFocus_Real(focused);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IME_Reset(void)
|
||||
void SDL_IME_Reset(void)
|
||||
{
|
||||
if (SDL_IME_Reset_Real) {
|
||||
SDL_IME_Reset_Real();
|
||||
@@ -141,16 +137,14 @@ SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, Uint8 state)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IME_UpdateTextRect(const SDL_Rect *rect)
|
||||
void SDL_IME_UpdateTextRect(const SDL_Rect *rect)
|
||||
{
|
||||
if (SDL_IME_UpdateTextRect_Real) {
|
||||
SDL_IME_UpdateTextRect_Real(rect);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_IME_PumpEvents()
|
||||
void SDL_IME_PumpEvents()
|
||||
{
|
||||
if (SDL_IME_PumpEvents_Real) {
|
||||
SDL_IME_PumpEvents_Real();
|
||||
|
||||
@@ -33,9 +33,7 @@ SDL_Sandbox SDL_DetectSandbox(void)
|
||||
|
||||
/* For Snap, we check multiple variables because they might be set for
|
||||
* unrelated reasons. This is the same thing WebKitGTK does. */
|
||||
if (SDL_getenv("SNAP") != NULL
|
||||
&& SDL_getenv("SNAP_NAME") != NULL
|
||||
&& SDL_getenv("SNAP_REVISION") != NULL) {
|
||||
if (SDL_getenv("SNAP") != NULL && SDL_getenv("SNAP_NAME") != NULL && SDL_getenv("SNAP_REVISION") != NULL) {
|
||||
return SDL_SANDBOX_SNAP;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,16 +48,16 @@
|
||||
#include <sched.h>
|
||||
|
||||
/* d-bus queries to org.freedesktop.RealtimeKit1. */
|
||||
#define RTKIT_DBUS_NODE "org.freedesktop.RealtimeKit1"
|
||||
#define RTKIT_DBUS_PATH "/org/freedesktop/RealtimeKit1"
|
||||
#define RTKIT_DBUS_NODE "org.freedesktop.RealtimeKit1"
|
||||
#define RTKIT_DBUS_PATH "/org/freedesktop/RealtimeKit1"
|
||||
#define RTKIT_DBUS_INTERFACE "org.freedesktop.RealtimeKit1"
|
||||
|
||||
/* d-bus queries to the XDG portal interface to RealtimeKit1 */
|
||||
#define XDG_PORTAL_DBUS_NODE "org.freedesktop.portal.Desktop"
|
||||
#define XDG_PORTAL_DBUS_PATH "/org/freedesktop/portal/desktop"
|
||||
#define XDG_PORTAL_DBUS_NODE "org.freedesktop.portal.Desktop"
|
||||
#define XDG_PORTAL_DBUS_PATH "/org/freedesktop/portal/desktop"
|
||||
#define XDG_PORTAL_DBUS_INTERFACE "org.freedesktop.portal.Realtime"
|
||||
|
||||
static SDL_bool rtkit_use_session_conn;
|
||||
static SDL_bool rtkit_use_session_conn;
|
||||
static const char *rtkit_dbus_node;
|
||||
static const char *rtkit_dbus_path;
|
||||
static const char *rtkit_dbus_interface;
|
||||
@@ -72,16 +72,14 @@ static Sint64 rtkit_max_rttime_usec = 200000;
|
||||
* - The desktop portal exists and supports the realtime interface.
|
||||
* - The realtime interface is new enough to have the required bug fixes applied.
|
||||
*/
|
||||
static SDL_bool
|
||||
realtime_portal_supported(DBusConnection *conn)
|
||||
static SDL_bool realtime_portal_supported(DBusConnection *conn)
|
||||
{
|
||||
Sint64 res;
|
||||
return SDL_DBus_QueryPropertyOnConnection(conn, XDG_PORTAL_DBUS_NODE, XDG_PORTAL_DBUS_PATH, XDG_PORTAL_DBUS_INTERFACE,
|
||||
"RTTimeUSecMax", DBUS_TYPE_INT64, &res);
|
||||
}
|
||||
|
||||
static void
|
||||
set_rtkit_interface()
|
||||
static void set_rtkit_interface()
|
||||
{
|
||||
SDL_DBusContext *dbus = SDL_DBus_GetContext();
|
||||
|
||||
@@ -99,8 +97,7 @@ set_rtkit_interface()
|
||||
}
|
||||
}
|
||||
|
||||
static DBusConnection*
|
||||
get_rtkit_dbus_connection()
|
||||
static DBusConnection *get_rtkit_dbus_connection()
|
||||
{
|
||||
SDL_DBusContext *dbus = SDL_DBus_GetContext();
|
||||
|
||||
@@ -111,8 +108,7 @@ get_rtkit_dbus_connection()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
rtkit_initialize()
|
||||
static void rtkit_initialize()
|
||||
{
|
||||
DBusConnection *dbus_conn;
|
||||
|
||||
@@ -138,8 +134,7 @@ rtkit_initialize()
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
rtkit_initialize_realtime_thread()
|
||||
static SDL_bool rtkit_initialize_realtime_thread()
|
||||
{
|
||||
// Following is an excerpt from rtkit README that outlines the requirements
|
||||
// a thread must meet before making rtkit requests:
|
||||
@@ -164,7 +159,7 @@ rtkit_initialize_realtime_thread()
|
||||
int err;
|
||||
struct rlimit rlimit;
|
||||
int nLimit = RLIMIT_RTTIME;
|
||||
pid_t nPid = 0; //self
|
||||
pid_t nPid = 0; // self
|
||||
int nSchedPolicy = sched_getscheduler(nPid) | SCHED_RESET_ON_FORK;
|
||||
struct sched_param schedParam;
|
||||
|
||||
@@ -198,8 +193,7 @@ rtkit_initialize_realtime_thread()
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
rtkit_setpriority_nice(pid_t thread, int nice_level)
|
||||
static SDL_bool rtkit_setpriority_nice(pid_t thread, int nice_level)
|
||||
{
|
||||
DBusConnection *dbus_conn;
|
||||
Uint64 pid = (Uint64)getpid();
|
||||
@@ -222,8 +216,7 @@ rtkit_setpriority_nice(pid_t thread, int nice_level)
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
rtkit_setpriority_realtime(pid_t thread, int rt_priority)
|
||||
static SDL_bool rtkit_setpriority_realtime(pid_t thread, int rt_priority)
|
||||
{
|
||||
DBusConnection *dbus_conn;
|
||||
Uint64 pid = (Uint64)getpid();
|
||||
@@ -261,8 +254,7 @@ rtkit_setpriority_realtime(pid_t thread, int rt_priority)
|
||||
#endif /* threads */
|
||||
|
||||
/* this is a public symbol, so it has to exist even if threads are disabled. */
|
||||
int
|
||||
SDL_LinuxSetThreadPriority(Sint64 threadID, int priority)
|
||||
int SDL_LinuxSetThreadPriority(Sint64 threadID, int priority)
|
||||
{
|
||||
#if SDL_THREADS_DISABLED
|
||||
return SDL_Unsupported();
|
||||
@@ -294,8 +286,7 @@ SDL_LinuxSetThreadPriority(Sint64 threadID, int priority)
|
||||
}
|
||||
|
||||
/* this is a public symbol, so it has to exist even if threads are disabled. */
|
||||
int
|
||||
SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy)
|
||||
int SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy)
|
||||
{
|
||||
#if SDL_THREADS_DISABLED
|
||||
return SDL_Unsupported();
|
||||
@@ -356,6 +347,6 @@ SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedP
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* __LINUX__ */
|
||||
#endif /* __LINUX__ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -49,8 +49,7 @@ static int SDL_UDEV_load_syms(void);
|
||||
static SDL_bool SDL_UDEV_hotplug_update_available(void);
|
||||
static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev);
|
||||
|
||||
static SDL_bool
|
||||
SDL_UDEV_load_sym(const char *fn, void **addr)
|
||||
static SDL_bool SDL_UDEV_load_sym(const char *fn, void **addr)
|
||||
{
|
||||
*addr = SDL_LoadFunction(_this->udev_handle, fn);
|
||||
if (*addr == NULL) {
|
||||
@@ -61,12 +60,12 @@ SDL_UDEV_load_sym(const char *fn, void **addr)
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_UDEV_load_syms(void)
|
||||
static int SDL_UDEV_load_syms(void)
|
||||
{
|
||||
/* cast funcs to char* first, to please GCC's strict aliasing rules. */
|
||||
#define SDL_UDEV_SYM(x) \
|
||||
if (!SDL_UDEV_load_sym(#x, (void **) (char *) & _this->syms.x)) return -1
|
||||
/* cast funcs to char* first, to please GCC's strict aliasing rules. */
|
||||
#define SDL_UDEV_SYM(x) \
|
||||
if (!SDL_UDEV_load_sym(#x, (void **)(char *)&_this->syms.x)) \
|
||||
return -1
|
||||
|
||||
SDL_UDEV_SYM(udev_device_get_action);
|
||||
SDL_UDEV_SYM(udev_device_get_devnode);
|
||||
@@ -94,13 +93,12 @@ SDL_UDEV_load_syms(void)
|
||||
SDL_UDEV_SYM(udev_unref);
|
||||
SDL_UDEV_SYM(udev_device_new_from_devnum);
|
||||
SDL_UDEV_SYM(udev_device_get_devnum);
|
||||
#undef SDL_UDEV_SYM
|
||||
#undef SDL_UDEV_SYM
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
SDL_UDEV_hotplug_update_available(void)
|
||||
static SDL_bool SDL_UDEV_hotplug_update_available(void)
|
||||
{
|
||||
if (_this->udev_mon != NULL) {
|
||||
const int fd = _this->syms.udev_monitor_get_fd(_this->udev_mon);
|
||||
@@ -111,14 +109,12 @@ SDL_UDEV_hotplug_update_available(void)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
SDL_UDEV_Init(void)
|
||||
int SDL_UDEV_Init(void)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (_this == NULL) {
|
||||
_this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this));
|
||||
_this = (SDL_UDEV_PrivateData *)SDL_calloc(1, sizeof(*_this));
|
||||
if (_this == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -151,7 +147,6 @@ SDL_UDEV_Init(void)
|
||||
|
||||
/* Do an initial scan of existing devices */
|
||||
SDL_UDEV_Scan();
|
||||
|
||||
}
|
||||
|
||||
_this->ref_count += 1;
|
||||
@@ -159,8 +154,7 @@ SDL_UDEV_Init(void)
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_UDEV_Quit(void)
|
||||
void SDL_UDEV_Quit(void)
|
||||
{
|
||||
SDL_UDEV_CallbackList *item;
|
||||
|
||||
@@ -194,8 +188,7 @@ SDL_UDEV_Quit(void)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_UDEV_Scan(void)
|
||||
void SDL_UDEV_Scan(void)
|
||||
{
|
||||
struct udev_enumerate *enumerate = NULL;
|
||||
struct udev_list_entry *devs = NULL;
|
||||
@@ -283,11 +276,7 @@ SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *product
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
SDL_UDEV_UnloadLibrary(void)
|
||||
void SDL_UDEV_UnloadLibrary(void)
|
||||
{
|
||||
if (_this == NULL) {
|
||||
return;
|
||||
@@ -299,8 +288,7 @@ SDL_UDEV_UnloadLibrary(void)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_UDEV_LoadLibrary(void)
|
||||
int SDL_UDEV_LoadLibrary(void)
|
||||
{
|
||||
int retval = 0, i;
|
||||
|
||||
@@ -327,7 +315,7 @@ SDL_UDEV_LoadLibrary(void)
|
||||
#endif
|
||||
|
||||
if (_this->udev_handle == NULL) {
|
||||
for ( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
|
||||
for (i = 0; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
|
||||
_this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]);
|
||||
if (_this->udev_handle != NULL) {
|
||||
retval = SDL_UDEV_load_syms();
|
||||
@@ -356,7 +344,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
|
||||
int i;
|
||||
unsigned long v;
|
||||
|
||||
SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask));
|
||||
SDL_memset(bitmask, 0, bitmask_len * sizeof(*bitmask));
|
||||
value = _this->syms.udev_device_get_sysattr_value(pdev, attr);
|
||||
if (value == NULL) {
|
||||
return;
|
||||
@@ -365,7 +353,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
|
||||
SDL_strlcpy(text, value, sizeof(text));
|
||||
i = 0;
|
||||
while ((word = SDL_strrchr(text, ' ')) != NULL) {
|
||||
v = SDL_strtoul(word+1, NULL, 16);
|
||||
v = SDL_strtoul(word + 1, NULL, 16);
|
||||
if (i < bitmask_len) {
|
||||
bitmask[i] = v;
|
||||
}
|
||||
@@ -378,8 +366,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
guess_device_class(struct udev_device *dev)
|
||||
static int guess_device_class(struct udev_device *dev)
|
||||
{
|
||||
struct udev_device *pdev;
|
||||
unsigned long bitmask_ev[NBITS(EV_MAX)];
|
||||
@@ -408,8 +395,7 @@ guess_device_class(struct udev_device *dev)
|
||||
&bitmask_rel[0]);
|
||||
}
|
||||
|
||||
static void
|
||||
device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
|
||||
static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
|
||||
{
|
||||
const char *subsystem;
|
||||
const char *val = NULL;
|
||||
@@ -429,23 +415,23 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
|
||||
/* udev rules reference: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c */
|
||||
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK");
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0) {
|
||||
devclass |= SDL_UDEV_DEVICE_JOYSTICK;
|
||||
}
|
||||
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_ACCELEROMETER");
|
||||
if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE) &&
|
||||
val != NULL && SDL_strcmp(val, "1") == 0 ) {
|
||||
val != NULL && SDL_strcmp(val, "1") == 0) {
|
||||
devclass |= SDL_UDEV_DEVICE_JOYSTICK;
|
||||
}
|
||||
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0) {
|
||||
devclass |= SDL_UDEV_DEVICE_MOUSE;
|
||||
}
|
||||
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN");
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0) {
|
||||
devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
|
||||
}
|
||||
|
||||
@@ -456,7 +442,7 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
|
||||
Ref: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c#n183
|
||||
*/
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_KEY");
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0) {
|
||||
devclass |= SDL_UDEV_DEVICE_KEYBOARD;
|
||||
}
|
||||
|
||||
@@ -488,8 +474,7 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_UDEV_Poll(void)
|
||||
void SDL_UDEV_Poll(void)
|
||||
{
|
||||
struct udev_device *dev = NULL;
|
||||
const char *action = NULL;
|
||||
@@ -517,11 +502,10 @@ SDL_UDEV_Poll(void)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
|
||||
int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
|
||||
{
|
||||
SDL_UDEV_CallbackList *item;
|
||||
item = (SDL_UDEV_CallbackList *) SDL_calloc(1, sizeof (SDL_UDEV_CallbackList));
|
||||
item = (SDL_UDEV_CallbackList *)SDL_calloc(1, sizeof(SDL_UDEV_CallbackList));
|
||||
if (item == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -538,8 +522,7 @@ SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
|
||||
void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
|
||||
{
|
||||
SDL_UDEV_CallbackList *item;
|
||||
SDL_UDEV_CallbackList *prev = NULL;
|
||||
@@ -578,8 +561,7 @@ SDL_UDEV_GetUdevSyms(void)
|
||||
return &_this->syms;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_UDEV_ReleaseUdevSyms(void)
|
||||
void SDL_UDEV_ReleaseUdevSyms(void)
|
||||
{
|
||||
SDL_UDEV_Quit();
|
||||
}
|
||||
|
||||
@@ -48,12 +48,14 @@ typedef enum
|
||||
|
||||
typedef void (*SDL_UDEV_Callback)(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath);
|
||||
|
||||
typedef struct SDL_UDEV_CallbackList {
|
||||
typedef struct SDL_UDEV_CallbackList
|
||||
{
|
||||
SDL_UDEV_Callback callback;
|
||||
struct SDL_UDEV_CallbackList *next;
|
||||
} SDL_UDEV_CallbackList;
|
||||
|
||||
typedef struct SDL_UDEV_Symbols {
|
||||
typedef struct SDL_UDEV_Symbols
|
||||
{
|
||||
const char *(*udev_device_get_action)(struct udev_device *);
|
||||
const char *(*udev_device_get_devnode)(struct udev_device *);
|
||||
const char *(*udev_device_get_subsystem)(struct udev_device *);
|
||||
@@ -78,8 +80,8 @@ typedef struct SDL_UDEV_Symbols {
|
||||
void (*udev_monitor_unref)(struct udev_monitor *);
|
||||
struct udev *(*udev_new)(void);
|
||||
void (*udev_unref)(struct udev *);
|
||||
struct udev_device * (*udev_device_new_from_devnum)(struct udev *udev, char type, dev_t devnum);
|
||||
dev_t (*udev_device_get_devnum) (struct udev_device *udev_device);
|
||||
struct udev_device *(*udev_device_new_from_devnum)(struct udev *udev, char type, dev_t devnum);
|
||||
dev_t (*udev_device_get_devnum)(struct udev_device *udev_device);
|
||||
} SDL_UDEV_Symbols;
|
||||
|
||||
typedef struct SDL_UDEV_PrivateData
|
||||
@@ -90,7 +92,7 @@ typedef struct SDL_UDEV_PrivateData
|
||||
struct udev_monitor *udev_mon;
|
||||
int ref_count;
|
||||
SDL_UDEV_CallbackList *first, *last;
|
||||
|
||||
|
||||
/* Function pointers */
|
||||
SDL_UDEV_Symbols syms;
|
||||
} SDL_UDEV_PrivateData;
|
||||
@@ -107,7 +109,6 @@ extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
|
||||
extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void);
|
||||
extern void SDL_UDEV_ReleaseUdevSyms(void);
|
||||
|
||||
|
||||
#endif /* HAVE_LIBUDEV_H && HAVE_LINUX_INPUT_H */
|
||||
|
||||
#endif /* SDL_udev_h_ */
|
||||
|
||||
Reference in New Issue
Block a user