From f4f525549cc69c4a53aab9319778b4a8227c8d74 Mon Sep 17 00:00:00 2001
From: BrandonSchaefer <brandontschaefer@gmail.com>
Date: Thu, 6 Nov 2014 00:28:17 -0800
Subject: [PATCH] Finish up the monitor work.

---
 src/mir_monitor.c  | 22 +++++++++++++++++-----
 src/mir_platform.h |  2 +-
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/mir_monitor.c b/src/mir_monitor.c
index 9841a524..e18c7041 100644
--- a/src/mir_monitor.c
+++ b/src/mir_monitor.c
@@ -39,7 +39,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
 
     _GLFWmonitor** monitors = NULL;
 
-    // TODO Break this loop down into the other functions there
     for (d = 0; d < display_config->num_outputs; d++)
     {
         MirDisplayOutput const* out = display_config->outputs + d;
@@ -57,7 +56,11 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
             monitor->mir.x         = out->position_x;
             monitor->mir.y         = out->position_y;
             monitor->mir.output_id = out->output_id;
-            monitor->mir.num_modes = out->num_modes;
+            monitor->mir.cur_mode  = out->current_mode;
+            monitor->modeCount     = out->num_modes;
+            monitor->widthMM       = out->physical_width_mm;
+            monitor->heightMM      = out->physical_height_mm;
+
             monitor->modes         = calloc(out->num_modes, sizeof(GLFWvidmode));
 
             int n_mode;
@@ -68,6 +71,8 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
                 monitor->modes[n_mode].refreshRate = out->modes[n_mode].refresh_rate;
             }
 
+            _glfwPlatformGetVideoMode(monitor, &monitor->currentMode);
+
             monitors[d] = monitor;
         }
     }
@@ -91,15 +96,22 @@ void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
         *ypos = monitor->mir.y;
 }
 
-// FIXME Break down the top function into these functions
 GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
 {
-    return NULL;
+    GLFWvidmode* modes = NULL;
+    int i, count = monitor->modeCount;
+
+    modes = calloc(count, sizeof(GLFWvidmode));
+    for (i = 0; i < count; i++)
+      modes[i] = monitor->modes[i];
+
+    *found = count;
+    return modes;
 }
 
-// FIXME Break down the top function into these functions
 void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
 {
+  *mode = monitor->modes[monitor->mir.cur_mode];
 }
 
 void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
diff --git a/src/mir_platform.h b/src/mir_platform.h
index b288c21d..a89a93b6 100644
--- a/src/mir_platform.h
+++ b/src/mir_platform.h
@@ -60,7 +60,7 @@ typedef struct _GLFWwindowMir
 
 typedef struct _GLFWmonitorMir
 {
-    int num_modes;
+    int cur_mode;
     int output_id;
     int x;
     int y;