|
|
|
@ -34,8 +34,7 @@ |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
|
|
#include "getopt.h" |
|
|
|
|
|
|
|
|
|
static GLFWwindow* windows[4]; |
|
|
|
|
static const char* titles[] = |
|
|
|
|
{ |
|
|
|
|
"Red", |
|
|
|
@ -55,18 +54,24 @@ static const struct |
|
|
|
|
{ 0.98f, 0.74f, 0.04f } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static void usage(void) |
|
|
|
|
static void error_callback(int error, const char* description) |
|
|
|
|
{ |
|
|
|
|
printf("Usage: windows [-h] [-b] [-f] \n"); |
|
|
|
|
printf("Options:\n"); |
|
|
|
|
printf(" -b create decorated windows\n"); |
|
|
|
|
printf(" -f set focus on show off for all but first window\n"); |
|
|
|
|
printf(" -h show this help\n"); |
|
|
|
|
fprintf(stderr, "Error: %s\n", description); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void error_callback(int error, const char* description) |
|
|
|
|
static void arrange_windows(void) |
|
|
|
|
{ |
|
|
|
|
fprintf(stderr, "Error: %s\n", description); |
|
|
|
|
int xbase, ybase; |
|
|
|
|
glfwGetWindowPos(windows[0], &xbase, &ybase); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) |
|
|
|
|
{ |
|
|
|
|
int left, top, right, bottom; |
|
|
|
|
glfwGetWindowFrameSize(windows[i], &left, &top, &right, &bottom); |
|
|
|
|
glfwSetWindowPos(windows[i], |
|
|
|
|
xbase + (i & 1) * (200 + left + right), |
|
|
|
|
ybase + (i >> 1) * (200 + top + bottom)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) |
|
|
|
@ -87,49 +92,34 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action, |
|
|
|
|
case GLFW_KEY_ESCAPE: |
|
|
|
|
glfwSetWindowShouldClose(window, GLFW_TRUE); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) |
|
|
|
|
{ |
|
|
|
|
int i, ch; |
|
|
|
|
int decorated = GLFW_FALSE; |
|
|
|
|
int focusOnShow = GLFW_TRUE; |
|
|
|
|
int running = GLFW_TRUE; |
|
|
|
|
GLFWwindow* windows[4]; |
|
|
|
|
|
|
|
|
|
while ((ch = getopt(argc, argv, "bfh")) != -1) |
|
|
|
|
{ |
|
|
|
|
switch (ch) |
|
|
|
|
case GLFW_KEY_D: |
|
|
|
|
{ |
|
|
|
|
case 'b': |
|
|
|
|
decorated = GLFW_TRUE; |
|
|
|
|
break; |
|
|
|
|
case 'f': |
|
|
|
|
focusOnShow = GLFW_FALSE; |
|
|
|
|
break; |
|
|
|
|
case 'h': |
|
|
|
|
usage(); |
|
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
|
default: |
|
|
|
|
usage(); |
|
|
|
|
exit(EXIT_FAILURE); |
|
|
|
|
for (int i = 0; i < 4; i++) |
|
|
|
|
{ |
|
|
|
|
const int decorated = glfwGetWindowAttrib(windows[i], GLFW_DECORATED); |
|
|
|
|
glfwSetWindowAttrib(windows[i], GLFW_DECORATED, !decorated); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
arrange_windows(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) |
|
|
|
|
{ |
|
|
|
|
glfwSetErrorCallback(error_callback); |
|
|
|
|
|
|
|
|
|
if (!glfwInit()) |
|
|
|
|
exit(EXIT_FAILURE); |
|
|
|
|
|
|
|
|
|
glfwWindowHint(GLFW_DECORATED, decorated); |
|
|
|
|
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); |
|
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) |
|
|
|
|
for (int i = 0; i < 4; i++) |
|
|
|
|
{ |
|
|
|
|
int left, top, right, bottom; |
|
|
|
|
if (i) |
|
|
|
|
glfwWindowHint(GLFW_FOCUS_ON_SHOW, focusOnShow); |
|
|
|
|
if (i > 0) |
|
|
|
|
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE); |
|
|
|
|
|
|
|
|
|
windows[i] = glfwCreateWindow(200, 200, titles[i], NULL, NULL); |
|
|
|
|
if (!windows[i]) |
|
|
|
@ -143,32 +133,29 @@ int main(int argc, char** argv) |
|
|
|
|
glfwMakeContextCurrent(windows[i]); |
|
|
|
|
gladLoadGL(glfwGetProcAddress); |
|
|
|
|
glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f); |
|
|
|
|
|
|
|
|
|
glfwGetWindowFrameSize(windows[i], &left, &top, &right, &bottom); |
|
|
|
|
glfwSetWindowPos(windows[i], |
|
|
|
|
100 + (i & 1) * (200 + left + right), |
|
|
|
|
100 + (i >> 1) * (200 + top + bottom)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) |
|
|
|
|
arrange_windows(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) |
|
|
|
|
glfwShowWindow(windows[i]); |
|
|
|
|
|
|
|
|
|
while (running) |
|
|
|
|
for (;;) |
|
|
|
|
{ |
|
|
|
|
for (i = 0; i < 4; i++) |
|
|
|
|
for (int i = 0; i < 4; i++) |
|
|
|
|
{ |
|
|
|
|
glfwMakeContextCurrent(windows[i]); |
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT); |
|
|
|
|
glfwSwapBuffers(windows[i]); |
|
|
|
|
|
|
|
|
|
if (glfwWindowShouldClose(windows[i])) |
|
|
|
|
running = GLFW_FALSE; |
|
|
|
|
{ |
|
|
|
|
glfwTerminate(); |
|
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glfwWaitEvents(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glfwTerminate(); |
|
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|