2011-09-21 05:09:47 -04:00
|
|
|
//========================================================================
|
|
|
|
// GLFW - An OpenGL library
|
2012-08-28 09:03:57 -04:00
|
|
|
// Platform: X11
|
2011-09-21 05:09:47 -04: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 10:43:28 -04:00
|
|
|
#include <stdio.h>
|
2011-09-21 05:09:47 -04:00
|
|
|
#include <limits.h>
|
|
|
|
#include <string.h>
|
2011-09-21 10:43:28 -04:00
|
|
|
#include <stdlib.h>
|
2011-09-21 05:09:47 -04:00
|
|
|
|
|
|
|
|
2012-03-28 09:05:17 -04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-04-11 17:32:50 -04:00
|
|
|
// Set the specified property to the contents of the requested selection
|
2013-02-04 07:22:10 -05:00
|
|
|
//
|
2012-04-11 17:32:50 -04:00
|
|
|
Atom _glfwWriteSelection(XSelectionRequestEvent* request)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2013-01-30 18:26:37 -05:00
|
|
|
if (request->property == None)
|
|
|
|
{
|
|
|
|
// The requestor is a legacy client (ICCCM section 2.2)
|
|
|
|
return None;
|
|
|
|
}
|
2012-04-11 17:32:50 -04:00
|
|
|
|
2013-01-28 20:45:08 -05:00
|
|
|
if (request->target == _glfw.x11.TARGETS)
|
2011-09-22 07:03:45 -04:00
|
|
|
{
|
2012-04-11 17:32:50 -04:00
|
|
|
// The list of supported targets was requested
|
|
|
|
|
2013-01-01 19:40:42 -05:00
|
|
|
XChangeProperty(_glfw.x11.display,
|
2012-04-09 09:12:59 -04:00
|
|
|
request->requestor,
|
2013-01-30 18:26:37 -05:00
|
|
|
request->property,
|
2012-04-11 17:32:50 -04:00
|
|
|
XA_ATOM,
|
|
|
|
32,
|
2012-04-09 09:12:59 -04:00
|
|
|
PropModeReplace,
|
2013-01-01 19:40:42 -05:00
|
|
|
(unsigned char*) _glfw.x11.selection.formats,
|
2012-04-11 17:32:50 -04:00
|
|
|
_GLFW_CLIPBOARD_FORMAT_COUNT);
|
|
|
|
|
2013-01-30 18:26:37 -05:00
|
|
|
return request->property;
|
2011-09-22 07:03:45 -04:00
|
|
|
}
|
2012-04-11 17:32:50 -04:00
|
|
|
|
2013-04-29 06:26:25 -04:00
|
|
|
if (request->target == _glfw.x11.MULTIPLE)
|
|
|
|
{
|
|
|
|
// Multiple conversions were requested
|
|
|
|
|
|
|
|
Atom* targets;
|
|
|
|
unsigned long i, count;
|
|
|
|
|
|
|
|
count = _glfwGetWindowProperty(request->requestor,
|
|
|
|
request->property,
|
|
|
|
XA_ATOM,
|
|
|
|
(unsigned char**) &targets);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i += 2)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < _GLFW_CLIPBOARD_FORMAT_COUNT; j++)
|
|
|
|
{
|
|
|
|
if (targets[i] == _glfw.x11.selection.formats[j])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j < _GLFW_CLIPBOARD_FORMAT_COUNT)
|
|
|
|
{
|
|
|
|
XChangeProperty(_glfw.x11.display,
|
|
|
|
request->requestor,
|
|
|
|
targets[i + 1],
|
|
|
|
targets[i],
|
|
|
|
8,
|
|
|
|
PropModeReplace,
|
|
|
|
(unsigned char*) _glfw.x11.selection.string,
|
|
|
|
strlen(_glfw.x11.selection.string));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
targets[i + 1] = None;
|
|
|
|
}
|
|
|
|
|
|
|
|
XChangeProperty(_glfw.x11.display,
|
|
|
|
request->requestor,
|
|
|
|
request->property,
|
|
|
|
request->target,
|
|
|
|
32,
|
|
|
|
PropModeReplace,
|
|
|
|
(unsigned char*) targets,
|
|
|
|
count);
|
|
|
|
|
|
|
|
XFree(targets);
|
|
|
|
|
|
|
|
return request->property;
|
|
|
|
}
|
|
|
|
|
2012-04-11 17:32:50 -04:00
|
|
|
for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++)
|
2011-09-22 07:03:45 -04:00
|
|
|
{
|
2013-01-01 19:40:42 -05:00
|
|
|
if (request->target == _glfw.x11.selection.formats[i])
|
2012-04-11 17:32:50 -04:00
|
|
|
{
|
2012-04-11 17:53:47 -04:00
|
|
|
// The requested target is one we support
|
2012-04-11 17:32:50 -04:00
|
|
|
|
2013-01-01 19:40:42 -05:00
|
|
|
XChangeProperty(_glfw.x11.display,
|
2012-04-11 17:32:50 -04:00
|
|
|
request->requestor,
|
2013-01-30 18:26:37 -05:00
|
|
|
request->property,
|
2012-04-11 17:32:50 -04:00
|
|
|
request->target,
|
|
|
|
8,
|
|
|
|
PropModeReplace,
|
2013-01-01 19:40:42 -05:00
|
|
|
(unsigned char*) _glfw.x11.selection.string,
|
|
|
|
strlen(_glfw.x11.selection.string));
|
2012-04-11 17:32:50 -04:00
|
|
|
|
2013-01-30 18:26:37 -05:00
|
|
|
return request->property;
|
2012-04-11 17:32:50 -04:00
|
|
|
}
|
2011-09-22 07:03:45 -04:00
|
|
|
}
|
2012-03-28 09:05:17 -04:00
|
|
|
|
2012-04-11 17:32:50 -04:00
|
|
|
return None;
|
2011-09-22 07:03:45 -04:00
|
|
|
}
|
|
|
|
|
2012-03-28 09:05:17 -04:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-04-09 10:00:54 -04:00
|
|
|
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
|
2011-09-21 05:09:47 -04:00
|
|
|
{
|
2013-01-01 19:40:42 -05:00
|
|
|
free(_glfw.x11.selection.string);
|
|
|
|
_glfw.x11.selection.string = strdup(string);
|
2011-09-22 07:03:45 -04:00
|
|
|
|
2013-01-01 19:40:42 -05:00
|
|
|
XSetSelectionOwner(_glfw.x11.display,
|
2013-01-28 20:45:08 -05:00
|
|
|
_glfw.x11.CLIPBOARD,
|
2013-01-01 19:40:42 -05:00
|
|
|
window->x11.handle, CurrentTime);
|
2013-01-30 18:26:37 -05:00
|
|
|
|
|
|
|
if (XGetSelectionOwner(_glfw.x11.display, _glfw.x11.CLIPBOARD) !=
|
|
|
|
window->x11.handle)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"X11: Failed to become owner of the clipboard selection");
|
|
|
|
}
|
2011-09-21 05:09:47 -04:00
|
|
|
}
|
|
|
|
|
2012-04-11 18:51:58 -04:00
|
|
|
const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
|
2011-09-21 05:09:47 -04:00
|
|
|
{
|
2012-04-11 17:32:50 -04:00
|
|
|
int i;
|
|
|
|
|
2013-01-30 18:26:37 -05:00
|
|
|
if (_glfwFindWindowByHandle(XGetSelectionOwner(_glfw.x11.display,
|
|
|
|
_glfw.x11.CLIPBOARD)))
|
|
|
|
{
|
|
|
|
// Instead of doing a large number of X round-trips just to put this
|
|
|
|
// string into a window property and then read it back, just return it
|
|
|
|
return _glfw.x11.selection.string;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(_glfw.x11.selection.string);
|
|
|
|
_glfw.x11.selection.string = NULL;
|
2011-09-22 07:03:45 -04:00
|
|
|
|
2012-04-09 09:21:54 -04:00
|
|
|
for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++)
|
2011-09-21 10:43:28 -04:00
|
|
|
{
|
2013-01-30 18:26:37 -05:00
|
|
|
Atom actualType;
|
|
|
|
int actualFormat;
|
|
|
|
unsigned long itemCount, bytesAfter;
|
|
|
|
char* data;
|
|
|
|
XEvent event;
|
2011-09-22 07:03:45 -04:00
|
|
|
|
2013-01-01 19:40:42 -05:00
|
|
|
XConvertSelection(_glfw.x11.display,
|
2013-01-28 20:45:08 -05:00
|
|
|
_glfw.x11.CLIPBOARD,
|
2013-01-30 18:26:37 -05:00
|
|
|
_glfw.x11.selection.formats[i],
|
2013-01-01 19:40:42 -05:00
|
|
|
_glfw.x11.selection.property,
|
|
|
|
window->x11.handle, CurrentTime);
|
2011-09-22 07:03:45 -04:00
|
|
|
|
2013-01-30 18:26:37 -05:00
|
|
|
// XCheckTypedEvent is used instead of XIfEvent in order not to lock
|
|
|
|
// other threads out from the display during the entire wait period
|
|
|
|
while (!XCheckTypedEvent(_glfw.x11.display, SelectionNotify, &event))
|
|
|
|
;
|
|
|
|
|
|
|
|
if (event.xselection.property == None)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
XGetWindowProperty(_glfw.x11.display,
|
|
|
|
event.xselection.requestor,
|
|
|
|
event.xselection.property,
|
|
|
|
0, LONG_MAX,
|
|
|
|
False,
|
|
|
|
event.xselection.target,
|
|
|
|
&actualType,
|
|
|
|
&actualFormat,
|
|
|
|
&itemCount,
|
|
|
|
&bytesAfter,
|
|
|
|
(unsigned char**) &data);
|
|
|
|
|
|
|
|
XDeleteProperty(_glfw.x11.display,
|
|
|
|
event.xselection.requestor,
|
|
|
|
event.xselection.property);
|
|
|
|
|
|
|
|
if (actualType == event.xselection.target)
|
|
|
|
_glfw.x11.selection.string = strdup(data);
|
|
|
|
|
|
|
|
XFree(data);
|
2011-09-22 07:03:45 -04:00
|
|
|
|
2013-01-30 18:26:37 -05:00
|
|
|
if (_glfw.x11.selection.string)
|
2011-09-21 10:43:28 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-30 18:26:37 -05:00
|
|
|
if (_glfw.x11.selection.string == NULL)
|
2011-09-22 07:03:45 -04:00
|
|
|
{
|
2012-12-31 15:05:28 -05:00
|
|
|
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
|
|
|
"X11: Failed to convert selection to string");
|
2011-09-22 07:03:45 -04:00
|
|
|
}
|
|
|
|
|
2013-01-01 19:40:42 -05:00
|
|
|
return _glfw.x11.selection.string;
|
2011-09-21 05:09:47 -04:00
|
|
|
}
|
|
|
|
|