Browse Source

Added display properties

Sam Lantinga 1 year ago
parent
commit
0cd4b7d3e3

+ 14 - 0
include/SDL3/SDL_video.h

@@ -339,6 +339,20 @@ extern DECLSPEC SDL_DisplayID *SDLCALL SDL_GetDisplays(int *count);
  */
  */
 extern DECLSPEC SDL_DisplayID SDLCALL SDL_GetPrimaryDisplay(void);
 extern DECLSPEC SDL_DisplayID SDLCALL SDL_GetPrimaryDisplay(void);
 
 
+/**
+ * Get the properties associated with a display.
+ *
+ * \param displayID the instance ID of the display to query
+ * \returns a valid property ID on success or 0 on failure; call
+ *          SDL_GetError() for more information.
+ *
+ * \since This function is available since SDL 3.0.0.
+ *
+ * \sa SDL_GetProperty
+ * \sa SDL_SetProperty
+ */
+extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetDisplayProperties(SDL_DisplayID displayID);
+
 /**
 /**
  * Get the name of a display in UTF-8 encoding.
  * Get the name of a display in UTF-8 encoding.
  *
  *

+ 1 - 0
src/dynapi/SDL_dynapi.sym

@@ -923,6 +923,7 @@ SDL3_0.0.0 {
     SDL_RWprintf;
     SDL_RWprintf;
     SDL_RWvprintf;
     SDL_RWvprintf;
     SDL_AllocateEventMemory;
     SDL_AllocateEventMemory;
+    SDL_GetDisplayProperties;
     # extra symbols go here (don't modify this line)
     # extra symbols go here (don't modify this line)
   local: *;
   local: *;
 };
 };

+ 1 - 0
src/dynapi/SDL_dynapi_overrides.h

@@ -948,3 +948,4 @@
 #define SDL_RWprintf SDL_RWprintf_REAL
 #define SDL_RWprintf SDL_RWprintf_REAL
 #define SDL_RWvprintf SDL_RWvprintf_REAL
 #define SDL_RWvprintf SDL_RWvprintf_REAL
 #define SDL_AllocateEventMemory SDL_AllocateEventMemory_REAL
 #define SDL_AllocateEventMemory SDL_AllocateEventMemory_REAL
+#define SDL_GetDisplayProperties SDL_GetDisplayProperties_REAL

+ 1 - 0
src/dynapi/SDL_dynapi_procs.h

@@ -981,3 +981,4 @@ SDL_DYNAPI_PROC(int,SDL_ClearProperty,(SDL_PropertiesID a, const char *b),(a,b),
 SDL_DYNAPI_PROC(int,SDL_EnterAppMainCallbacks,(int a, char *b[], SDL_AppInit_func c, SDL_AppIterate_func d, SDL_AppEvent_func e, SDL_AppQuit_func f),(a,b,c,d,e,f),return)
 SDL_DYNAPI_PROC(int,SDL_EnterAppMainCallbacks,(int a, char *b[], SDL_AppInit_func c, SDL_AppIterate_func d, SDL_AppEvent_func e, SDL_AppQuit_func f),(a,b,c,d,e,f),return)
 SDL_DYNAPI_PROC(size_t,SDL_RWvprintf,(SDL_RWops *a, const char *b, va_list c),(a,b,c),return)
 SDL_DYNAPI_PROC(size_t,SDL_RWvprintf,(SDL_RWops *a, const char *b, va_list c),(a,b,c),return)
 SDL_DYNAPI_PROC(void*,SDL_AllocateEventMemory,(size_t a),(a),return)
 SDL_DYNAPI_PROC(void*,SDL_AllocateEventMemory,(size_t a),(a),return)
+SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetDisplayProperties,(SDL_DisplayID a),(a),return)

+ 2 - 0
src/video/SDL_sysvideo.h

@@ -146,6 +146,8 @@ struct SDL_VideoDisplay
 
 
     SDL_VideoDevice *device;
     SDL_VideoDevice *device;
 
 
+    SDL_PropertiesID props;
+
     SDL_DisplayData *driverdata;
     SDL_DisplayData *driverdata;
 };
 };
 
 

+ 13 - 0
src/video/SDL_video.c

@@ -717,6 +717,7 @@ void SDL_DelVideoDisplay(SDL_DisplayID displayID, SDL_bool send_event)
         SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_REMOVED, 0);
         SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_REMOVED, 0);
     }
     }
 
 
+    SDL_DestroyProperties(display->props);
     SDL_free(display->name);
     SDL_free(display->name);
     SDL_ResetFullscreenDisplayModes(display);
     SDL_ResetFullscreenDisplayModes(display);
     SDL_free(display->desktop_mode.driverdata);
     SDL_free(display->desktop_mode.driverdata);
@@ -820,6 +821,18 @@ SDL_DisplayData *SDL_GetDisplayDriverDataForWindow(SDL_Window *window)
     return SDL_GetDisplayDriverData(SDL_GetDisplayForWindow(window));
     return SDL_GetDisplayDriverData(SDL_GetDisplayForWindow(window));
 }
 }
 
 
+SDL_PropertiesID SDL_GetDisplayProperties(SDL_DisplayID displayID)
+{
+    SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID);
+
+    CHECK_DISPLAY_MAGIC(display, 0);
+
+    if (display->props == 0) {
+        display->props = SDL_CreateProperties();
+    }
+    return display->props;
+}
+
 const char *SDL_GetDisplayName(SDL_DisplayID displayID)
 const char *SDL_GetDisplayName(SDL_DisplayID displayID)
 {
 {
     SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID);
     SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID);