iconify.c
Go to the documentation of this file.
1 //========================================================================
2 // Iconify/restore test program
3 // Copyright (c) Camilla Löwy <elmindreda@glfw.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 program is used to test the iconify/restore functionality for
27 // both full screen and windowed mode windows
28 //
29 //========================================================================
30 
31 #include <glad/glad.h>
32 #include <GLFW/glfw3.h>
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 
37 #include "getopt.h"
38 
40 
41 static void usage(void)
42 {
43  printf("Usage: iconify [-h] [-f [-a] [-n]]\n");
44  printf("Options:\n");
45  printf(" -a create windows for all monitors\n");
46  printf(" -f create full screen window(s)\n");
47  printf(" -h show this help\n");
48 }
49 
50 static void error_callback(int error, const char* description)
51 {
52  fprintf(stderr, "Error: %s\n", description);
53 }
54 
55 static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
56 {
57  printf("%0.2f Key %s\n",
58  glfwGetTime(),
59  action == GLFW_PRESS ? "pressed" : "released");
60 
61  if (action != GLFW_PRESS)
62  return;
63 
64  switch (key)
65  {
66  case GLFW_KEY_I:
67  glfwIconifyWindow(window);
68  break;
69  case GLFW_KEY_M:
70  glfwMaximizeWindow(window);
71  break;
72  case GLFW_KEY_R:
73  glfwRestoreWindow(window);
74  break;
75  case GLFW_KEY_ESCAPE:
77  break;
78  case GLFW_KEY_A:
80  break;
81  case GLFW_KEY_B:
83  break;
84  case GLFW_KEY_D:
86  break;
87  case GLFW_KEY_F:
89  break;
90  case GLFW_KEY_F11:
91  case GLFW_KEY_ENTER:
92  {
93  if (mods != GLFW_MOD_ALT)
94  return;
95 
96  if (glfwGetWindowMonitor(window))
97  {
98  glfwSetWindowMonitor(window, NULL,
101  0);
102  }
103  else
104  {
105  GLFWmonitor* monitor = glfwGetPrimaryMonitor();
106  if (monitor)
107  {
108  const GLFWvidmode* mode = glfwGetVideoMode(monitor);
111  glfwSetWindowMonitor(window, monitor,
112  0, 0, mode->width, mode->height,
113  mode->refreshRate);
114  }
115  }
116 
117  break;
118  }
119  }
120 }
121 
123 {
124  printf("%0.2f Window resized to %ix%i\n", glfwGetTime(), width, height);
125 }
126 
128 {
129  printf("%0.2f Framebuffer resized to %ix%i\n", glfwGetTime(), width, height);
130 }
131 
132 static void window_focus_callback(GLFWwindow* window, int focused)
133 {
134  printf("%0.2f Window %s\n",
135  glfwGetTime(),
136  focused ? "focused" : "defocused");
137 }
138 
139 static void window_iconify_callback(GLFWwindow* window, int iconified)
140 {
141  printf("%0.2f Window %s\n",
142  glfwGetTime(),
143  iconified ? "iconified" : "uniconified");
144 }
145 
147 {
148  printf("%0.2f Window %s\n",
149  glfwGetTime(),
150  maximized ? "maximized" : "unmaximized");
151 }
152 
154 {
155  printf("%0.2f Window refresh\n", glfwGetTime());
156 
157  glfwMakeContextCurrent(window);
158 
160  glfwSwapBuffers(window);
161 }
162 
164 {
165  int width, height;
167 
168  if (monitor)
169  {
170  const GLFWvidmode* mode = glfwGetVideoMode(monitor);
171 
176 
177  width = mode->width;
178  height = mode->height;
179  }
180  else
181  {
182  width = 640;
183  height = 480;
184  }
185 
186  window = glfwCreateWindow(width, height, "Iconify", monitor, NULL);
187  if (!window)
188  {
189  glfwTerminate();
190  exit(EXIT_FAILURE);
191  }
192 
193  glfwMakeContextCurrent(window);
195 
196  return window;
197 }
198 
199 int main(int argc, char** argv)
200 {
201  int ch, i, window_count;
202  int fullscreen = GLFW_FALSE, all_monitors = GLFW_FALSE;
203  GLFWwindow** windows;
204 
205  while ((ch = getopt(argc, argv, "afhn")) != -1)
206  {
207  switch (ch)
208  {
209  case 'a':
210  all_monitors = GLFW_TRUE;
211  break;
212 
213  case 'h':
214  usage();
215  exit(EXIT_SUCCESS);
216 
217  case 'f':
218  fullscreen = GLFW_TRUE;
219  break;
220 
221  default:
222  usage();
223  exit(EXIT_FAILURE);
224  }
225  }
226 
228 
229  if (!glfwInit())
230  exit(EXIT_FAILURE);
231 
232  if (fullscreen && all_monitors)
233  {
234  int monitor_count;
235  GLFWmonitor** monitors = glfwGetMonitors(&monitor_count);
236 
237  window_count = monitor_count;
238  windows = calloc(window_count, sizeof(GLFWwindow*));
239 
240  for (i = 0; i < monitor_count; i++)
241  {
242  windows[i] = create_window(monitors[i]);
243  if (!windows[i])
244  break;
245  }
246  }
247  else
248  {
249  GLFWmonitor* monitor = NULL;
250 
251  if (fullscreen)
252  monitor = glfwGetPrimaryMonitor();
253 
254  window_count = 1;
255  windows = calloc(window_count, sizeof(GLFWwindow*));
256  windows[0] = create_window(monitor);
257  }
258 
259  for (i = 0; i < window_count; i++)
260  {
261  glfwSetKeyCallback(windows[i], key_callback);
268 
269  window_refresh_callback(windows[i]);
270 
271  printf("Window is %s and %s\n",
272  glfwGetWindowAttrib(windows[i], GLFW_ICONIFIED) ? "iconified" : "restored",
273  glfwGetWindowAttrib(windows[i], GLFW_FOCUSED) ? "focused" : "defocused");
274  }
275 
276  for (;;)
277  {
278  glfwWaitEvents();
279 
280  for (i = 0; i < window_count; i++)
281  {
282  if (glfwWindowShouldClose(windows[i]))
283  break;
284  }
285 
286  if (i < window_count)
287  break;
288 
289  // Workaround for an issue with msvcrt and mintty
290  fflush(stdout);
291  }
292 
293  glfwTerminate();
294  exit(EXIT_SUCCESS);
295 }
296 
int redBits
Definition: glfw3.h:1535
static void window_focus_callback(GLFWwindow *window, int focused)
Definition: iconify.c:132
#define GLFW_AUTO_ICONIFY
Window auto-iconification window hint and attribute.
Definition: glfw3.h:792
int height
Definition: glfw3.h:1532
GLFWAPI void glfwGetWindowSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the client area of the specified window.
Definition: window.c:544
#define GLFW_KEY_I
Definition: glfw3.h:386
static int windowed_xpos
Definition: iconify.c:39
int blueBits
Definition: glfw3.h:1541
static void error_callback(int error, const char *description)
Definition: iconify.c:50
#define GLFW_KEY_F
Definition: glfw3.h:383
GLFWAPI int glfwGetWindowAttrib(GLFWwindow *window, int attrib)
Returns an attribute of the specified window.
Definition: window.c:804
GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow *window, GLFWwindowsizefun cbfun)
Sets the size callback for the specified window.
Definition: window.c:984
The header of the GLFW 3 API.
GLFWAPI GLFWglproc glfwGetProcAddress(const char *procname)
Returns the address of the specified function for the current context.
Definition: context.c:741
static void window_refresh_callback(GLFWwindow *window)
Definition: iconify.c:153
static GLFWwindow * create_window(GLFWmonitor *monitor)
Definition: iconify.c:163
void *(* GLADloadproc)(const char *name)
static GLFWwindow * window
Definition: joysticks.c:55
int width
Definition: glfw3.h:1529
GLFWAPI void glfwSetWindowAttrib(GLFWwindow *window, int attrib, int value)
Sets an attribute of the specified window.
Definition: window.c:863
#define GLFW_ICONIFIED
Window iconification window attribute.
Definition: glfw3.h:768
GLFWAPI const GLFWvidmode * glfwGetVideoMode(GLFWmonitor *monitor)
Returns the current mode of the specified monitor.
Definition: monitor.c:417
static void window_size_callback(GLFWwindow *window, int width, int height)
Definition: iconify.c:122
struct GLFWmonitor GLFWmonitor
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
Sets the error callback.
Definition: init.c:309
#define GLFW_REFRESH_RATE
Monitor refresh rate hint.
Definition: glfw3.h:903
#define GLFW_FALSE
Zero.
Definition: glfw3.h:287
int refreshRate
Definition: glfw3.h:1544
GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow *window, GLFWframebuffersizefun cbfun)
Sets the framebuffer resize callback for the specified window.
Definition: window.c:1050
static int windowed_height
Definition: iconify.c:39
int getopt(int argc, char *const argv[], const char *optstring)
Definition: getopt.c:52
#define GLFW_KEY_B
Definition: glfw3.h:379
static void window_maximize_callback(GLFWwindow *window, int maximized)
Definition: iconify.c:146
#define GLFW_KEY_A
Definition: glfw3.h:378
int greenBits
Definition: glfw3.h:1538
GLuint64 key
Definition: glext.h:8966
GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow *window, GLFWwindowiconifyfun cbfun)
Sets the iconify callback for the specified window.
Definition: window.c:1028
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
Definition: init.c:198
#define GLFW_RED_BITS
Framebuffer bit depth hint.
Definition: glfw3.h:833
GLenum mode
GLFWAPI GLFWmonitor ** glfwGetMonitors(int *count)
Returns the currently connected monitors.
Definition: monitor.c:296
#define GLFW_FLOATING
Window decoration window hint and attribute.
Definition: glfw3.h:798
#define GL_COLOR_BUFFER_BIT
GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow *window, GLFWwindowrefreshfun cbfun)
Sets the refresh callback for the specified window.
Definition: window.c:1006
#define GLFW_KEY_F11
Definition: glfw3.h:441
static int windowed_width
Definition: iconify.c:39
static int windowed_ypos
Definition: iconify.c:39
#define GLFW_KEY_ESCAPE
Definition: glfw3.h:412
GLFWAPI void glfwIconifyWindow(GLFWwindow *window)
Iconifies the specified window.
Definition: window.c:724
#define glClear
GLint GLsizei GLsizei height
GLFWAPI void glfwSwapBuffers(GLFWwindow *window)
Swaps the front and back buffers of the specified window.
Definition: context.c:641
GLFWAPI void glfwMakeContextCurrent(GLFWwindow *window)
Makes the context of the specified window current for the calling thread.
Definition: context.c:611
GLFWAPI void glfwMaximizeWindow(GLFWwindow *window)
Maximizes the specified window.
Definition: window.c:742
GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow *window, GLFWwindowfocusfun cbfun)
Sets the focus callback for the specified window.
Definition: window.c:1017
#define GLFW_KEY_ENTER
Definition: glfw3.h:413
#define GLFW_GREEN_BITS
Framebuffer bit depth hint.
Definition: glfw3.h:838
GLuint * monitors
Definition: glext.h:5686
#define GLFW_KEY_D
Definition: glfw3.h:381
#define GLFW_MOD_ALT
If this bit is set one or more Alt keys were held down.
Definition: glfw3.h:509
#define GLFW_RESIZABLE
Window resize-ability window hint and attribute.
Definition: glfw3.h:774
action
Definition: enums.py:62
GLAPI int gladLoadGLLoader(GLADloadproc)
Definition: glad/glad.c:1697
GLFWAPI GLFWmonitor * glfwGetWindowMonitor(GLFWwindow *window)
Returns the monitor that the window uses for full screen mode.
Definition: window.c:907
static void window_iconify_callback(GLFWwindow *window, int iconified)
Definition: iconify.c:139
static const textual_icon exit
Definition: model-views.h:254
#define GLFW_FOCUSED
Input focus window hint and attribute.
Definition: glfw3.h:763
GLFWAPI void glfwSetWindowShouldClose(GLFWwindow *window, int value)
Sets the close flag of the specified window.
Definition: window.c:486
GLFWAPI void glfwWaitEvents(void)
Waits until events are queued and processes them.
Definition: window.c:1078
#define GLFW_KEY_M
Definition: glfw3.h:390
GLFWAPI void glfwSetWindowMonitor(GLFWwindow *window, GLFWmonitor *monitor, int xpos, int ypos, int width, int height, int refreshRate)
Sets the mode, monitor, video mode and placement of a window.
Definition: window.c:916
GLFWAPI GLFWwindow * glfwCreateWindow(int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share)
Creates a window and its associated context.
Definition: window.c:151
#define GLFW_TRUE
One.
Definition: glfw3.h:279
GLFWAPI double glfwGetTime(void)
Returns the value of the GLFW timer.
Definition: input.c:1275
Video mode type.
Definition: glfw3.h:1525
GLFWAPI void glfwGetWindowPos(GLFWwindow *window, int *xpos, int *ypos)
Retrieves the position of the client area of the specified window.
Definition: window.c:517
int main(int argc, char **argv)
Definition: iconify.c:199
GLFWAPI GLFWmonitor * glfwGetPrimaryMonitor(void)
Returns the primary monitor.
Definition: monitor.c:308
static const char * maximized
Definition: model-views.h:183
GLFWAPI void glfwTerminate(void)
Terminates the GLFW library.
Definition: init.c:243
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow *window, GLFWkeyfun cbfun)
Sets the key callback.
Definition: input.c:791
#define GLFW_BLUE_BITS
Framebuffer bit depth hint.
Definition: glfw3.h:843
#define NULL
Definition: tinycthread.c:47
int i
static void usage(void)
Definition: iconify.c:41
#define GLFW_KEY_R
Definition: glfw3.h:395
#define GLFW_DECORATED
Window decoration window hint and attribute.
Definition: glfw3.h:786
GLFWAPI void glfwRestoreWindow(GLFWwindow *window)
Restores the specified window.
Definition: window.c:733
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
Definition: iconify.c:55
#define GLFW_PRESS
The key or mouse button was pressed.
Definition: glfw3.h:304
static void framebuffer_size_callback(GLFWwindow *window, int width, int height)
Definition: iconify.c:127
struct GLFWwindow GLFWwindow
GLFWAPI void glfwWindowHint(int hint, int value)
Sets the specified window hint to the desired value.
Definition: window.c:291
GLint GLsizei width
GLFWAPI GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow *window, GLFWwindowmaximizefun cbfun)
Sets the maximize callback for the specified window.
Definition: window.c:1039
GLFWAPI int glfwWindowShouldClose(GLFWwindow *window)
Checks the close flag of the specified window.
Definition: window.c:477


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:16