2011-09-21 09:09:47 +00:00
|
|
|
//========================================================================
|
|
|
|
// GLFW - An OpenGL library
|
2012-08-28 13:03:57 +00:00
|
|
|
// Platform: X11
|
2011-09-21 09:09:47 +00:00
|
|
|
// API version: 3.0
|
|
|
|
// WWW: http://www.glfw.org/
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2010 Camilla Berglund <elmindreda@elmindreda.org>
|
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2011-09-21 14:43:28 +00:00
|
|
|
#include <stdio.h>
|
2011-09-21 09:09:47 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <string.h>
|
2011-09-21 14:43:28 +00:00
|
|
|
#include <stdlib.h>
|
2011-09-21 09:09:47 +00:00
|
|
|
|
|
|
|
|
2012-03-28 13:05:17 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-09-22 11:03:45 +00:00
|
|
|
//========================================================================
|
2012-04-11 21:32:50 +00:00
|
|
|
// Save the contents of the specified property
|
2011-09-22 11:03:45 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2012-04-11 21:32:50 +00:00
|
|
|
GLboolean _glfwReadSelection(XSelectionEvent* request)
|
2011-09-22 11:03:45 +00:00
|
|
|
{
|
2012-04-11 21:32:50 +00:00
|
|
|
Atom actualType;
|
|
|
|
int actualFormat;
|
|
|
|
unsigned long itemCount, bytesAfter;
|
|
|
|
char* data;
|
2012-04-09 13:12:59 +00:00
|
|
|
|
2012-04-11 21:32:50 +00:00
|
|
|
if (request->property == None)
|
|
|
|
return GL_FALSE;
|
|
|
|
|
|
|
|
XGetWindowProperty(_glfwLibrary.X11.display,
|
|
|
|
request->requestor,
|
|
|
|
request->property,
|
|
|
|
0, LONG_MAX,
|
|
|
|
False,
|
|
|
|
request->target,
|
|
|
|
&actualType,
|
|
|
|
&actualFormat,
|
|
|
|
&itemCount,
|
|
|
|
&bytesAfter,
|
|
|
|
(unsigned char**) &data);
|
|
|
|
|
|
|
|
if (actualType == None)
|
|
|
|
return GL_FALSE;
|
|
|
|
|
|
|
|
free(_glfwLibrary.X11.selection.string);
|
|
|
|
_glfwLibrary.X11.selection.string = strdup(data);
|
|
|
|
|
|
|
|
XFree(data);
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Set the specified property to the contents of the requested selection
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
Atom _glfwWriteSelection(XSelectionRequestEvent* request)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Atom property = request->property;
|
|
|
|
|
|
|
|
if (property == None)
|
|
|
|
property = _glfwLibrary.X11.selection.property;
|
|
|
|
|
|
|
|
if (request->target == _glfwLibrary.X11.selection.targets)
|
2011-09-22 11:03:45 +00:00
|
|
|
{
|
2012-04-11 21:32:50 +00:00
|
|
|
// The list of supported targets was requested
|
|
|
|
|
2011-09-22 11:03:45 +00:00
|
|
|
XChangeProperty(_glfwLibrary.X11.display,
|
2012-04-09 13:12:59 +00:00
|
|
|
request->requestor,
|
2012-04-11 21:32:50 +00:00
|
|
|
property,
|
|
|
|
XA_ATOM,
|
|
|
|
32,
|
2012-04-09 13:12:59 +00:00
|
|
|
PropModeReplace,
|
2012-04-11 21:32:50 +00:00
|
|
|
(unsigned char*) _glfwLibrary.X11.selection.formats,
|
|
|
|
_GLFW_CLIPBOARD_FORMAT_COUNT);
|
|
|
|
|
|
|
|
return property;
|
2011-09-22 11:03:45 +00:00
|
|
|
}
|
2012-04-11 21:32:50 +00:00
|
|
|
|
|
|
|
for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++)
|
2011-09-22 11:03:45 +00:00
|
|
|
{
|
2012-04-11 21:32:50 +00:00
|
|
|
if (request->target == _glfwLibrary.X11.selection.formats[i])
|
|
|
|
{
|
2012-04-11 21:53:47 +00:00
|
|
|
// The requested target is one we support
|
2012-04-11 21:32:50 +00:00
|
|
|
|
|
|
|
XChangeProperty(_glfwLibrary.X11.display,
|
|
|
|
request->requestor,
|
|
|
|
property,
|
|
|
|
request->target,
|
|
|
|
8,
|
|
|
|
PropModeReplace,
|
|
|
|
(unsigned char*) _glfwLibrary.X11.selection.string,
|
|
|
|
strlen(_glfwLibrary.X11.selection.string));
|
|
|
|
|
|
|
|
return property;
|
|
|
|
}
|
2011-09-22 11:03:45 +00:00
|
|
|
}
|
2012-03-28 13:05:17 +00:00
|
|
|
|
2012-04-11 21:32:50 +00:00
|
|
|
return None;
|
2011-09-22 11:03:45 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 13:05:17 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-09-21 09:09:47 +00:00
|
|
|
//========================================================================
|
|
|
|
// Set the clipboard contents
|
|
|
|
//========================================================================
|
|
|
|
|
2012-04-09 14:00:54 +00:00
|
|
|
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
|
2011-09-21 09:09:47 +00:00
|
|
|
{
|
2012-04-11 21:32:50 +00:00
|
|
|
// Store the new string in preparation for a selection request event
|
2012-04-09 22:52:21 +00:00
|
|
|
free(_glfwLibrary.X11.selection.string);
|
2012-04-11 21:32:50 +00:00
|
|
|
_glfwLibrary.X11.selection.string = strdup(string);
|
2011-09-22 11:03:45 +00:00
|
|
|
|
2012-04-11 21:32:50 +00:00
|
|
|
// Set the specified window as owner of the selection
|
2011-09-22 11:03:45 +00:00
|
|
|
XSetSelectionOwner(_glfwLibrary.X11.display,
|
2012-04-09 13:00:52 +00:00
|
|
|
_glfwLibrary.X11.selection.atom,
|
2012-04-09 14:00:54 +00:00
|
|
|
window->X11.handle, CurrentTime);
|
2011-09-21 09:09:47 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 13:05:17 +00:00
|
|
|
|
2011-09-21 09:09:47 +00:00
|
|
|
//========================================================================
|
|
|
|
// Return the current clipboard contents
|
|
|
|
//========================================================================
|
|
|
|
|
2012-04-11 22:51:58 +00:00
|
|
|
const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
|
2011-09-21 09:09:47 +00:00
|
|
|
{
|
2012-04-11 21:32:50 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
_glfwLibrary.X11.selection.status = _GLFW_CONVERSION_INACTIVE;
|
2011-09-22 11:03:45 +00:00
|
|
|
|
2012-04-09 13:21:54 +00:00
|
|
|
for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++)
|
2011-09-21 14:43:28 +00:00
|
|
|
{
|
2012-04-11 21:32:50 +00:00
|
|
|
// Request conversion to the selected format
|
|
|
|
_glfwLibrary.X11.selection.target =
|
2012-04-09 13:21:54 +00:00
|
|
|
_glfwLibrary.X11.selection.formats[i];
|
2011-09-22 11:03:45 +00:00
|
|
|
|
2012-04-09 13:00:52 +00:00
|
|
|
XConvertSelection(_glfwLibrary.X11.display,
|
|
|
|
_glfwLibrary.X11.selection.atom,
|
2012-04-11 21:32:50 +00:00
|
|
|
_glfwLibrary.X11.selection.target,
|
|
|
|
_glfwLibrary.X11.selection.property,
|
|
|
|
window->X11.handle, CurrentTime);
|
2011-09-22 11:03:45 +00:00
|
|
|
|
2012-04-09 23:15:50 +00:00
|
|
|
// Process the resulting SelectionNotify event
|
|
|
|
XSync(_glfwLibrary.X11.display, False);
|
2012-04-11 21:32:50 +00:00
|
|
|
while (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_INACTIVE)
|
|
|
|
_glfwPlatformWaitEvents();
|
2011-09-22 11:03:45 +00:00
|
|
|
|
2012-04-11 21:32:50 +00:00
|
|
|
if (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_SUCCEEDED)
|
2011-09-21 14:43:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-11 21:32:50 +00:00
|
|
|
if (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_FAILED)
|
2011-09-22 11:03:45 +00:00
|
|
|
{
|
2012-04-09 13:54:36 +00:00
|
|
|
_glfwSetError(GLFW_FORMAT_UNAVAILABLE,
|
2012-08-28 13:03:57 +00:00
|
|
|
"X11: Failed to convert selection to string");
|
2012-04-11 22:51:58 +00:00
|
|
|
return NULL;
|
2011-09-22 11:03:45 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 22:51:58 +00:00
|
|
|
return _glfwLibrary.X11.selection.string;
|
2011-09-21 09:09:47 +00:00
|
|
|
}
|
|
|
|
|