From 79cf19f96a9e63588c249230fac4dd9748944c9d Mon Sep 17 00:00:00 2001 From: ajs Date: Tue, 21 Oct 2025 13:17:01 +0100 Subject: [PATCH] implemented monitor profile functions --- src/raylib.h | 13 +++++++++++ src/rcore.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/src/raylib.h b/src/raylib.h index e4be11084..c65132bb8 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -956,6 +956,17 @@ typedef bool (*SaveFileDataCallback)(const char *fileName, void *data, int dataS typedef char *(*LoadFileTextCallback)(const char *fileName); // FileIO: Load text data typedef bool (*SaveFileTextCallback)(const char *fileName, const char *text); // FileIO: Save text data +typedef struct{ + unsigned int width; + unsigned int height; +} MonitorResolution; + +typedef struct { + unsigned int monitor_id; + unsigned int resolution_count; + MonitorResolution *resolutions; +}MonitorProfile; + //------------------------------------------------------------------------------------ // Global Variables Definition //------------------------------------------------------------------------------------ @@ -1011,6 +1022,8 @@ RLAPI int GetMonitorHeight(int monitor); // Get specifi RLAPI int GetMonitorPhysicalWidth(int monitor); // Get specified monitor physical width in millimetres RLAPI int GetMonitorPhysicalHeight(int monitor); // Get specified monitor physical height in millimetres RLAPI int GetMonitorRefreshRate(int monitor); // Get specified monitor refresh rate +RLAPI MonitorProfile* GetMonitorProfile(unsigned int monitor_id); // Get monitor profiles +RLAPI void ClearMonitorProfile(MonitorProfile* profile); // Destruct monitor profile object RLAPI Vector2 GetWindowPosition(void); // Get window position XY on monitor RLAPI Vector2 GetWindowScaleDPI(void); // Get window scale DPI factor RLAPI const char *GetMonitorName(int monitor); // Get the human-readable, UTF-8 encoded name of the specified monitor diff --git a/src/rcore.c b/src/rcore.c index 350490ad1..28e0ac137 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -620,6 +620,70 @@ const char *TextFormat(const char *text, ...); // Formatting of text with variab //void EnableCursor(void) //void DisableCursor(void) +void ClearMonitorProfile(MonitorProfile *profile) { + if(profile != NULL){ + if(profile->resolutions!=NULL){ + free(profile->resolutions); + } + free(profile); + } +} + +MonitorProfile *GetMonitorProfile(unsigned int monitor_id) { +#if defined(PLATFORM_DESKTOP_GLFW) + int count; + GLFWmonitor **monitors = glfwGetMonitors(&count); + if ( + count < monitor_id || + monitors == NULL || + monitors[monitor_id] == NULL + ) { return NULL; } + const GLFWvidmode *modes = glfwGetVideoModes(monitors[monitor_id], &count); + const GLFWvidmode* currentMode = glfwGetVideoMode(monitors[monitor_id]); + if ( + count == 0 || + modes == NULL || + currentMode == NULL + ) { return NULL; } + MonitorProfile *profile = malloc(sizeof(MonitorProfile)); + profile->monitor_id = monitor_id; + int actual_count = 0, idx; + const int + max_rr = currentMode->refreshRate, + max_rb = currentMode->redBits, + max_bb = currentMode->blueBits, + max_gb = currentMode->greenBits; + for (idx = 0; idx < count; idx++) { + const GLFWvidmode mode = modes[idx]; + if ( + mode.refreshRate != max_rr || + mode.greenBits != max_gb || + mode.blueBits != max_bb || + mode.redBits != max_rb + ) { continue; } + actual_count++; + } + profile->resolution_count = actual_count; + profile->resolutions = calloc(actual_count, sizeof(MonitorResolution)); + int filtered_idx = 0; + for (idx = 0; idx < count; idx++) { + const GLFWvidmode mode = modes[idx]; + if ( + mode.refreshRate != max_rr || + mode.greenBits != max_gb || + mode.blueBits != max_bb || + mode.redBits != max_rb + ) { continue; } + profile->resolutions[filtered_idx].width = mode.width; + profile->resolutions[filtered_idx].height = mode.height; + filtered_idx++; + } + return profile; +#else + return NULL; +#endif +} + // Initialize window and OpenGL context void InitWindow(int width, int height, const char *title) {