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 
127  glfwSwapInterval(1);
128 
130 
131  glClearColor(0.5f, 0.5f, 0.5f, 0);
132 
133  while (!glfwWindowShouldClose(window))
134  {
136 
138  glfwWaitEvents();
139  }
140 
141  glfwTerminate();
142  exit(EXIT_SUCCESS);
143 }
144 
glfwSetClipboardString
GLFWAPI void glfwSetClipboardString(GLFWwindow *window, const char *string)
Sets the clipboard to the specified string.
Definition: input.c:1261
glfwSwapInterval
GLFWAPI void glfwSwapInterval(int interval)
Sets the swap interval for the current context.
Definition: context.c:658
GL_COLOR_BUFFER_BIT
#define GL_COLOR_BUFFER_BIT
Definition: glad/glad/glad.h:144
key_callback
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
Definition: clipboard.c:54
glfwMakeContextCurrent
GLFWAPI void glfwMakeContextCurrent(GLFWwindow *window)
Makes the context of the specified window current for the calling thread.
Definition: context.c:611
glfwTerminate
GLFWAPI void glfwTerminate(void)
Terminates the GLFW library.
Definition: init.c:243
getopt.h
GLFW_PRESS
#define GLFW_PRESS
The key or mouse button was pressed.
Definition: glfw3.h:304
glfw3.h
The header of the GLFW 3 API.
string
GLsizei const GLchar *const * string
Definition: glad/glad/glad.h:2861
window
static GLFWwindow * window
Definition: joysticks.c:55
GLFW_KEY_V
#define GLFW_KEY_V
Definition: glfw3.h:399
glfwGetClipboardString
const GLFWAPI char * glfwGetClipboardString(GLFWwindow *window)
Returns the contents of the clipboard as a string.
Definition: input.c:1269
glfwSetErrorCallback
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
Sets the error callback.
Definition: init.c:309
glfwWaitEvents
GLFWAPI void glfwWaitEvents(void)
Waits until events are queued and processes them.
Definition: window.c:1078
glfwSwapBuffers
GLFWAPI void glfwSwapBuffers(GLFWwindow *window)
Swaps the front and back buffers of the specified window.
Definition: context.c:641
getopt
int getopt(int argc, char *const argv[], const char *optstring)
Definition: getopt.c:52
main
int main(int argc, char **argv)
Definition: clipboard.c:89
gladLoadGLLoader
GLAPI int gladLoadGLLoader(GLADloadproc)
Definition: glad/glad.c:1696
usage
static void usage(void)
Definition: clipboard.c:44
NULL
#define NULL
Definition: tinycthread.c:47
test-ts-eof.stderr
stderr
Definition: test-ts-eof.py:102
MODIFIER
#define MODIFIER
Definition: clipboard.c:41
GLFW_TRUE
#define GLFW_TRUE
One.
Definition: glfw3.h:279
f
GLdouble f
Definition: glad/glad/glad.h:1517
GLFWwindow
struct GLFWwindow GLFWwindow
Definition: rs_processing_gl.h:43
GLADloadproc
void *(* GLADloadproc)(const char *name)
Definition: glad/glad/glad.h:64
glClearColor
#define glClearColor
Definition: glad/glad/glad.h:1426
glfwInit
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
Definition: init.c:198
glfwGetProcAddress
GLFWAPI GLFWglproc glfwGetProcAddress(const char *procname)
Returns the address of the specified function for the current context.
Definition: context.c:741
devices.action
action
Definition: third-party/realdds/scripts/devices.py:6
window
Definition: example.hpp:513
error_callback
static void error_callback(int error, const char *description)
Definition: clipboard.c:49
key
void key(GLFWwindow *window, int k, int s, int action, int mods)
Definition: gears.c:213
GLFW_KEY_ESCAPE
#define GLFW_KEY_ESCAPE
Definition: glfw3.h:412
GLFW_KEY_C
#define GLFW_KEY_C
Definition: glfw3.h:380
glfwSetKeyCallback
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow *window, GLFWkeyfun cbfun)
Sets the key callback.
Definition: input.c:791
glClear
#define glClear
Definition: glad/glad/glad.h:1423
glfwCreateWindow
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
rs2::textual_icons::exit
static const textual_icon exit
Definition: device-model.h:222
glfwWindowShouldClose
GLFWAPI int glfwWindowShouldClose(GLFWwindow *window)
Checks the close flag of the specified window.
Definition: window.c:477
glfwSetWindowShouldClose
GLFWAPI void glfwSetWindowShouldClose(GLFWwindow *window, int value)
Sets the close flag of the specified window.
Definition: window.c:486


librealsense2
Author(s): LibRealSense ROS Team
autogenerated on Fri Aug 2 2024 08:30:01