mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-12-16 11:54:21 +08:00
Add XSETTINGS support to x11 driver
Import the XSettingsClient implementation to handle the settings selection. Currently, we only care about the Gdk/WindowScalingFactor value used by the windowing system to notify us of display-wide changes in the scaling factor.
This commit is contained in:
committed by
Sam Lantinga
parent
d6da494c1c
commit
61dafb3b2f
@@ -104,7 +104,10 @@ function(get_clang_tidy_ignored_files OUTVAR)
|
||||
"hid.m"
|
||||
"hidraw.cpp"
|
||||
"hidusb.cpp"
|
||||
"hidapi.h")
|
||||
"hidapi.h"
|
||||
# XSETTINGS
|
||||
"xsettings-client.c"
|
||||
"xsettings-client.h")
|
||||
|
||||
foreach(SOURCE_FILE ${3RD_PARTY_SOURCES})
|
||||
list(APPEND IGNORED_LIST "{\"name\":\"${SOURCE_FILE}\",\"lines\":[[1,1]]}")
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "SDL_x11touch.h"
|
||||
#include "SDL_x11xinput2.h"
|
||||
#include "SDL_x11xfixes.h"
|
||||
#include "SDL_x11settings.h"
|
||||
#include "../SDL_clipboard_c.h"
|
||||
#include "../../core/unix/SDL_poll.h"
|
||||
#include "../../events/SDL_events_c.h"
|
||||
@@ -779,6 +780,16 @@ static void X11_HandleClipboardEvent(SDL_VideoDevice *_this, const XEvent *xeven
|
||||
}
|
||||
}
|
||||
|
||||
static void X11_HandleSettingsEvent(SDL_VideoDevice *_this, const XEvent *xevent)
|
||||
{
|
||||
SDL_VideoData *videodata = _this->driverdata;
|
||||
|
||||
SDL_assert(videodata->xsettings_window != None);
|
||||
SDL_assert(xevent->xany.window == videodata->xsettings_window);
|
||||
|
||||
X11_HandleXsettings(_this, xevent);
|
||||
}
|
||||
|
||||
static Bool isMapNotify(Display *display, XEvent *ev, XPointer arg)
|
||||
{
|
||||
XUnmapEvent *unmap;
|
||||
@@ -1103,6 +1114,12 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent)
|
||||
return;
|
||||
}
|
||||
|
||||
if ((videodata->xsettings_window != None) &&
|
||||
(videodata->xsettings_window == xevent->xany.window)) {
|
||||
X11_HandleSettingsEvent(_this, xevent);
|
||||
return;
|
||||
}
|
||||
|
||||
data = X11_FindWindow(_this, xevent->xany.window);
|
||||
|
||||
if (!data) {
|
||||
|
||||
97
src/video/x11/SDL_x11settings.c
Normal file
97
src/video/x11/SDL_x11settings.c
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright 2024 Igalia S.L.
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "SDL_internal.h"
|
||||
|
||||
#if defined(SDL_VIDEO_DRIVER_X11)
|
||||
|
||||
#include "SDL_x11video.h"
|
||||
#include "SDL_x11settings.h"
|
||||
|
||||
#define SDL_XSETTINGS_GDK_WINDOW_SCALING_FACTOR "Gdk/WindowScalingFactor"
|
||||
|
||||
static void X11_XsettingsNotify(const char *name, XSettingsAction action, XSettingsSetting *setting, void *data)
|
||||
{
|
||||
SDL_VideoDevice *_this = data;
|
||||
float scale_factor = 1.0;
|
||||
int i;
|
||||
|
||||
if (SDL_strcmp(name, SDL_XSETTINGS_GDK_WINDOW_SCALING_FACTOR) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (setting->type != XSETTINGS_TYPE_INT) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case XSETTINGS_ACTION_NEW:
|
||||
SDL_FALLTHROUGH;
|
||||
case XSETTINGS_ACTION_CHANGED:
|
||||
scale_factor = setting->data.v_int;
|
||||
break;
|
||||
case XSETTINGS_ACTION_DELETED:
|
||||
scale_factor = 1.0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (_this) {
|
||||
for (i = 0; i < _this->num_displays; ++i) {
|
||||
SDL_SetDisplayContentScale(_this->displays[i], scale_factor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void X11_InitXsettings(SDL_VideoDevice *_this)
|
||||
{
|
||||
SDL_VideoData *data = _this->driverdata;
|
||||
SDLX11_SettingsData *xsettings_data = &data->xsettings_data;
|
||||
|
||||
xsettings_data->xsettings = xsettings_client_new(data->display,
|
||||
DefaultScreen(data->display), X11_XsettingsNotify, NULL, _this);
|
||||
|
||||
}
|
||||
|
||||
void X11_QuitXsettings(SDL_VideoDevice *_this)
|
||||
{
|
||||
SDL_VideoData *data = _this->driverdata;
|
||||
SDLX11_SettingsData *xsettings_data = &data->xsettings_data;
|
||||
|
||||
if (xsettings_data->xsettings) {
|
||||
xsettings_client_destroy(xsettings_data->xsettings);
|
||||
xsettings_data->xsettings = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void X11_HandleXsettings(SDL_VideoDevice *_this, const XEvent *xevent)
|
||||
{
|
||||
SDL_VideoData *data = _this->driverdata;
|
||||
SDLX11_SettingsData *xsettings_data = &data->xsettings_data;
|
||||
|
||||
if (xsettings_data->xsettings) {
|
||||
if (!xsettings_client_process_event(xsettings_data->xsettings, xevent)) {
|
||||
xsettings_client_destroy(xsettings_data->xsettings);
|
||||
xsettings_data->xsettings = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_X11 */
|
||||
38
src/video/x11/SDL_x11settings.h
Normal file
38
src/video/x11/SDL_x11settings.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright 2024 Igalia S.L.
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "SDL_internal.h"
|
||||
|
||||
#ifndef SDL_x11settings_h_
|
||||
#define SDL_x11settings_h_
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include "xsettings-client.h"
|
||||
|
||||
typedef struct X11_SettingsData {
|
||||
XSettingsClient *xsettings;
|
||||
} SDLX11_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);
|
||||
|
||||
#endif /* SDL_x11settings_h_ */
|
||||
@@ -443,6 +443,8 @@ int X11_VideoInit(SDL_VideoDevice *_this)
|
||||
X11_InitXfixes(_this);
|
||||
#endif /* SDL_VIDEO_DRIVER_X11_XFIXES */
|
||||
|
||||
X11_InitXsettings(_this);
|
||||
|
||||
#ifndef X_HAVE_UTF8_STRING
|
||||
#warning X server does not support UTF8_STRING, a feature introduced in 2000! This is likely to become a hard error in a future libSDL3.
|
||||
#endif
|
||||
@@ -469,6 +471,10 @@ void X11_VideoQuit(SDL_VideoDevice *_this)
|
||||
X11_XDestroyWindow(data->display, data->clipboard_window);
|
||||
}
|
||||
|
||||
if (data->xsettings_window) {
|
||||
X11_XDestroyWindow(data->display, data->xsettings_window);
|
||||
}
|
||||
|
||||
#ifdef X_HAVE_UTF8_STRING
|
||||
if (data->im) {
|
||||
X11_XCloseIM(data->im);
|
||||
@@ -480,6 +486,7 @@ void X11_VideoQuit(SDL_VideoDevice *_this)
|
||||
X11_QuitMouse(_this);
|
||||
X11_QuitTouch(_this);
|
||||
X11_QuitClipboard(_this);
|
||||
X11_QuitXsettings(_this);
|
||||
}
|
||||
|
||||
SDL_bool X11_UseDirectColorVisuals(void)
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "SDL_x11modes.h"
|
||||
#include "SDL_x11mouse.h"
|
||||
#include "SDL_x11opengl.h"
|
||||
#include "SDL_x11settings.h"
|
||||
#include "SDL_x11window.h"
|
||||
#include "SDL_x11vulkan.h"
|
||||
|
||||
@@ -58,6 +59,8 @@ struct SDL_VideoData
|
||||
#ifdef SDL_VIDEO_DRIVER_X11_XFIXES
|
||||
SDL_Window *active_cursor_confined_window;
|
||||
#endif /* SDL_VIDEO_DRIVER_X11_XFIXES */
|
||||
Window xsettings_window;
|
||||
SDLX11_SettingsData xsettings_data;
|
||||
|
||||
/* This is true for ICCCM2.0-compliant window managers */
|
||||
SDL_bool net_wm;
|
||||
|
||||
855
src/video/x11/xsettings-client.c
Normal file
855
src/video/x11/xsettings-client.c
Normal file
File diff suppressed because it is too large
Load Diff
153
src/video/x11/xsettings-client.h
Normal file
153
src/video/x11/xsettings-client.h
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright © 2001, 2007 Red Hat, Inc.
|
||||
* Copyright 2024 Igalia S.L.
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of Red Hat not be used in advertising or
|
||||
* publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. Red Hat makes no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*
|
||||
* RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
|
||||
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* Author: Owen Taylor, Red Hat, Inc.
|
||||
*/
|
||||
#ifndef XSETTINGS_CLIENT_H
|
||||
#define XSETTINGS_CLIENT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct _XSettingsBuffer XSettingsBuffer;
|
||||
typedef struct _XSettingsColor XSettingsColor;
|
||||
typedef struct _XSettingsList XSettingsList;
|
||||
typedef struct _XSettingsSetting XSettingsSetting;
|
||||
|
||||
/* Types of settings possible. Enum values correspond to
|
||||
* protocol values.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
XSETTINGS_TYPE_INT = 0,
|
||||
XSETTINGS_TYPE_STRING = 1,
|
||||
XSETTINGS_TYPE_COLOR = 2
|
||||
} XSettingsType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
XSETTINGS_SUCCESS,
|
||||
XSETTINGS_NO_MEM,
|
||||
XSETTINGS_ACCESS,
|
||||
XSETTINGS_FAILED,
|
||||
XSETTINGS_NO_ENTRY,
|
||||
XSETTINGS_DUPLICATE_ENTRY
|
||||
} XSettingsResult;
|
||||
|
||||
struct _XSettingsBuffer
|
||||
{
|
||||
char byte_order;
|
||||
size_t len;
|
||||
unsigned char *data;
|
||||
unsigned char *pos;
|
||||
};
|
||||
|
||||
struct _XSettingsColor
|
||||
{
|
||||
unsigned short red, green, blue, alpha;
|
||||
};
|
||||
|
||||
struct _XSettingsList
|
||||
{
|
||||
XSettingsSetting *setting;
|
||||
XSettingsList *next;
|
||||
};
|
||||
|
||||
struct _XSettingsSetting
|
||||
{
|
||||
char *name;
|
||||
XSettingsType type;
|
||||
|
||||
union {
|
||||
int v_int;
|
||||
char *v_string;
|
||||
XSettingsColor v_color;
|
||||
} data;
|
||||
|
||||
unsigned long last_change_serial;
|
||||
};
|
||||
|
||||
XSettingsSetting *xsettings_setting_copy (XSettingsSetting *setting);
|
||||
void xsettings_setting_free (XSettingsSetting *setting);
|
||||
int xsettings_setting_equal (XSettingsSetting *setting_a,
|
||||
XSettingsSetting *setting_b);
|
||||
|
||||
void xsettings_list_free (XSettingsList *list);
|
||||
XSettingsList *xsettings_list_copy (XSettingsList *list);
|
||||
XSettingsResult xsettings_list_insert (XSettingsList **list,
|
||||
XSettingsSetting *setting);
|
||||
XSettingsSetting *xsettings_list_lookup (XSettingsList *list,
|
||||
const char *name);
|
||||
XSettingsResult xsettings_list_delete (XSettingsList **list,
|
||||
const char *name);
|
||||
|
||||
char xsettings_byte_order (void);
|
||||
|
||||
#define XSETTINGS_PAD(n,m) ((n + m - 1) & (~(m-1)))
|
||||
|
||||
typedef struct _XSettingsClient XSettingsClient;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
XSETTINGS_ACTION_NEW,
|
||||
XSETTINGS_ACTION_CHANGED,
|
||||
XSETTINGS_ACTION_DELETED
|
||||
} XSettingsAction;
|
||||
|
||||
typedef void (*XSettingsNotifyFunc) (const char *name,
|
||||
XSettingsAction action,
|
||||
XSettingsSetting *setting,
|
||||
void *cb_data);
|
||||
typedef Bool (*XSettingsWatchFunc) (Window window,
|
||||
Bool is_start,
|
||||
long mask,
|
||||
void *cb_data);
|
||||
typedef void (*XSettingsGrabFunc) (Display *display);
|
||||
|
||||
XSettingsClient *xsettings_client_new (Display *display,
|
||||
int screen,
|
||||
XSettingsNotifyFunc notify,
|
||||
XSettingsWatchFunc watch,
|
||||
void *cb_data);
|
||||
XSettingsClient *xsettings_client_new_with_grab_funcs (Display *display,
|
||||
int screen,
|
||||
XSettingsNotifyFunc notify,
|
||||
XSettingsWatchFunc watch,
|
||||
void *cb_data,
|
||||
XSettingsGrabFunc grab,
|
||||
XSettingsGrabFunc ungrab);
|
||||
void xsettings_client_set_grab_func (XSettingsClient *client,
|
||||
XSettingsGrabFunc grab);
|
||||
void xsettings_client_set_ungrab_func (XSettingsClient *client,
|
||||
XSettingsGrabFunc ungrab);
|
||||
void xsettings_client_destroy (XSettingsClient *client);
|
||||
Bool xsettings_client_process_event (XSettingsClient *client,
|
||||
const XEvent *xev);
|
||||
XSettingsResult xsettings_client_get_setting (XSettingsClient *client,
|
||||
const char *name,
|
||||
XSettingsSetting **setting);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* XSETTINGS_CLIENT_H */
|
||||
Reference in New Issue
Block a user