Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions to fetch various system preferences and accessibility options #11720

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,7 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
sdl_sources(
"${SDL3_SOURCE_DIR}/src/core/linux/SDL_dbus.c"
"${SDL3_SOURCE_DIR}/src/core/linux/SDL_system_theme.c"
"${SDL3_SOURCE_DIR}/src/core/linux/SDL_system_preferences.c"
)
endif()

Expand Down
20 changes: 20 additions & 0 deletions include/SDL3/SDL_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ typedef enum SDL_EventType

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

SDL_EVENT_SYSTEM_PREFERENCE_CHANGED, /**< A system preference setting changed */
SDL_EVENT_SYSTEM_TEXT_SCALE_CHANGED, /**< The text scale changed */
SDL_EVENT_SYSTEM_CURSOR_SCALE_CHANGED, /**< The cursor scale changed */
SDL_EVENT_SYSTEM_ACCENT_COLOR_CHANGED, /**< The accent color changed */

/* Display events */
/* 0x150 was SDL_DISPLAYEVENT, reserve the number for sdl2-compat */
SDL_EVENT_DISPLAY_ORIENTATION = 0x151, /**< Display orientation has changed to data1 */
Expand Down Expand Up @@ -924,6 +929,20 @@ typedef struct SDL_ClipboardEvent
const char **mime_types; /**< current mime types */
} SDL_ClipboardEvent;

/**
* An event triggered when the clipboard contents have changed
* (event.clipboard.*)
*
* \since This struct is available since SDL 3.1.3.
*/
typedef struct SDL_PreferenceEvent
{
SDL_EventType type; /**< SDL_EVENT_SYSTEM_PREFERENCE_CHANGED */
Uint32 reserved;
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_SystemPreference pref; /**< The preference setting that changed */
} SDL_PreferenceEvent;

/**
* Sensor event structure (event.sensor.*)
*
Expand Down Expand Up @@ -1022,6 +1041,7 @@ typedef union SDL_Event
SDL_RenderEvent render; /**< Render event data */
SDL_DropEvent drop; /**< Drag and drop event data */
SDL_ClipboardEvent clipboard; /**< Clipboard event data */
SDL_PreferenceEvent pref; /**< Clipboard event data */

/* This is necessary for ABI compatibility between Visual C++ and GCC.
Visual C++ will respect the push pack pragma and use 52 bytes (size of
Expand Down
80 changes: 80 additions & 0 deletions include/SDL3/SDL_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,86 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentVideoDriver(void);
*/
extern SDL_DECLSPEC SDL_SystemTheme SDLCALL SDL_GetSystemTheme(void);

/**
* An enumeration of various boolean system preferences.
*
* Some systems provide a variety of accessibility options that allow users to
* adapt their environment to various conditions.
*
* \since This enum is available since SDL 3.2.0.
*
* \sa SDL_GetSystemPreference
*/
typedef enum SDL_SystemPreference
{
SDL_SYSTEM_PREFERENCE_REDUCED_MOTION, /**< Disable smooth graphical transitions */
SDL_SYSTEM_PREFERENCE_REDUCED_TRANSPARENCY, /**< Reduce usage of semi-transparent objects */
SDL_SYSTEM_PREFERENCE_HIGH_CONTRAST, /**< Use extreme color differences between different elements of the interface */
SDL_SYSTEM_PREFERENCE_COLORBLIND, /**< Add shape-based distinction between color-coded elements, for example "0" and "1" on switches */
SDL_SYSTEM_PREFERENCE_PERSIST_SCROLLBARS, /**< Always show scrollbars, don't hide them after a few seconds of inactivity */
SDL_SYSTEM_PREFERENCE_SCREEN_READER, /**< A screen reader is currently active */
} SDL_SystemPreference;

/**
* Get whether or not a certain system preference was enabled by the user.
*
* \param preference the preference to be fetched.
* \returns true if the user enabled the system preference; false if the user
* disabled that setting, or the setting doesn't exist, or an error
* occured.
*
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_SystemPreference
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetSystemPreference(SDL_SystemPreference preference);

/**
* Get the system's accent color, as chosen by the user.
*
* If the current system does not have an accent color, false is returned and
* the struct is unaffected.
*
* \param color a pointer to a struct to be filled with the color info. The
* alpha channel is what the operating system returned and may or
* may not be opaque.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC bool SDLCALL SDL_GetSystemAccentColor(SDL_Color *color);

/**
* Get the scale factor for text, as set by the user for their system.
*
* If the system does not have a setting to scale the font, 1 is returned.
*
* \returns the preferred scale for text; a scale of 1 means no scaling.
*
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC float SDLCALL SDL_GetSystemTextScale(void);

/**
* Get the scale factor for the cursor, as set by the user for their system.
*
* If the system does not have a setting to scale the cursor, 1 is returned.
*
* \returns the preferred scale for the cursor; a scale of 1 means no scaling.
*
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*/
extern SDL_DECLSPEC float SDLCALL SDL_GetSystemCursorScale(void);

/**
* Get a list of currently connected displays.
*
Expand Down
Loading
Loading