@@ -192,121 +192,6 @@ static int X11Toolkit_SharedMemoryErrorHandler(Display *d, XErrorEvent *e)
192192 return g_old_error_handler (d , e );
193193}
194194
195- int X11Toolkit_SettingsGetInt (XSettingsClient * client , const char * key , int fallback_value ) {
196- XSettingsSetting * setting = NULL ;
197- int res = fallback_value ;
198-
199- if (client ) {
200- if (xsettings_client_get_setting (client , key , & setting ) != XSETTINGS_SUCCESS ) {
201- goto no_key ;
202- }
203-
204- if (setting -> type != XSETTINGS_TYPE_INT ) {
205- goto no_key ;
206- }
207-
208- res = setting -> data .v_int ;
209- }
210-
211- no_key :
212- if (setting ) {
213- xsettings_setting_free (setting );
214- }
215-
216- return res ;
217- }
218-
219- static float X11Toolkit_GetUIScale (XSettingsClient * client , Display * display )
220- {
221- double scale_factor = 0.0 ;
222-
223- // First use the forced scaling factor specified by the app/user
224- const char * hint = SDL_GetHint (SDL_HINT_VIDEO_X11_SCALING_FACTOR );
225- if (hint && * hint ) {
226- double value = SDL_atof (hint );
227- if (value >= 1.0f && value <= 10.0f ) {
228- scale_factor = value ;
229- }
230- }
231-
232- // If that failed, try "Xft.dpi" from the XResourcesDatabase...
233- // We attempt to read this directly to get the live value, XResourceManagerString
234- // is cached per display connection.
235- if (scale_factor <= 0.0 ) {
236- int status , real_format ;
237- Atom real_type ;
238- Atom res_mgr ;
239- unsigned long items_read , items_left ;
240- char * resource_manager ;
241- bool owns_resource_manager = false;
242-
243- X11_XrmInitialize ();
244- res_mgr = X11_XInternAtom (display , "RESOURCE_MANAGER" , False );
245- status = X11_XGetWindowProperty (display , RootWindow (display , DefaultScreen (display )),
246- res_mgr , 0L , 8192L , False , XA_STRING ,
247- & real_type , & real_format , & items_read , & items_left ,
248- (unsigned char * * )& resource_manager );
249-
250- if (status == Success && resource_manager ) {
251- owns_resource_manager = true;
252- } else {
253- // Fall back to XResourceManagerString. This will not be updated if the
254- // dpi value is later changed but should allow getting the initial value.
255- resource_manager = X11_XResourceManagerString (display );
256- }
257-
258- if (resource_manager ) {
259- XrmDatabase db ;
260- XrmValue value ;
261- char * type ;
262-
263- db = X11_XrmGetStringDatabase (resource_manager );
264-
265- // Get the value of Xft.dpi from the Database
266- if (X11_XrmGetResource (db , "Xft.dpi" , "String" , & type , & value )) {
267- if (value .addr && type && SDL_strcmp (type , "String" ) == 0 ) {
268- int dpi = SDL_atoi (value .addr );
269- scale_factor = dpi / 96.0 ;
270- }
271- }
272- X11_XrmDestroyDatabase (db );
273-
274- if (owns_resource_manager ) {
275- X11_XFree (resource_manager );
276- }
277- }
278- }
279-
280- // If that failed, try the XSETTINGS keys...
281- if (scale_factor <= 0.0 ) {
282- scale_factor = X11Toolkit_SettingsGetInt (client , "Gdk/WindowScalingFactor" , -1 );
283-
284- // The Xft/DPI key is stored in increments of 1024th
285- if (scale_factor <= 0.0 ) {
286- int dpi = X11Toolkit_SettingsGetInt (client , "Xft/DPI" , -1 );
287- if (dpi > 0 ) {
288- scale_factor = (double ) dpi / 1024.0 ;
289- scale_factor /= 96.0 ;
290- }
291- }
292- }
293-
294- // If that failed, try the GDK_SCALE envvar...
295- if (scale_factor <= 0.0 ) {
296- const char * scale_str = SDL_getenv ("GDK_SCALE" );
297- if (scale_str ) {
298- scale_factor = SDL_atoi (scale_str );
299- }
300- }
301-
302- // Nothing or a bad value, just fall back to 1.0
303- if (scale_factor <= 0.0 ) {
304- scale_factor = 1.0 ;
305- }
306-
307- return (float )scale_factor ;
308- }
309-
310195static void X11Toolkit_InitWindowPixmap (SDL_ToolkitWindowX11 * data ) {
311196 if (data -> pixmap ) {
312197#ifndef NO_SHARED_MEMORY
@@ -467,8 +352,11 @@ static void X11Toolkit_SettingsNotify(const char *name, XSettingsAction action,
467352 }
468353
469354 /* set scale vars */
470- window -> scale = X11Toolkit_GetUIScale (window -> xsettings , window -> display );
355+ window -> scale = X11_GetGlobalContentScale (window -> display , window -> xsettings );
471356 window -> iscale = (int )SDL_ceilf (window -> scale );
357+ if (window -> scale < 1 ) {
358+ window -> scale = 1 ;
359+ }
472360 if (SDL_roundf (window -> scale ) == window -> scale ) {
473361 window -> scale = 0 ;
474362 }
@@ -728,7 +616,10 @@ SDL_ToolkitWindowX11 *X11Toolkit_CreateWindowStruct(SDL_Window *parent, SDL_Tool
728616 window -> xsettings_first_time = true;
729617 window -> xsettings = xsettings_client_new (window -> display , DefaultScreen (window -> display ), X11Toolkit_SettingsNotify , NULL , window );
730618 window -> xsettings_first_time = false;
731- window -> scale = X11Toolkit_GetUIScale (window -> xsettings , window -> display );
619+ window -> scale = X11_GetGlobalContentScale (window -> display , window -> xsettings );
620+ if (window -> scale < 1 ) {
621+ window -> scale = 1 ;
622+ }
732623 window -> iscale = (int )SDL_ceilf (window -> scale );
733624 if (SDL_roundf (window -> scale ) == window -> scale ) {
734625 window -> scale = 0 ;
0 commit comments