mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 13:04:35 +00:00
Added window parameter to clipboard API.
This commit is contained in:
parent
7044ed6f06
commit
bf1ada029b
@ -576,8 +576,8 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes);
|
|||||||
GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
|
GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
|
||||||
|
|
||||||
/* Clipboard */
|
/* Clipboard */
|
||||||
GLFWAPI void glfwSetClipboardString(const char* data);
|
GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* data);
|
||||||
GLFWAPI size_t glfwGetClipboardString(char* data, size_t size);
|
GLFWAPI size_t glfwGetClipboardString(GLFWwindow window, char* data, size_t size);
|
||||||
|
|
||||||
/* Time */
|
/* Time */
|
||||||
GLFWAPI double glfwGetTime(void);
|
GLFWAPI double glfwGetTime(void);
|
||||||
|
@ -41,15 +41,17 @@
|
|||||||
// Set the clipboard contents
|
// Set the clipboard contents
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetClipboardString(const char* string)
|
GLFWAPI void glfwSetClipboardString(GLFWwindow handle, const char* string)
|
||||||
{
|
{
|
||||||
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwPlatformSetClipboardString(string);
|
_glfwPlatformSetClipboardString(window, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -57,8 +59,10 @@ GLFWAPI void glfwSetClipboardString(const char* string)
|
|||||||
// Return the current clipboard contents
|
// Return the current clipboard contents
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI size_t glfwGetClipboardString(char* string, size_t size)
|
GLFWAPI size_t glfwGetClipboardString(GLFWwindow handle, char* string, size_t size)
|
||||||
{
|
{
|
||||||
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
@ -68,6 +72,6 @@ GLFWAPI size_t glfwGetClipboardString(char* string, size_t size)
|
|||||||
if (!string || !size)
|
if (!string || !size)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return _glfwPlatformGetClipboardString(string, size);
|
return _glfwPlatformGetClipboardString(window, string, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,8 +289,8 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp);
|
|||||||
void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp);
|
void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp);
|
||||||
|
|
||||||
// Clipboard
|
// Clipboard
|
||||||
void _glfwPlatformSetClipboardString(const char* string);
|
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string);
|
||||||
size_t _glfwPlatformGetClipboardString(char *data, size_t size);
|
size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char *data, size_t size);
|
||||||
|
|
||||||
// Joystick
|
// Joystick
|
||||||
int _glfwPlatformGetJoystickParam(int joy, int param);
|
int _glfwPlatformGetJoystickParam(int joy, int param);
|
||||||
|
@ -93,7 +93,7 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent* request)
|
|||||||
// Set the clipboard contents
|
// Set the clipboard contents
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSetClipboardString(const char* string)
|
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
|
||||||
{
|
{
|
||||||
size_t size = strlen(string) + 1;
|
size_t size = strlen(string) + 1;
|
||||||
|
|
||||||
@ -115,10 +115,10 @@ void _glfwPlatformSetClipboardString(const char* string)
|
|||||||
|
|
||||||
// Set the selection owner to our active window
|
// Set the selection owner to our active window
|
||||||
XSetSelectionOwner(_glfwLibrary.X11.display, XA_PRIMARY,
|
XSetSelectionOwner(_glfwLibrary.X11.display, XA_PRIMARY,
|
||||||
_glfwLibrary.activeWindow->X11.handle, CurrentTime);
|
window->X11.handle, CurrentTime);
|
||||||
XSetSelectionOwner(_glfwLibrary.X11.display,
|
XSetSelectionOwner(_glfwLibrary.X11.display,
|
||||||
_glfwLibrary.X11.selection.atom,
|
_glfwLibrary.X11.selection.atom,
|
||||||
_glfwLibrary.activeWindow->X11.handle, CurrentTime);
|
window->X11.handle, CurrentTime);
|
||||||
XFlush(_glfwLibrary.X11.display);
|
XFlush(_glfwLibrary.X11.display);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,16 +127,13 @@ void _glfwPlatformSetClipboardString(const char* string)
|
|||||||
// Return the current clipboard contents
|
// Return the current clipboard contents
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
size_t _glfwPlatformGetClipboardString(char* data, size_t size)
|
size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* data, size_t size)
|
||||||
{
|
{
|
||||||
size_t len, rembytes, dummy;
|
size_t len, rembytes, dummy;
|
||||||
unsigned char* d;
|
unsigned char* d;
|
||||||
int i, fmt;
|
int i, fmt;
|
||||||
Atom type;
|
Atom type;
|
||||||
|
|
||||||
// Get the currently active window
|
|
||||||
Window window = _glfwLibrary.activeWindow->X11.handle;
|
|
||||||
|
|
||||||
for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++)
|
for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++)
|
||||||
{
|
{
|
||||||
// Specify the format we would like.
|
// Specify the format we would like.
|
||||||
@ -147,7 +144,7 @@ size_t _glfwPlatformGetClipboardString(char* data, size_t size)
|
|||||||
XConvertSelection(_glfwLibrary.X11.display,
|
XConvertSelection(_glfwLibrary.X11.display,
|
||||||
_glfwLibrary.X11.selection.atom,
|
_glfwLibrary.X11.selection.atom,
|
||||||
_glfwLibrary.X11.selection.request,
|
_glfwLibrary.X11.selection.request,
|
||||||
None, window, CurrentTime);
|
None, window->X11.handle, CurrentTime);
|
||||||
XFlush(_glfwLibrary.X11.display);
|
XFlush(_glfwLibrary.X11.display);
|
||||||
|
|
||||||
// Process pending events until we get a SelectionNotify.
|
// Process pending events until we get a SelectionNotify.
|
||||||
@ -176,7 +173,7 @@ size_t _glfwPlatformGetClipboardString(char* data, size_t size)
|
|||||||
|
|
||||||
// Check the length of data to receive (rembytes)
|
// Check the length of data to receive (rembytes)
|
||||||
XGetWindowProperty(_glfwLibrary.X11.display,
|
XGetWindowProperty(_glfwLibrary.X11.display,
|
||||||
window,
|
window->X11.handle,
|
||||||
_glfwLibrary.X11.selection.request,
|
_glfwLibrary.X11.selection.request,
|
||||||
0, 0,
|
0, 0,
|
||||||
0,
|
0,
|
||||||
@ -190,7 +187,7 @@ size_t _glfwPlatformGetClipboardString(char* data, size_t size)
|
|||||||
if (rembytes > 0)
|
if (rembytes > 0)
|
||||||
{
|
{
|
||||||
int result = XGetWindowProperty(_glfwLibrary.X11.display,
|
int result = XGetWindowProperty(_glfwLibrary.X11.display,
|
||||||
window,
|
window->X11.handle,
|
||||||
_glfwLibrary.X11.selection.request,
|
_glfwLibrary.X11.selection.request,
|
||||||
0, rembytes,
|
0, rembytes,
|
||||||
0,
|
0,
|
||||||
|
@ -64,7 +64,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
|||||||
|
|
||||||
printf("Paste test.\n");
|
printf("Paste test.\n");
|
||||||
|
|
||||||
size = glfwGetClipboardString(buffer, sizeof(buffer));
|
size = glfwGetClipboardString(window, buffer, sizeof(buffer));
|
||||||
if (size >= sizeof(buffer))
|
if (size >= sizeof(buffer))
|
||||||
printf("Buffer wasn't big enough to hold clipboard data.\n");
|
printf("Buffer wasn't big enough to hold clipboard data.\n");
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
|||||||
if (control_is_down(window))
|
if (control_is_down(window))
|
||||||
{
|
{
|
||||||
const char* string = "Hello GLFW World!";
|
const char* string = "Hello GLFW World!";
|
||||||
glfwSetClipboardString(string);
|
glfwSetClipboardString(window, string);
|
||||||
printf("Setting clipboard to: %s\n", string);
|
printf("Setting clipboard to: %s\n", string);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user