implemented monitor profile functions

This commit is contained in:
ajs 2025-10-21 13:17:01 +01:00
parent ec06f9be37
commit 79cf19f96a
2 changed files with 77 additions and 0 deletions

View File

@ -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 char *(*LoadFileTextCallback)(const char *fileName); // FileIO: Load text data
typedef bool (*SaveFileTextCallback)(const char *fileName, const char *text); // FileIO: Save 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 // 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 GetMonitorPhysicalWidth(int monitor); // Get specified monitor physical width in millimetres
RLAPI int GetMonitorPhysicalHeight(int monitor); // Get specified monitor physical height 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 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 GetWindowPosition(void); // Get window position XY on monitor
RLAPI Vector2 GetWindowScaleDPI(void); // Get window scale DPI factor 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 RLAPI const char *GetMonitorName(int monitor); // Get the human-readable, UTF-8 encoded name of the specified monitor

View File

@ -620,6 +620,70 @@ const char *TextFormat(const char *text, ...); // Formatting of text with variab
//void EnableCursor(void) //void EnableCursor(void)
//void DisableCursor(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 // Initialize window and OpenGL context
void InitWindow(int width, int height, const char *title) void InitWindow(int width, int height, const char *title)
{ {