Skip to content

Commit 2068401

Browse files
author
Semphris
committed
System preferences
1 parent 69d2802 commit 2068401

19 files changed

+1083
-7
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,7 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
17321732
sdl_sources(
17331733
"${SDL3_SOURCE_DIR}/src/core/linux/SDL_dbus.c"
17341734
"${SDL3_SOURCE_DIR}/src/core/linux/SDL_system_theme.c"
1735+
"${SDL3_SOURCE_DIR}/src/core/linux/SDL_system_preferences.c"
17351736
)
17361737
endif()
17371738

include/SDL3/SDL_events.h

+23
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 */
@@ -925,6 +930,23 @@ typedef struct SDL_ClipboardEvent
925930
const char **mime_types; /**< current mime types */
926931
} SDL_ClipboardEvent;
927932

933+
/**
934+
* An event triggered when a system preference has changed (event.pref.*)
935+
*
936+
* Note that some platforms may provide certain settings, but not allow
937+
* listening to changes; as such, there may be certain preferences that can be
938+
* fetched but that won't produce events when they are changed.
939+
*
940+
* \since This struct is available since SDL 3.4.0.
941+
*/
942+
typedef struct SDL_PreferenceEvent
943+
{
944+
SDL_EventType type; /**< SDL_EVENT_SYSTEM_PREFERENCE_CHANGED */
945+
Uint32 reserved;
946+
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
947+
SDL_SystemPreference pref; /**< The preference setting that changed */
948+
} SDL_PreferenceEvent;
949+
928950
/**
929951
* Sensor event structure (event.sensor.*)
930952
*
@@ -1023,6 +1045,7 @@ typedef union SDL_Event
10231045
SDL_RenderEvent render; /**< Render event data */
10241046
SDL_DropEvent drop; /**< Drag and drop event data */
10251047
SDL_ClipboardEvent clipboard; /**< Clipboard event data */
1048+
SDL_PreferenceEvent pref; /**< Preference event data */
10261049

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

include/SDL3/SDL_video.h

+107
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,113 @@ 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.4.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+
* This setting will emit a `SDL_EVENT_SYSTEM_PREFERENCE_CHANGED` when the user
597+
* updates the corresponding preference in their settings or accessibility app.
598+
* Note that some platforms may provide certain settings, but not allow
599+
* listening to changes; as such, there may be certain preferences that can be
600+
* fetched but that won't produce events when they are changed.
601+
*
602+
* \param preference the preference to be fetched.
603+
* \returns true if the user enabled the system preference; false if the user
604+
* disabled that setting, or the setting doesn't exist, or an error
605+
* occured.
606+
*
607+
* \threadsafety This function should only be called on the main thread.
608+
*
609+
* \since This function is available since SDL 3.4.0.
610+
*
611+
* \sa SDL_SystemPreference
612+
* \sa SDL_PreferenceEvent
613+
*/
614+
extern SDL_DECLSPEC bool SDLCALL SDL_GetSystemPreference(SDL_SystemPreference preference);
615+
616+
/**
617+
* Get the system's accent color, as chosen by the user.
618+
*
619+
* If the current system does not have an accent color, false is returned and
620+
* the struct is unaffected.
621+
*
622+
* This setting will emit a `SDL_EVENT_SYSTEM_ACCENT_COLOR_CHANGED` when the
623+
* user updates the corresponding preference in their settings or accessibility
624+
* app. Note that some platforms may provide certain settings, but not allow
625+
* listening to changes; as such, there may be certain preferences that can be
626+
* fetched but that won't produce events when they are changed.
627+
*
628+
* \param color a pointer to a struct to be filled with the color info. The
629+
* alpha channel is what the operating system returned and may or
630+
* may not be opaque.
631+
* \returns true on success or false on failure; call SDL_GetError() for more
632+
* information.
633+
*
634+
* \threadsafety This function should only be called on the main thread.
635+
*
636+
* \since This function is available since SDL 3.4.0.
637+
*/
638+
extern SDL_DECLSPEC bool SDLCALL SDL_GetSystemAccentColor(SDL_Color *color);
639+
640+
/**
641+
* Get the scale factor for text, as set by the user for their system. For
642+
* absolute scaling methods, this presumes a base size of 16 pixels.
643+
*
644+
* If the system does not have a setting to scale the font, 1 is returned.
645+
*
646+
* This setting will emit a `SDL_EVENT_SYSTEM_TEXT_SCALE_CHANGED` when the user
647+
* updates the corresponding preference in their settings or accessibility app.
648+
* Note that some platforms may provide certain settings, but not allow
649+
* listening to changes; as such, there may be certain preferences that can be
650+
* fetched but that won't produce events when they are changed.
651+
*
652+
* \returns the preferred scale for text; a scale of 1 means no scaling.
653+
*
654+
* \threadsafety This function should only be called on the main thread.
655+
*
656+
* \since This function is available since SDL 3.4.0.
657+
*/
658+
extern SDL_DECLSPEC float SDLCALL SDL_GetSystemTextScale(void);
659+
660+
/**
661+
* Get the scale factor for the cursor, as set by the user for their system. For
662+
* absolute scaling methods, this presumes a base size of 32 pixels.
663+
*
664+
* If the system does not have a setting to scale the cursor, 1 is returned.
665+
*
666+
* This setting will emit a `SDL_EVENT_SYSTEM_CURSOR_SCALE_CHANGED` when the
667+
* user updates the corresponding preference in their settings or accessibility
668+
* app. Note that some platforms may provide certain settings, but not allow
669+
* listening to changes; as such, there may be certain preferences that can be
670+
* fetched but that won't produce events when they are changed.
671+
*
672+
* \returns the preferred scale for the cursor; a scale of 1 means no scaling.
673+
*
674+
* \threadsafety This function should only be called on the main thread.
675+
*
676+
* \since This function is available since SDL 3.4.0.
677+
*/
678+
extern SDL_DECLSPEC float SDLCALL SDL_GetSystemCursorScale(void);
679+
573680
/**
574681
* Get a list of currently connected displays.
575682
*

0 commit comments

Comments
 (0)