clipboard.c
Go to the documentation of this file.
1 //========================================================================
2 // Clipboard 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 clipboard functionality.
27 //
28 //========================================================================
29 
30 #include <glad/glad.h>
31 #include <GLFW/glfw3.h>
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 
36 #include "getopt.h"
37 
38 #if defined(__APPLE__)
39  #define MODIFIER GLFW_MOD_SUPER
40 #else
41  #define MODIFIER GLFW_MOD_CONTROL
42 #endif
43 
44 static void usage(void)
45 {
46  printf("Usage: clipboard [-h]\n");
47 }
48 
49 static void error_callback(int error, const char* description)
50 {
51  fprintf(stderr, "Error: %s\n", description);
52 }
53 
54 static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
55 {
56  if (action != GLFW_PRESS)
57  return;
58 
59  switch (key)
60  {
61  case GLFW_KEY_ESCAPE:
63  break;
64 
65  case GLFW_KEY_V:
66  if (mods == MODIFIER)
67  {
68  const char* string;
69 
70  string = glfwGetClipboardString(NULL);
71  if (string)
72  printf("Clipboard contains \"%s\"\n", string);
73  else
74  printf("Clipboard does not contain a string\n");
75  }
76  break;
77 
78  case GLFW_KEY_C:
79  if (mods == MODIFIER)
80  {
81  const char* string = "Hello GLFW World!";
83  printf("Setting clipboard to \"%s\"\n", string);
84  }
85  break;
86  }
87 }
88 
89 int main(int argc, char** argv)
90 {
91  int ch;
93 
94  while ((ch = getopt(argc, argv, "h")) != -1)
95  {
96  switch (ch)
97  {
98  case 'h':
99  usage();
100  exit(EXIT_SUCCESS);
101 
102  default:
103  usage();
104  exit(EXIT_FAILURE);
105  }
106  }
107 
109 
110  if (!glfwInit())
111  {
112  fprintf(stderr, "Failed to initialize GLFW\n");
113  exit(EXIT_FAILURE);
114  }
115 
116  window = glfwCreateWindow(200, 200, "Clipboard Test", NULL, NULL);
117  if (!window)
118  {
119  glfwTerminate();
120 
121  fprintf(stderr, "Failed to open GLFW window\n");
122  exit(EXIT_FAILURE);
123  }
124 
125  glfwMakeContextCurrent(window);
127  glfwSwapInterval(1);
128 
130 
131  glClearColor(0.5f, 0.5f, 0.5f, 0);
132 
133  while (!glfwWindowShouldClose(window))
134  {
136 
137  glfwSwapBuffers(window);
138  glfwWaitEvents();
139  }
140 
141  glfwTerminate();
142  exit(EXIT_SUCCESS);
143 }
144 
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
void *(* GLADloadproc)(const char *name)
static GLFWwindow * window
Definition: joysticks.c:55
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
Sets the error callback.
Definition: init.c:309
GLsizei const GLchar *const * string
int getopt(int argc, char *const argv[], const char *optstring)
Definition: getopt.c:52
int main(int argc, char **argv)
Definition: clipboard.c:89
#define GLFW_KEY_V
Definition: glfw3.h:399
GLuint64 key
Definition: glext.h:8966
GLFWAPI const char * glfwGetClipboardString(GLFWwindow *window)
Returns the contents of the clipboard as a string.
Definition: input.c:1269
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
Definition: init.c:198
GLdouble f
#define GL_COLOR_BUFFER_BIT
GLFWAPI void glfwSwapInterval(int interval)
Sets the swap interval for the current context.
Definition: context.c:658
#define GLFW_KEY_ESCAPE
Definition: glfw3.h:412
#define glClear
GLFWAPI void glfwSwapBuffers(GLFWwindow *window)
Swaps the front and back buffers of the specified window.
Definition: context.c:641
#define MODIFIER
Definition: clipboard.c:41
GLFWAPI void glfwMakeContextCurrent(GLFWwindow *window)
Makes the context of the specified window current for the calling thread.
Definition: context.c:611
static void error_callback(int error, const char *description)
Definition: clipboard.c:49
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
Definition: clipboard.c:54
action
Definition: enums.py:62
GLAPI int gladLoadGLLoader(GLADloadproc)
Definition: glad/glad.c:1697
static const textual_icon exit
Definition: model-views.h:254
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
GLFWAPI void glfwSetClipboardString(GLFWwindow *window, const char *string)
Sets the clipboard to the specified string.
Definition: input.c:1261
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 void glfwTerminate(void)
Terminates the GLFW library.
Definition: init.c:243
#define glClearColor
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow *window, GLFWkeyfun cbfun)
Sets the key callback.
Definition: input.c:791
#define NULL
Definition: tinycthread.c:47
#define GLFW_PRESS
The key or mouse button was pressed.
Definition: glfw3.h:304
static void usage(void)
Definition: clipboard.c:44
struct GLFWwindow GLFWwindow
#define GLFW_KEY_C
Definition: glfw3.h:380
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:11