Query XSETTINGS for the content scale factor
For GTK-based systems using XSETTINGS it's much more likely to be available, rather than the "GDK_SCALE" environment variable, which is a debugging tool according to the GTK documentation.
This commit is contained in:
parent
61dafb3b2f
commit
e049098733
@ -23,6 +23,7 @@
|
||||
#ifdef SDL_VIDEO_DRIVER_X11
|
||||
|
||||
#include "SDL_x11video.h"
|
||||
#include "SDL_x11settings.h"
|
||||
#include "edid.h"
|
||||
|
||||
/* #define X11MODES_DEBUG */
|
||||
@ -230,9 +231,13 @@ static float GetGlobalContentScale(SDL_VideoDevice *_this)
|
||||
}
|
||||
}
|
||||
|
||||
/* If that failed, try the XSETTINGS key... */
|
||||
if (scale_factor <= 0.0) {
|
||||
scale_factor = X11_GetXsettingsIntKey(_this, "Gdk/WindowScalingFactor", -1);
|
||||
}
|
||||
|
||||
/* If that failed, try the GDK_SCALE envvar... */
|
||||
if (scale_factor <= 0.0)
|
||||
{
|
||||
if (scale_factor <= 0.0) {
|
||||
const char *scale_str = SDL_getenv("GDK_SCALE");
|
||||
if (scale_str) {
|
||||
scale_factor = SDL_atoi(scale_str);
|
||||
|
@ -94,4 +94,31 @@ void X11_HandleXsettings(SDL_VideoDevice *_this, const XEvent *xevent)
|
||||
}
|
||||
}
|
||||
|
||||
int X11_GetXsettingsIntKey(SDL_VideoDevice *_this, const char *key, int fallback_value) {
|
||||
SDL_VideoData *data = _this->driverdata;
|
||||
SDLX11_SettingsData *xsettings_data = &data->xsettings_data;
|
||||
XSettingsSetting *setting = NULL;
|
||||
int res = fallback_value;
|
||||
|
||||
|
||||
if (xsettings_data->xsettings) {
|
||||
if (xsettings_client_get_setting(xsettings_data->xsettings, key, &setting) != XSETTINGS_SUCCESS) {
|
||||
goto no_key;
|
||||
}
|
||||
|
||||
if (setting->type != XSETTINGS_TYPE_INT) {
|
||||
goto no_key;
|
||||
}
|
||||
|
||||
res = setting->data.v_int;
|
||||
}
|
||||
|
||||
no_key:
|
||||
if (setting) {
|
||||
xsettings_setting_free(setting);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_X11 */
|
||||
|
@ -34,5 +34,6 @@ typedef struct X11_SettingsData {
|
||||
extern void X11_InitXsettings(SDL_VideoDevice *_this);
|
||||
extern void X11_QuitXsettings(SDL_VideoDevice *_this);
|
||||
extern void X11_HandleXsettings(SDL_VideoDevice *_this, const XEvent *xevent);
|
||||
extern int X11_GetXsettingsIntKey(SDL_VideoDevice *_this, const char *key, int fallback_value);
|
||||
|
||||
#endif /* SDL_x11settings_h_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user