x11: Remove text-scaling-factor setting checks

The text-scaling-factor setting is not useful, now that we watch the
Xft/DPI and Gdk/WindowScalingFactor XSETTINGS keys; on the contrary, it
is problematic in mixed environments with both the KDE and GNOME
portals, as they end up stepping on each other's toes, and we end up
with the wrong scaling factor value.

Fixes: https://github.com/libsdl-org/SDL/issues/11142
This commit is contained in:
Emmanuele Bassi
2024-10-17 17:23:37 +01:00
committed by Sam Lantinga
parent 1c51b8dc33
commit 8119568805

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)
{