From 784f60365e0a33f3dbaaa196b9bdd9d2e6851d3e Mon Sep 17 00:00:00 2001 From: Marcel Metz Date: Sun, 9 Oct 2011 00:20:34 -0400 Subject: [PATCH] Stub implementation of monitor callback. --- src/internal.h | 1 + src/monitor.c | 15 +++++++++++++++ tests/events.c | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/internal.h b/src/internal.h index be01dbe6..74388d6e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -264,6 +264,7 @@ struct _GLFWlibrary GLFWscrollfun scrollCallback; GLFWkeyfun keyCallback; GLFWcharfun charCallback; + GLFWmonitordevicefun monitorCallback; GLFWthreadmodel threading; GLFWallocator allocator; diff --git a/src/monitor.c b/src/monitor.c index 78c919b2..3263eb9f 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -130,3 +130,18 @@ GLFWAPI const char* glfwGetMonitorString(GLFWmonitor handle, int param) return NULL; } +//======================================================================== +// Set a callback function for monitor events +//======================================================================== + +GLFWAPI void glfwSetMonitorDeviceCallback(GLFWmonitordevicefun cbfun) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + _glfwLibrary.monitorCallback= cbfun; +} + diff --git a/tests/events.c b/tests/events.c index ac758100..1a1280a3 100644 --- a/tests/events.c +++ b/tests/events.c @@ -216,6 +216,19 @@ static const char* get_character_string(int character) return result; } +static const char* get_monitor_event_name(int event) +{ + switch (event) + { + case GLFW_MONITOR_CONNECTED: + return "connected"; + case GLFW_MONITOR_DISCONNECTED: + return "disconnected"; + } + + return NULL; +} + static void window_size_callback(GLFWwindow window, int width, int height) { printf("%08x at %0.3f: Window size: %i %i\n", @@ -330,6 +343,16 @@ static void char_callback(GLFWwindow window, int character) get_character_string(character)); } +void monitor_callback(GLFWmonitor monitor, int event) +{ + printf("%08x at %0.3f: Monitor %s %s", + counter++, + glfwGetTime(), + glfwGetMonitorString(monitor, GLFW_MONITOR_NAME), + get_monitor_event_name(event)); + +} + int main(void) { GLFWwindow window; @@ -354,6 +377,7 @@ int main(void) glfwSetScrollCallback(scroll_callback); glfwSetKeyCallback(key_callback); glfwSetCharCallback(char_callback); + glfwSetMonitorDeviceCallback(monitor_callback); window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Event Linter", NULL); if (!window)