1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 12:18:51 -05:00

Stub implementation of monitor callback.

This commit is contained in:
Marcel Metz 2011-10-09 00:20:34 -04:00
parent ac57be060d
commit 784f60365e
3 changed files with 40 additions and 0 deletions

View File

@ -264,6 +264,7 @@ struct _GLFWlibrary
GLFWscrollfun scrollCallback;
GLFWkeyfun keyCallback;
GLFWcharfun charCallback;
GLFWmonitordevicefun monitorCallback;
GLFWthreadmodel threading;
GLFWallocator allocator;

View File

@ -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;
}

View File

@ -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)