Skip to content

Commit 1464644

Browse files
author
Semphris
committed
System preferences
1 parent b8036bd commit 1464644

13 files changed

+703
-0
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,7 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
17081708
sdl_sources(
17091709
"${SDL3_SOURCE_DIR}/src/core/linux/SDL_dbus.c"
17101710
"${SDL3_SOURCE_DIR}/src/core/linux/SDL_system_theme.c"
1711+
"${SDL3_SOURCE_DIR}/src/core/linux/SDL_system_preferences.c"
17111712
)
17121713
endif()
17131714

include/SDL3/SDL_events.h

+20
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ typedef enum SDL_EventType
118118

119119
SDL_EVENT_SYSTEM_THEME_CHANGED, /**< The system theme changed */
120120

121+
SDL_EVENT_SYSTEM_PREFERENCE_CHANGED, /**< A system preference setting changed */
122+
SDL_EVENT_SYSTEM_TEXT_SCALE_CHANGED, /**< The text scale changed */
123+
SDL_EVENT_SYSTEM_CURSOR_SCALE_CHANGED, /**< The cursor scale changed */
124+
SDL_EVENT_SYSTEM_ACCENT_COLOR_CHANGED, /**< The accent color changed */
125+
121126
/* Display events */
122127
/* 0x150 was SDL_DISPLAYEVENT, reserve the number for sdl2-compat */
123128
SDL_EVENT_DISPLAY_ORIENTATION = 0x151, /**< Display orientation has changed to data1 */
@@ -924,6 +929,20 @@ typedef struct SDL_ClipboardEvent
924929
const char **mime_types; /**< current mime types */
925930
} SDL_ClipboardEvent;
926931

932+
/**
933+
* An event triggered when the clipboard contents have changed
934+
* (event.clipboard.*)
935+
*
936+
* \since This struct is available since SDL 3.1.3.
937+
*/
938+
typedef struct SDL_PreferenceEvent
939+
{
940+
SDL_EventType type; /**< SDL_EVENT_SYSTEM_PREFERENCE_CHANGED */
941+
Uint32 reserved;
942+
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
943+
SDL_SystemPreference pref; /**< The preference setting that changed */
944+
} SDL_PreferenceEvent;
945+
927946
/**
928947
* Sensor event structure (event.sensor.*)
929948
*
@@ -1022,6 +1041,7 @@ typedef union SDL_Event
10221041
SDL_RenderEvent render; /**< Render event data */
10231042
SDL_DropEvent drop; /**< Drag and drop event data */
10241043
SDL_ClipboardEvent clipboard; /**< Clipboard event data */
1044+
SDL_PreferenceEvent pref; /**< Clipboard event data */
10251045

10261046
/* This is necessary for ABI compatibility between Visual C++ and GCC.
10271047
Visual C++ will respect the push pack pragma and use 52 bytes (size of

include/SDL3/SDL_video.h

+80
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,86 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentVideoDriver(void);
570570
*/
571571
extern SDL_DECLSPEC SDL_SystemTheme SDLCALL SDL_GetSystemTheme(void);
572572

573+
/**
574+
* An enumeration of various boolean system preferences.
575+
*
576+
* Some systems provide a variety of accessibility options that allow users to
577+
* adapt their environment to various conditions.
578+
*
579+
* \since This enum is available since SDL 3.2.0.
580+
*
581+
* \sa SDL_GetSystemPreference
582+
*/
583+
typedef enum SDL_SystemPreference
584+
{
585+
SDL_SYSTEM_PREFERENCE_REDUCED_MOTION, /**< Disable smooth graphical transitions */
586+
SDL_SYSTEM_PREFERENCE_REDUCED_TRANSPARENCY, /**< Reduce usage of semi-transparent objects */
587+
SDL_SYSTEM_PREFERENCE_HIGH_CONTRAST, /**< Use extreme color differences between different elements of the interface */
588+
SDL_SYSTEM_PREFERENCE_COLORBLIND, /**< Add shape-based distinction between color-coded elements, for example "0" and "1" on switches */
589+
SDL_SYSTEM_PREFERENCE_PERSIST_SCROLLBARS, /**< Always show scrollbars, don't hide them after a few seconds of inactivity */
590+
SDL_SYSTEM_PREFERENCE_SCREEN_READER, /**< A screen reader is currently active */
591+
} SDL_SystemPreference;
592+
593+
/**
594+
* Get whether or not a certain system preference was enabled by the user.
595+
*
596+
* \param preference the preference to be fetched.
597+
* \returns true if the user enabled the system preference; false if the user
598+
* disabled that setting, or the setting doesn't exist, or an error
599+
* occured.
600+
*
601+
* \threadsafety This function should only be called on the main thread.
602+
*
603+
* \since This function is available since SDL 3.2.0.
604+
*
605+
* \sa SDL_SystemPreference
606+
*/
607+
extern SDL_DECLSPEC bool SDLCALL SDL_GetSystemPreference(SDL_SystemPreference preference);
608+
609+
/**
610+
* Get the system's accent color, as chosen by the user.
611+
*
612+
* If the current system does not have an accent color, false is returned and
613+
* the struct is unaffected.
614+
*
615+
* \param color a pointer to a struct to be filled with the color info. The
616+
* alpha channel is what the operating system returned and may or
617+
* may not be opaque.
618+
* \returns true on success or false on failure; call SDL_GetError() for more
619+
* information.
620+
*
621+
* \threadsafety This function should only be called on the main thread.
622+
*
623+
* \since This function is available since SDL 3.2.0.
624+
*/
625+
extern SDL_DECLSPEC bool SDLCALL SDL_GetSystemAccentColor(SDL_Color *color);
626+
627+
/**
628+
* Get the scale factor for text, as set by the user for their system.
629+
*
630+
* If the system does not have a setting to scale the font, 1 is returned.
631+
*
632+
* \returns the preferred scale for text; a scale of 1 means no scaling.
633+
*
634+
* \threadsafety This function should only be called on the main thread.
635+
*
636+
* \since This function is available since SDL 3.2.0.
637+
*/
638+
extern SDL_DECLSPEC float SDLCALL SDL_GetSystemTextScale(void);
639+
640+
/**
641+
* Get the scale factor for the cursor, as set by the user for their system.
642+
*
643+
* If the system does not have a setting to scale the cursor, 1 is returned.
644+
*
645+
* \returns the preferred scale for the cursor; a scale of 1 means no scaling.
646+
*
647+
* \threadsafety This function should only be called on the main thread.
648+
*
649+
* \since This function is available since SDL 3.2.0.
650+
*/
651+
extern SDL_DECLSPEC float SDLCALL SDL_GetSystemCursorScale(void);
652+
573653
/**
574654
* Get a list of currently connected displays.
575655
*

0 commit comments

Comments
 (0)