mirror of
https://github.com/glfw/glfw.git
synced 2024-11-25 06:04:34 +00:00
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:
parent
a6ba9d6bcd
commit
2b62858770
169
tests/iconify.c
169
tests/iconify.c
@ -37,7 +37,12 @@
|
||||
|
||||
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)
|
||||
@ -91,35 +96,31 @@ static void window_iconify_callback(GLFWwindow* window, int iconified)
|
||||
iconified ? "iconified" : "restored");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
static void window_refresh_callback(GLFWwindow* window)
|
||||
{
|
||||
int width, height, ch;
|
||||
GLFWmonitor* monitor = NULL;
|
||||
int width, height;
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||
@ -145,35 +146,103 @@ int main(int argc, char** argv)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
return window;
|
||||
}
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||
glfwSetWindowFocusCallback(window, window_focus_callback);
|
||||
glfwSetWindowIconifyCallback(window, window_iconify_callback);
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int ch, i, window_count;
|
||||
GLboolean auto_iconify = GL_TRUE, fullscreen = GL_FALSE, all_monitors = GL_FALSE;
|
||||
GLFWwindow** windows;
|
||||
|
||||
while ((ch = getopt(argc, argv, "afhn")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'a':
|
||||
all_monitors = GL_TRUE;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
case 'f':
|
||||
fullscreen = GL_TRUE;
|
||||
break;
|
||||
|
||||
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(window, GLFW_ICONIFIED) ? "iconified" : "restored",
|
||||
glfwGetWindowAttrib(window, GLFW_FOCUSED) ? "focused" : "defocused");
|
||||
glfwGetWindowAttrib(windows[i], GLFW_ICONIFIED) ? "iconified" : "restored",
|
||||
glfwGetWindowAttrib(windows[i], GLFW_FOCUSED) ? "focused" : "defocused");
|
||||
}
|
||||
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
for (;;)
|
||||
{
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
|
||||
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);
|
||||
glfwPollEvents();
|
||||
|
||||
for (i = 0; i < window_count; i++)
|
||||
{
|
||||
if (glfwWindowShouldClose(windows[i]))
|
||||
break;
|
||||
}
|
||||
|
||||
if (i < window_count)
|
||||
break;
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
|
Loading…
Reference in New Issue
Block a user