mirror of
https://github.com/glfw/glfw.git
synced 2024-11-25 19:42:00 +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);
|
||||
|
||||
/* Clipboard */
|
||||
GLFWAPI void glfwSetClipboardString(const char* data);
|
||||
GLFWAPI size_t glfwGetClipboardString(char* data, size_t size);
|
||||
GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* data);
|
||||
GLFWAPI size_t glfwGetClipboardString(GLFWwindow window, char* data, size_t size);
|
||||
|
||||
/* Time */
|
||||
GLFWAPI double glfwGetTime(void);
|
||||
|
@ -41,15 +41,17 @@
|
||||
// Set the clipboard contents
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetClipboardString(const char* string)
|
||||
GLFWAPI void glfwSetClipboardString(GLFWwindow handle, const char* string)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwPlatformSetClipboardString(string);
|
||||
_glfwPlatformSetClipboardString(window, string);
|
||||
}
|
||||
|
||||
|
||||
@ -57,8 +59,10 @@ GLFWAPI void glfwSetClipboardString(const char* string)
|
||||
// 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)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
@ -68,6 +72,6 @@ GLFWAPI size_t glfwGetClipboardString(char* string, size_t size)
|
||||
if (!string || !size)
|
||||
return 0;
|
||||
|
||||
return _glfwPlatformGetClipboardString(string, size);
|
||||
return _glfwPlatformGetClipboardString(window, string, size);
|
||||
}
|
||||
|
||||
|
@ -289,8 +289,8 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp);
|
||||
void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp);
|
||||
|
||||
// Clipboard
|
||||
void _glfwPlatformSetClipboardString(const char* string);
|
||||
size_t _glfwPlatformGetClipboardString(char *data, size_t size);
|
||||
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string);
|
||||
size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char *data, size_t size);
|
||||
|
||||
// Joystick
|
||||
int _glfwPlatformGetJoystickParam(int joy, int param);
|
||||
|
@ -93,7 +93,7 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent* request)
|
||||
// Set the clipboard contents
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformSetClipboardString(const char* string)
|
||||
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
|
||||
{
|
||||
size_t size = strlen(string) + 1;
|
||||
|
||||
@ -115,10 +115,10 @@ void _glfwPlatformSetClipboardString(const char* string)
|
||||
|
||||
// Set the selection owner to our active window
|
||||
XSetSelectionOwner(_glfwLibrary.X11.display, XA_PRIMARY,
|
||||
_glfwLibrary.activeWindow->X11.handle, CurrentTime);
|
||||
window->X11.handle, CurrentTime);
|
||||
XSetSelectionOwner(_glfwLibrary.X11.display,
|
||||
_glfwLibrary.X11.selection.atom,
|
||||
_glfwLibrary.activeWindow->X11.handle, CurrentTime);
|
||||
window->X11.handle, CurrentTime);
|
||||
XFlush(_glfwLibrary.X11.display);
|
||||
}
|
||||
|
||||
@ -127,16 +127,13 @@ void _glfwPlatformSetClipboardString(const char* string)
|
||||
// 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;
|
||||
unsigned char* d;
|
||||
int i, fmt;
|
||||
Atom type;
|
||||
|
||||
// Get the currently active window
|
||||
Window window = _glfwLibrary.activeWindow->X11.handle;
|
||||
|
||||
for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++)
|
||||
{
|
||||
// Specify the format we would like.
|
||||
@ -147,7 +144,7 @@ size_t _glfwPlatformGetClipboardString(char* data, size_t size)
|
||||
XConvertSelection(_glfwLibrary.X11.display,
|
||||
_glfwLibrary.X11.selection.atom,
|
||||
_glfwLibrary.X11.selection.request,
|
||||
None, window, CurrentTime);
|
||||
None, window->X11.handle, CurrentTime);
|
||||
XFlush(_glfwLibrary.X11.display);
|
||||
|
||||
// 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)
|
||||
XGetWindowProperty(_glfwLibrary.X11.display,
|
||||
window,
|
||||
window->X11.handle,
|
||||
_glfwLibrary.X11.selection.request,
|
||||
0, 0,
|
||||
0,
|
||||
@ -190,7 +187,7 @@ size_t _glfwPlatformGetClipboardString(char* data, size_t size)
|
||||
if (rembytes > 0)
|
||||
{
|
||||
int result = XGetWindowProperty(_glfwLibrary.X11.display,
|
||||
window,
|
||||
window->X11.handle,
|
||||
_glfwLibrary.X11.selection.request,
|
||||
0, rembytes,
|
||||
0,
|
||||
|
@ -64,7 +64,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||
|
||||
printf("Paste test.\n");
|
||||
|
||||
size = glfwGetClipboardString(buffer, sizeof(buffer));
|
||||
size = glfwGetClipboardString(window, buffer, sizeof(buffer));
|
||||
if (size >= sizeof(buffer))
|
||||
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))
|
||||
{
|
||||
const char* string = "Hello GLFW World!";
|
||||
glfwSetClipboardString(string);
|
||||
glfwSetClipboardString(window, string);
|
||||
printf("Setting clipboard to: %s\n", string);
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user