Atlas - SDL_x11settings.c
Home / ext / SDL / src / video / x11 Lines: 1 | Size: 3389 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright 2024 Igalia S.L. 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22#include "SDL_internal.h" 23 24#if defined(SDL_VIDEO_DRIVER_X11) 25 26#include "SDL_x11video.h" 27#include "SDL_x11settings.h" 28 29static void UpdateContentScale(SDL_VideoDevice *_this) 30{ 31 if (_this) { 32 float scale_factor = X11_GetGlobalContentScaleForDevice(_this); 33 for (int i = 0; i < _this->num_displays; ++i) { 34 SDL_SetDisplayContentScale(_this->displays[i], scale_factor); 35 } 36 } 37} 38 39static void X11_XsettingsNotify(const char *name, XSettingsAction action, XSettingsSetting *setting, void *data) 40{ 41 SDL_VideoDevice *_this = data; 42 43 if (SDL_strcmp(name, SDL_XSETTINGS_GDK_WINDOW_SCALING_FACTOR) == 0 || 44 SDL_strcmp(name, SDL_XSETTINGS_GDK_UNSCALED_DPI) == 0 || 45 SDL_strcmp(name, SDL_XSETTINGS_XFT_DPI) == 0) { 46 UpdateContentScale(_this); 47 } 48} 49 50void X11_InitXsettings(SDL_VideoDevice *_this) 51{ 52 SDL_VideoData *data = _this->internal; 53 SDLX11_SettingsData *xsettings_data = &data->xsettings_data; 54 55 xsettings_data->xsettings = xsettings_client_new(data->display, 56 DefaultScreen(data->display), X11_XsettingsNotify, NULL, _this); 57} 58 59void X11_QuitXsettings(SDL_VideoDevice *_this) 60{ 61 SDL_VideoData *data = _this->internal; 62 SDLX11_SettingsData *xsettings_data = &data->xsettings_data; 63 64 if (xsettings_data->xsettings) { 65 xsettings_client_destroy(xsettings_data->xsettings); 66 xsettings_data->xsettings = NULL; 67 } 68} 69 70void X11_HandleXsettingsEvent(SDL_VideoDevice *_this, const XEvent *xevent) 71{ 72 SDL_VideoData *data = _this->internal; 73 SDLX11_SettingsData *xsettings_data = &data->xsettings_data; 74 75 if (xsettings_data->xsettings) { 76 xsettings_client_process_event(xsettings_data->xsettings, xevent); 77 } 78} 79 80int X11_GetXsettingsClientIntKey(XSettingsClient *client, const char *key, int fallback_value) { 81 XSettingsSetting *setting = NULL; 82 int res = fallback_value; 83 84 if (client) { 85 if (xsettings_client_get_setting(client, key, &setting) != XSETTINGS_SUCCESS) { 86 goto no_key; 87 } 88 89 if (setting->type != XSETTINGS_TYPE_INT) { 90 goto no_key; 91 } 92 93 res = setting->data.v_int; 94 } 95 96no_key: 97 if (setting) { 98 xsettings_setting_free(setting); 99 } 100 101 return res; 102} 103 104int X11_GetXsettingsIntKey(SDL_VideoDevice *_this, const char *key, int fallback_value) { 105 return X11_GetXsettingsClientIntKey(_this->internal->xsettings_data.xsettings, key, fallback_value); 106} 107 108#endif // SDL_VIDEO_DRIVER_X11 109[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.