Added multi-window support to iconify test.

Added -a option for creating one window per monitor.  Added -n option
for disabling auto-iconification. Added option descriptions to usage.
This commit is contained in:
Camilla Berglund 2014-12-09 20:46:45 +01:00
parent a6ba9d6bcd
commit 2b62858770

View File

@ -37,7 +37,12 @@
static void usage(void) static void usage(void)
{ {
printf("Usage: iconify [-h] [-f]\n"); printf("Usage: iconify [-h] [-f [-a] [-n]]\n");
printf("Options:\n");
printf(" -a create windows for all monitors\n");
printf(" -f create full screen window(s)\n");
printf(" -h show this help\n");
printf(" -n no automatic iconification of full screen windows\n");
} }
static void error_callback(int error, const char* description) static void error_callback(int error, const char* description)
@ -91,35 +96,31 @@ static void window_iconify_callback(GLFWwindow* window, int iconified)
iconified ? "iconified" : "restored"); iconified ? "iconified" : "restored");
} }
int main(int argc, char** argv) static void window_refresh_callback(GLFWwindow* window)
{ {
int width, height, ch; int width, height;
GLFWmonitor* monitor = NULL; glfwGetFramebufferSize(window, &width, &height);
glfwMakeContextCurrent(window);
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, width, height);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glScissor(0, 0, 640, 480);
glClearColor(1, 1, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
}
static GLFWwindow* create_window(GLFWmonitor* monitor)
{
int width, height;
GLFWwindow* window; GLFWwindow* window;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(EXIT_FAILURE);
while ((ch = getopt(argc, argv, "fh")) != -1)
{
switch (ch)
{
case 'h':
usage();
exit(EXIT_SUCCESS);
case 'f':
monitor = glfwGetPrimaryMonitor();
break;
default:
usage();
exit(EXIT_FAILURE);
}
}
if (monitor) if (monitor)
{ {
const GLFWvidmode* mode = glfwGetVideoMode(monitor); const GLFWvidmode* mode = glfwGetVideoMode(monitor);
@ -145,35 +146,103 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
glfwMakeContextCurrent(window); return window;
glfwSwapInterval(1); }
glfwSetKeyCallback(window, key_callback); int main(int argc, char** argv)
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); {
glfwSetWindowSizeCallback(window, window_size_callback); int ch, i, window_count;
glfwSetWindowFocusCallback(window, window_focus_callback); GLboolean auto_iconify = GL_TRUE, fullscreen = GL_FALSE, all_monitors = GL_FALSE;
glfwSetWindowIconifyCallback(window, window_iconify_callback); GLFWwindow** windows;
printf("Window is %s and %s\n", while ((ch = getopt(argc, argv, "afhn")) != -1)
glfwGetWindowAttrib(window, GLFW_ICONIFIED) ? "iconified" : "restored",
glfwGetWindowAttrib(window, GLFW_FOCUSED) ? "focused" : "defocused");
glEnable(GL_SCISSOR_TEST);
while (!glfwWindowShouldClose(window))
{ {
glfwGetFramebufferSize(window, &width, &height); switch (ch)
{
case 'a':
all_monitors = GL_TRUE;
break;
glScissor(0, 0, width, height); case 'h':
glClearColor(0, 0, 0, 0); usage();
glClear(GL_COLOR_BUFFER_BIT); exit(EXIT_SUCCESS);
glScissor(0, 0, 640, 480); case 'f':
glClearColor(1, 1, 1, 0); fullscreen = GL_TRUE;
glClear(GL_COLOR_BUFFER_BIT); break;
glfwSwapBuffers(window); case 'n':
auto_iconify = GL_FALSE;
break;
default:
usage();
exit(EXIT_FAILURE);
}
}
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(EXIT_FAILURE);
glfwWindowHint(GLFW_AUTO_ICONIFY, auto_iconify);
if (fullscreen && all_monitors)
{
int monitor_count;
GLFWmonitor** monitors = glfwGetMonitors(&monitor_count);
window_count = monitor_count;
windows = calloc(window_count, sizeof(GLFWwindow*));
for (i = 0; i < monitor_count; i++)
{
windows[i] = create_window(monitors[i]);
if (!windows[i])
break;
}
}
else
{
GLFWmonitor* monitor = NULL;
if (fullscreen)
monitor = glfwGetPrimaryMonitor();
window_count = 1;
windows = calloc(window_count, sizeof(GLFWwindow*));
windows[0] = create_window(monitor);
}
for (i = 0; i < window_count; i++)
{
glfwSetKeyCallback(windows[i], key_callback);
glfwSetFramebufferSizeCallback(windows[i], framebuffer_size_callback);
glfwSetWindowSizeCallback(windows[i], window_size_callback);
glfwSetWindowFocusCallback(windows[i], window_focus_callback);
glfwSetWindowIconifyCallback(windows[i], window_iconify_callback);
glfwSetWindowRefreshCallback(windows[i], window_refresh_callback);
window_refresh_callback(windows[i]);
printf("Window is %s and %s\n",
glfwGetWindowAttrib(windows[i], GLFW_ICONIFIED) ? "iconified" : "restored",
glfwGetWindowAttrib(windows[i], GLFW_FOCUSED) ? "focused" : "defocused");
}
for (;;)
{
glfwPollEvents(); glfwPollEvents();
for (i = 0; i < window_count; i++)
{
if (glfwWindowShouldClose(windows[i]))
break;
}
if (i < window_count)
break;
} }
glfwTerminate(); glfwTerminate();