Camilla Berglund | 5ca2189 | 2010-10-04 18:19:04 +0200 | [diff] [blame] | 1 | //======================================================================== |
| 2 | // Fullscreen window (un)focus test |
| 3 | // Copyright (c) Camilla Berglund <elmindreda@elmindreda.org> |
| 4 | // |
| 5 | // This software is provided 'as-is', without any express or implied |
| 6 | // warranty. In no event will the authors be held liable for any damages |
| 7 | // arising from the use of this software. |
| 8 | // |
| 9 | // Permission is granted to anyone to use this software for any purpose, |
| 10 | // including commercial applications, and to alter it and redistribute it |
| 11 | // freely, subject to the following restrictions: |
| 12 | // |
| 13 | // 1. The origin of this software must not be misrepresented; you must not |
| 14 | // claim that you wrote the original software. If you use this software |
| 15 | // in a product, an acknowledgment in the product documentation would |
| 16 | // be appreciated but is not required. |
| 17 | // |
| 18 | // 2. Altered source versions must be plainly marked as such, and must not |
| 19 | // be misrepresented as being the original software. |
| 20 | // |
| 21 | // 3. This notice may not be removed or altered from any source |
| 22 | // distribution. |
| 23 | // |
| 24 | //======================================================================== |
| 25 | // |
| 26 | // This test is used to test window activation and iconfication for |
| 27 | // fullscreen windows with a video mode differing from the desktop mode |
| 28 | // |
| 29 | //======================================================================== |
| 30 | |
| 31 | #include <GL/glfw3.h> |
| 32 | |
| 33 | #include <stdio.h> |
| 34 | #include <stdlib.h> |
| 35 | |
| 36 | static GLboolean running = GL_TRUE; |
| 37 | |
| 38 | static void window_focus_callback(GLFWwindow window, int activated) |
| 39 | { |
| 40 | printf("%0.3f: Window %s\n", |
| 41 | glfwGetTime(), |
| 42 | activated ? "activated" : "deactivated"); |
| 43 | } |
| 44 | |
| 45 | static void window_key_callback(GLFWwindow window, int key, int action) |
| 46 | { |
| 47 | if (action != GLFW_PRESS) |
| 48 | return; |
| 49 | |
| 50 | switch (key) |
| 51 | { |
Marcus | e3cb563 | 2011-01-03 22:22:14 +0100 | [diff] [blame] | 52 | case GLFW_KEY_ESCAPE: |
Camilla Berglund | 5ca2189 | 2010-10-04 18:19:04 +0200 | [diff] [blame] | 53 | { |
| 54 | printf("%0.3f: User pressed Escape\n", glfwGetTime()); |
| 55 | running = GL_FALSE; |
| 56 | break; |
| 57 | } |
| 58 | |
| 59 | case GLFW_KEY_SPACE: |
| 60 | { |
| 61 | printf("%0.3f: User pressed Space\n", glfwGetTime()); |
| 62 | glfwIconifyWindow(window); |
| 63 | break; |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | static int window_close_callback(GLFWwindow window) |
| 69 | { |
| 70 | printf("%0.3f: User closed window\n", glfwGetTime()); |
Camilla Berglund | 2972cdf | 2012-08-03 16:20:52 +0200 | [diff] [blame] | 71 | running = GL_FALSE; |
Camilla Berglund | 5ca2189 | 2010-10-04 18:19:04 +0200 | [diff] [blame] | 72 | return GL_TRUE; |
| 73 | } |
| 74 | |
| 75 | int main(void) |
| 76 | { |
| 77 | GLFWwindow window; |
| 78 | |
Camilla Berglund | 0c3b1b5 | 2012-02-07 14:58:58 +0100 | [diff] [blame] | 79 | if (!glfwInit()) |
Camilla Berglund | 5ca2189 | 2010-10-04 18:19:04 +0200 | [diff] [blame] | 80 | { |
| 81 | fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); |
| 82 | exit(EXIT_FAILURE); |
| 83 | } |
| 84 | |
Camilla Berglund | aff30d0 | 2012-08-06 17:56:41 +0200 | [diff] [blame] | 85 | window = glfwCreateWindow(640, 480, GLFW_FULLSCREEN, "Fullscreen focus", NULL); |
Camilla Berglund | 5ca2189 | 2010-10-04 18:19:04 +0200 | [diff] [blame] | 86 | if (!window) |
| 87 | { |
| 88 | glfwTerminate(); |
| 89 | |
| 90 | fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError())); |
| 91 | exit(EXIT_FAILURE); |
| 92 | } |
| 93 | |
Camilla Berglund | 2f095cc | 2012-08-10 15:29:45 +0200 | [diff] [blame] | 94 | glfwMakeContextCurrent(window); |
Camilla Berglund | 5ca2189 | 2010-10-04 18:19:04 +0200 | [diff] [blame] | 95 | glfwSwapInterval(1); |
Camilla Berglund | 2f095cc | 2012-08-10 15:29:45 +0200 | [diff] [blame] | 96 | |
Camilla Berglund | ce288a8 | 2012-02-04 00:51:35 +0100 | [diff] [blame] | 97 | glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL); |
Camilla Berglund | 5ca2189 | 2010-10-04 18:19:04 +0200 | [diff] [blame] | 98 | |
Camilla Berglund | 18d71c2 | 2012-10-28 13:45:11 +0100 | [diff] [blame^] | 99 | glfwSetWindowFocusCallback(window, window_focus_callback); |
| 100 | glfwSetKeyCallback(window, window_key_callback); |
| 101 | glfwSetWindowCloseCallback(window, window_close_callback); |
Camilla Berglund | 5ca2189 | 2010-10-04 18:19:04 +0200 | [diff] [blame] | 102 | |
Camilla Berglund | 2972cdf | 2012-08-03 16:20:52 +0200 | [diff] [blame] | 103 | while (running) |
Camilla Berglund | 5ca2189 | 2010-10-04 18:19:04 +0200 | [diff] [blame] | 104 | { |
| 105 | glClear(GL_COLOR_BUFFER_BIT); |
Camilla Berglund | 585a840 | 2012-08-06 18:13:37 +0200 | [diff] [blame] | 106 | glfwSwapBuffers(window); |
Camilla Berglund | 5ca2189 | 2010-10-04 18:19:04 +0200 | [diff] [blame] | 107 | glfwWaitEvents(); |
| 108 | } |
| 109 | |
| 110 | glfwTerminate(); |
| 111 | exit(EXIT_SUCCESS); |
| 112 | } |
| 113 | |