update SDL3 to 3.1.6.

This commit is contained in:
Sasha Szpakowski
2024-11-16 00:44:49 -04:00
parent aecb572558
commit 8c4c8655aa
231 changed files with 16035 additions and 3495 deletions
+49 -144
View File
@@ -46,126 +46,6 @@
*/
// #define XRANDR_DISABLED_BY_DEFAULT
#ifdef SDL_USE_LIBDBUS
#define SCALE_FACTOR_NODE "org.freedesktop.portal.Desktop"
#define SCALE_FACTOR_PATH "/org/freedesktop/portal/desktop"
#define SCALE_FACTOR_INTERFACE "org.freedesktop.portal.Settings"
#define SCALE_FACTOR_NAMESPACE "org.gnome.desktop.interface"
#define SCALE_FACTOR_SIGNAL_NAME "SettingChanged"
#define SCALE_FACTOR_KEY "text-scaling-factor"
static DBusMessage *ReadDBusSetting(SDL_DBusContext *dbus, const char *key)
{
static const char *iface = SCALE_FACTOR_NAMESPACE;
DBusMessage *reply = NULL;
DBusMessage *msg = dbus->message_new_method_call(SCALE_FACTOR_NODE,
SCALE_FACTOR_PATH,
SCALE_FACTOR_INTERFACE,
"Read"); // Method
if (msg) {
if (dbus->message_append_args(msg, DBUS_TYPE_STRING, &iface, DBUS_TYPE_STRING, &key, DBUS_TYPE_INVALID)) {
reply = dbus->connection_send_with_reply_and_block(dbus->session_conn, msg, DBUS_TIMEOUT_USE_DEFAULT, NULL);
}
dbus->message_unref(msg);
}
return reply;
}
static bool ParseDBusReply(SDL_DBusContext *dbus, DBusMessage *reply, int type, void *value)
{
DBusMessageIter iter[3];
dbus->message_iter_init(reply, &iter[0]);
if (dbus->message_iter_get_arg_type(&iter[0]) != DBUS_TYPE_VARIANT) {
return false;
}
dbus->message_iter_recurse(&iter[0], &iter[1]);
if (dbus->message_iter_get_arg_type(&iter[1]) != DBUS_TYPE_VARIANT) {
return false;
}
dbus->message_iter_recurse(&iter[1], &iter[2]);
if (dbus->message_iter_get_arg_type(&iter[2]) != type) {
return false;
}
dbus->message_iter_get_basic(&iter[2], value);
return true;
}
static void UpdateDisplayContentScale(float scale)
{
SDL_VideoDevice *viddevice = SDL_GetVideoDevice();
int i;
if (viddevice) {
for (i = 0; i < viddevice->num_displays; ++i) {
SDL_SetDisplayContentScale(viddevice->displays[i], scale);
}
}
}
static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *data)
{
SDL_DBusContext *dbus = SDL_DBus_GetContext();
double *scale_factor = (double *)data;
double new_scale = 0.0;
if (dbus->message_is_signal(msg, SCALE_FACTOR_INTERFACE, SCALE_FACTOR_SIGNAL_NAME)) {
DBusMessageIter signal_iter, variant_iter;
const char *namespace, *key;
dbus->message_iter_init(msg, &signal_iter);
// Check if the parameters are what we expect
if (dbus->message_iter_get_arg_type(&signal_iter) != DBUS_TYPE_STRING) {
goto not_our_signal;
}
dbus->message_iter_get_basic(&signal_iter, &namespace);
if (SDL_strcmp(SCALE_FACTOR_NAMESPACE, namespace) != 0) {
goto not_our_signal;
}
if (!dbus->message_iter_next(&signal_iter)) {
goto not_our_signal;
}
if (dbus->message_iter_get_arg_type(&signal_iter) != DBUS_TYPE_STRING) {
goto not_our_signal;
}
dbus->message_iter_get_basic(&signal_iter, &key);
if (SDL_strcmp(SCALE_FACTOR_KEY, key) != 0) {
goto not_our_signal;
}
if (!dbus->message_iter_next(&signal_iter)) {
goto not_our_signal;
}
if (dbus->message_iter_get_arg_type(&signal_iter) != DBUS_TYPE_VARIANT) {
goto not_our_signal;
}
dbus->message_iter_recurse(&signal_iter, &variant_iter);
if (dbus->message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_DOUBLE) {
goto not_our_signal;
}
dbus->message_iter_get_basic(&variant_iter, &new_scale);
if (new_scale > 0.0) {
*scale_factor = new_scale;
UpdateDisplayContentScale((float)new_scale);
}
return DBUS_HANDLER_RESULT_HANDLED;
}
not_our_signal:
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
#endif
static float GetGlobalContentScale(SDL_VideoDevice *_this)
{
static double scale_factor = 0.0;
@@ -181,30 +61,6 @@ static float GetGlobalContentScale(SDL_VideoDevice *_this)
}
}
// Next try the settings portal via D-Bus for the text scaling factor (aka 'Global Scale' on KDE)
#ifdef SDL_USE_LIBDBUS
if (scale_factor <= 0.0)
{
DBusMessage *reply;
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if (dbus) {
if ((reply = ReadDBusSetting(dbus, SCALE_FACTOR_KEY))) {
if (ParseDBusReply(dbus, reply, DBUS_TYPE_DOUBLE, &scale_factor)) {
// If the setting exists, register a listener for scale changes.
dbus->bus_add_match(dbus->session_conn,
"type='signal', interface='"SCALE_FACTOR_INTERFACE"',"
"member='"SCALE_FACTOR_SIGNAL_NAME"', arg0='"SCALE_FACTOR_NAMESPACE"',"
"arg1='"SCALE_FACTOR_KEY"'", NULL);
dbus->connection_add_filter(dbus->session_conn, &DBus_MessageFilter, &scale_factor, NULL);
dbus->connection_flush(dbus->session_conn);
}
dbus->message_unref(reply);
}
}
}
#endif
// If that failed, try "Xft.dpi" from the XResourcesDatabase...
if (scale_factor <= 0.0)
{
@@ -623,6 +479,7 @@ static bool X11_FillXRandRDisplayInfo(SDL_VideoDevice *_this, Display *dpy, int
displaydata->y = display_y;
displaydata->use_xrandr = true;
displaydata->xrandr_output = outputid;
SDL_strlcpy(displaydata->connector_name, display_name, sizeof(displaydata->connector_name));
SetXRandRModeInfo(dpy, res, output_crtc, modeID, &mode);
SetXRandRDisplayName(dpy, EDID, display_name, display_name_size, outputid, display_mm_width, display_mm_height);
@@ -751,6 +608,52 @@ void X11_HandleXRandREvent(SDL_VideoDevice *_this, const XEvent *xevent)
}
}
static void X11_SortOutputsByPriorityHint(SDL_VideoDevice *_this)
{
const char *name_hint = SDL_GetHint(SDL_HINT_VIDEO_DISPLAY_PRIORITY);
if (name_hint) {
char *saveptr;
char *str = SDL_strdup(name_hint);
SDL_VideoDisplay **sorted_list = SDL_malloc(sizeof(SDL_VideoDisplay *) * _this->num_displays);
if (str && sorted_list) {
int sorted_index = 0;
// Sort the requested displays to the front of the list.
const char *token = SDL_strtok_r(str, ",", &saveptr);
while (token) {
for (int i = 0; i < _this->num_displays; ++i) {
SDL_VideoDisplay *d = _this->displays[i];
if (d) {
SDL_DisplayData *data = d->internal;
if (SDL_strcmp(token, data->connector_name) == 0) {
sorted_list[sorted_index++] = d;
_this->displays[i] = NULL;
break;
}
}
}
token = SDL_strtok_r(NULL, ",", &saveptr);
}
// Append the remaining displays to the end of the list.
for (int i = 0; i < _this->num_displays; ++i) {
if (_this->displays[i]) {
sorted_list[sorted_index++] = _this->displays[i];
}
}
// Copy the sorted list back to the display list.
SDL_memcpy(_this->displays, sorted_list, sizeof(SDL_VideoDisplay *) * _this->num_displays);
}
SDL_free(str);
SDL_free(sorted_list);
}
}
static bool X11_InitModes_XRandR(SDL_VideoDevice *_this)
{
SDL_VideoData *data = _this->internal;
@@ -810,6 +713,8 @@ static bool X11_InitModes_XRandR(SDL_VideoDevice *_this)
return SDL_SetError("No available displays");
}
X11_SortOutputsByPriorityHint(_this);
return true;
}
#endif // SDL_VIDEO_DRIVER_X11_XRANDR