Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pirvi-public
glfw
Commits
8d170c7f
Commit
8d170c7f
authored
Sep 09, 2014
by
Camilla Berglund
Browse files
Merged clipboard code into input.
parent
66c3af76
Changes
13
Hide whitespace changes
Inline
Side-by-side
include/GLFW/glfw3.h
View file @
8d170c7f
...
...
@@ -38,8 +38,6 @@ extern "C" {
* Doxygen documentation
*************************************************************************/
/*! @defgroup clipboard Clipboard support
*/
/*! @defgroup context Context handling
*/
/*! @defgroup error Error handling
...
...
@@ -2418,7 +2416,7 @@ GLFWAPI const char* glfwGetJoystickName(int joy);
*
* @sa glfwGetClipboardString
*
* @ingroup
clipboard
* @ingroup
input
*/
GLFWAPI
void
glfwSetClipboardString
(
GLFWwindow
*
window
,
const
char
*
string
);
...
...
@@ -2442,7 +2440,7 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string);
*
* @sa glfwSetClipboardString
*
* @ingroup
clipboard
* @ingroup
input
*/
GLFWAPI
const
char
*
glfwGetClipboardString
(
GLFWwindow
*
window
);
...
...
src/CMakeLists.txt
View file @
8d170c7f
...
...
@@ -8,33 +8,29 @@ add_definitions(-D_GLFW_USE_CONFIG_H)
set
(
common_HEADERS
"
${
GLFW_BINARY_DIR
}
/src/glfw_config.h"
internal.h
"
${
GLFW_SOURCE_DIR
}
/include/GLFW/glfw3.h"
"
${
GLFW_SOURCE_DIR
}
/include/GLFW/glfw3native.h"
)
set
(
common_SOURCES
clipboard.c
context.c init.c input.c joystick.c
monitor.c time.c
window.c
)
set
(
common_SOURCES context.c init.c input.c joystick.c
monitor.c time.c
window.c
)
if
(
_GLFW_COCOA
)
set
(
glfw_HEADERS
${
common_HEADERS
}
cocoa_platform.h iokit_joystick.h
posix_tls.h
)
set
(
glfw_SOURCES
${
common_SOURCES
}
cocoa_clipboard.m cocoa_init.m
cocoa_monitor.m cocoa_window.m iokit_joystick.m mach_time.c
posix_tls.c
)
set
(
glfw_SOURCES
${
common_SOURCES
}
cocoa_init.m cocoa_monitor.m
cocoa_window.m iokit_joystick.m mach_time.c posix_tls.c
)
elseif
(
_GLFW_WIN32
)
set
(
glfw_HEADERS
${
common_HEADERS
}
win32_platform.h win32_tls.h
winmm_joystick.h
)
set
(
glfw_SOURCES
${
common_SOURCES
}
win32_clipboard.c win32_init.c
win32_monitor.c win32_time.c win32_tls.c win32_window.c
winmm_joystick.c
)
set
(
glfw_SOURCES
${
common_SOURCES
}
win32_init.c win32_monitor.c win32_time.c
win32_tls.c win32_window.c winmm_joystick.c
)
elseif
(
_GLFW_X11
)
set
(
glfw_HEADERS
${
common_HEADERS
}
x11_platform.h xkb_unicode.h
linux_joystick.h posix_time.h posix_tls.h
)
set
(
glfw_SOURCES
${
common_SOURCES
}
x11_clipboard.c x11_init.c x11_monitor.c
x11_window.c xkb_unicode.c linux_joystick.c posix_time.c
posix_tls.c
)
set
(
glfw_SOURCES
${
common_SOURCES
}
x11_init.c x11_monitor.c x11_window.c
xkb_unicode.c linux_joystick.c posix_time.c posix_tls.c
)
elseif
(
_GLFW_WAYLAND
)
set
(
glfw_HEADERS
${
common_HEADERS
}
wl_platform.h linux_joystick.h
posix_time.h posix_tls.h xkb_unicode.h
)
set
(
glfw_SOURCES
${
common_SOURCES
}
wl_clipboard.c wl_init.c wl_monitor.c
wl_window.c linux_joystick.c posix_time.c posix_tls.c
xkb_unicode.c
)
set
(
glfw_SOURCES
${
common_SOURCES
}
wl_init.c wl_monitor.c wl_window.c
linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c
)
endif
()
if
(
_GLFW_EGL
)
...
...
src/clipboard.c
deleted
100644 → 0
View file @
66c3af76
//========================================================================
// GLFW 3.1 - 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"
#include
<math.h>
#include
<string.h>
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
GLFWAPI
void
glfwSetClipboardString
(
GLFWwindow
*
handle
,
const
char
*
string
)
{
_GLFWwindow
*
window
=
(
_GLFWwindow
*
)
handle
;
_GLFW_REQUIRE_INIT
();
_glfwPlatformSetClipboardString
(
window
,
string
);
}
GLFWAPI
const
char
*
glfwGetClipboardString
(
GLFWwindow
*
handle
)
{
_GLFWwindow
*
window
=
(
_GLFWwindow
*
)
handle
;
_GLFW_REQUIRE_INIT_OR_RETURN
(
NULL
);
return
_glfwPlatformGetClipboardString
(
window
);
}
src/cocoa_clipboard.m
deleted
100644 → 0
View file @
66c3af76
//========================================================================
// GLFW 3.1 OS X - 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"
#include
<limits.h>
#include
<string.h>
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
{
NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil];
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
[pasteboard declareTypes:types owner:nil];
[pasteboard setString:[NSString stringWithUTF8String:string]
forType:NSStringPboardType];
}
const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
{
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
if (![[pasteboard types] containsObject:NSStringPboardType])
{
_glfwInputError(GLFW_FORMAT_UNAVAILABLE, NULL);
return NULL;
}
NSString* object = [pasteboard stringForType:NSStringPboardType];
if (!object)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Cocoa: Failed to retrieve object from pasteboard");
return NULL;
}
free(_glfw.ns.clipboardString);
_glfw.ns.clipboardString = strdup([object UTF8String]);
return _glfw.ns.clipboardString;
}
src/cocoa_window.m
View file @
8d170c7f
...
...
@@ -26,6 +26,8 @@
#include
"internal.h"
#include
<string.h>
// Needed for _NSGetProgname
#include
<crt_externs.h>
...
...
@@ -1295,6 +1297,40 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
}
}
void
_glfwPlatformSetClipboardString
(
_GLFWwindow
*
window
,
const
char
*
string
)
{
NSArray
*
types
=
[
NSArray
arrayWithObjects
:
NSStringPboardType
,
nil
];
NSPasteboard
*
pasteboard
=
[
NSPasteboard
generalPasteboard
];
[
pasteboard
declareTypes
:
types
owner
:
nil
];
[
pasteboard
setString
:[
NSString
stringWithUTF8String
:
string
]
forType:
NSStringPboardType
];
}
const
char
*
_glfwPlatformGetClipboardString
(
_GLFWwindow
*
window
)
{
NSPasteboard
*
pasteboard
=
[
NSPasteboard
generalPasteboard
];
if
(
!
[[
pasteboard
types
]
containsObject
:
NSStringPboardType
])
{
_glfwInputError
(
GLFW_FORMAT_UNAVAILABLE
,
NULL
);
return
NULL
;
}
NSString
*
object
=
[
pasteboard
stringForType
:
NSStringPboardType
];
if
(
!
object
)
{
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Cocoa: Failed to retrieve object from pasteboard"
);
return
NULL
;
}
free
(
_glfw
.
ns
.
clipboardString
);
_glfw
.
ns
.
clipboardString
=
strdup
([
object
UTF8String
]);
return
_glfw
.
ns
.
clipboardString
;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW native API //////
...
...
src/input.c
View file @
8d170c7f
...
...
@@ -497,3 +497,17 @@ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* handle, GLFWdropfun cbfun)
return
cbfun
;
}
GLFWAPI
void
glfwSetClipboardString
(
GLFWwindow
*
handle
,
const
char
*
string
)
{
_GLFWwindow
*
window
=
(
_GLFWwindow
*
)
handle
;
_GLFW_REQUIRE_INIT
();
_glfwPlatformSetClipboardString
(
window
,
string
);
}
GLFWAPI
const
char
*
glfwGetClipboardString
(
GLFWwindow
*
handle
)
{
_GLFWwindow
*
window
=
(
_GLFWwindow
*
)
handle
;
_GLFW_REQUIRE_INIT_OR_RETURN
(
NULL
);
return
_glfwPlatformGetClipboardString
(
window
);
}
src/win32_clipboard.c
deleted
100644 → 0
View file @
66c3af76
//========================================================================
// GLFW 3.1 Win32 - 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"
#include
<limits.h>
#include
<string.h>
#include
<stdlib.h>
#include
<malloc.h>
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
void
_glfwPlatformSetClipboardString
(
_GLFWwindow
*
window
,
const
char
*
string
)
{
WCHAR
*
wideString
;
HANDLE
stringHandle
;
size_t
wideSize
;
wideString
=
_glfwCreateWideStringFromUTF8
(
string
);
if
(
!
wideString
)
{
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Win32: Failed to convert clipboard string to "
"wide string"
);
return
;
}
wideSize
=
(
wcslen
(
wideString
)
+
1
)
*
sizeof
(
WCHAR
);
stringHandle
=
GlobalAlloc
(
GMEM_MOVEABLE
,
wideSize
);
if
(
!
stringHandle
)
{
free
(
wideString
);
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Win32: Failed to allocate global handle for clipboard"
);
return
;
}
memcpy
(
GlobalLock
(
stringHandle
),
wideString
,
wideSize
);
GlobalUnlock
(
stringHandle
);
if
(
!
OpenClipboard
(
window
->
win32
.
handle
))
{
GlobalFree
(
stringHandle
);
free
(
wideString
);
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Win32: Failed to open clipboard"
);
return
;
}
EmptyClipboard
();
SetClipboardData
(
CF_UNICODETEXT
,
stringHandle
);
CloseClipboard
();
free
(
wideString
);
}
const
char
*
_glfwPlatformGetClipboardString
(
_GLFWwindow
*
window
)
{
HANDLE
stringHandle
;
if
(
!
IsClipboardFormatAvailable
(
CF_UNICODETEXT
))
{
_glfwInputError
(
GLFW_FORMAT_UNAVAILABLE
,
NULL
);
return
NULL
;
}
if
(
!
OpenClipboard
(
window
->
win32
.
handle
))
{
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Win32: Failed to open clipboard"
);
return
NULL
;
}
stringHandle
=
GetClipboardData
(
CF_UNICODETEXT
);
if
(
!
stringHandle
)
{
CloseClipboard
();
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Win32: Failed to retrieve clipboard data"
);
return
NULL
;
}
free
(
_glfw
.
win32
.
clipboardString
);
_glfw
.
win32
.
clipboardString
=
_glfwCreateUTF8FromWideString
(
GlobalLock
(
stringHandle
));
GlobalUnlock
(
stringHandle
);
CloseClipboard
();
if
(
!
_glfw
.
win32
.
clipboardString
)
{
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Win32: Failed to convert wide string to UTF-8"
);
return
NULL
;
}
return
_glfw
.
win32
.
clipboardString
;
}
src/win32_window.c
View file @
8d170c7f
...
...
@@ -29,6 +29,7 @@
#include
<stdlib.h>
#include
<malloc.h>
#include
<string.h>
#include
<windowsx.h>
#include
<shellapi.h>
...
...
@@ -1372,6 +1373,95 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
}
}
void
_glfwPlatformSetClipboardString
(
_GLFWwindow
*
window
,
const
char
*
string
)
{
WCHAR
*
wideString
;
HANDLE
stringHandle
;
size_t
wideSize
;
wideString
=
_glfwCreateWideStringFromUTF8
(
string
);
if
(
!
wideString
)
{
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Win32: Failed to convert clipboard string to "
"wide string"
);
return
;
}
wideSize
=
(
wcslen
(
wideString
)
+
1
)
*
sizeof
(
WCHAR
);
stringHandle
=
GlobalAlloc
(
GMEM_MOVEABLE
,
wideSize
);
if
(
!
stringHandle
)
{
free
(
wideString
);
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Win32: Failed to allocate global handle for clipboard"
);
return
;
}
memcpy
(
GlobalLock
(
stringHandle
),
wideString
,
wideSize
);
GlobalUnlock
(
stringHandle
);
if
(
!
OpenClipboard
(
window
->
win32
.
handle
))
{
GlobalFree
(
stringHandle
);
free
(
wideString
);
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Win32: Failed to open clipboard"
);
return
;
}
EmptyClipboard
();
SetClipboardData
(
CF_UNICODETEXT
,
stringHandle
);
CloseClipboard
();
free
(
wideString
);
}
const
char
*
_glfwPlatformGetClipboardString
(
_GLFWwindow
*
window
)
{
HANDLE
stringHandle
;
if
(
!
IsClipboardFormatAvailable
(
CF_UNICODETEXT
))
{
_glfwInputError
(
GLFW_FORMAT_UNAVAILABLE
,
NULL
);
return
NULL
;
}
if
(
!
OpenClipboard
(
window
->
win32
.
handle
))
{
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Win32: Failed to open clipboard"
);
return
NULL
;
}
stringHandle
=
GetClipboardData
(
CF_UNICODETEXT
);
if
(
!
stringHandle
)
{
CloseClipboard
();
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Win32: Failed to retrieve clipboard data"
);
return
NULL
;
}
free
(
_glfw
.
win32
.
clipboardString
);
_glfw
.
win32
.
clipboardString
=
_glfwCreateUTF8FromWideString
(
GlobalLock
(
stringHandle
));
GlobalUnlock
(
stringHandle
);
CloseClipboard
();
if
(
!
_glfw
.
win32
.
clipboardString
)
{
_glfwInputError
(
GLFW_PLATFORM_ERROR
,
"Win32: Failed to convert wide string to UTF-8"
);
return
NULL
;
}
return
_glfw
.
win32
.
clipboardString
;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW native API //////
...
...
src/wl_clipboard.c
deleted
100644 → 0
View file @
66c3af76
//========================================================================
// GLFW 3.1 Wayland - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2014 Jonas Ådahl <jadahl@gmail.com>
//
// 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"
#include
<stdio.h>
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
void
_glfwPlatformSetClipboardString
(
_GLFWwindow
*
window
,
const
char
*
string
)
{
// TODO
fprintf
(
stderr
,
"_glfwPlatformSetClipboardString not implemented yet
\n
"
);
}
const
char
*
_glfwPlatformGetClipboardString
(
_GLFWwindow
*
window
)
{
// TODO
fprintf
(
stderr
,
"_glfwPlatformGetClipboardString not implemented yet
\n
"
);
return
NULL
;
}
src/wl_window.c
View file @
8d170c7f
...
...
@@ -312,3 +312,16 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
fprintf
(
stderr
,
"_glfwPlatformSetCursor not implemented yet
\n
"
);
}
void
_glfwPlatformSetClipboardString
(
_GLFWwindow
*
window
,
const
char
*
string
)
{
// TODO
fprintf
(
stderr
,
"_glfwPlatformSetClipboardString not implemented yet
\n
"
);
}
const
char
*
_glfwPlatformGetClipboardString
(
_GLFWwindow
*
window
)
{
// TODO
fprintf
(
stderr
,
"_glfwPlatformGetClipboardString not implemented yet
\n
"
);
return
NULL
;
}
src/x11_clipboard.c
deleted
100644 → 0
View file @
66c3af76
//========================================================================
// GLFW 3.1 X11 - 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"
#include
<stdio.h>
#include
<limits.h>
#include
<string.h>
#include
<stdlib.h>
// Returns whether the event is a selection event
//
static
Bool
isSelectionEvent
(
Display
*
display
,
XEvent
*
event
,
XPointer
pointer
)
{
return
event
->
type
==
SelectionRequest
||
event
->
type
==
SelectionNotify
||
event
->
type
==
SelectionClear
;
}
// Set the specified property to the selection converted to the requested target
//
static
Atom
writeTargetToProperty
(
const
XSelectionRequestEvent
*
request
)
{
int
i
;
const
Atom
formats
[]
=
{
_glfw
.
x11
.
UTF8_STRING
,
_glfw
.
x11
.
COMPOUND_STRING
,
XA_STRING
};
const
int
formatCount
=
sizeof
(
formats
)
/
sizeof
(
formats
[
0
]);
if
(
request
->
property
==
None
)
{
// The requestor is a legacy client (ICCCM section 2.2)
// We don't support legacy clients, so fail here
return
None
;
}
if
(
request
->
target
==
_glfw
.
x11
.
TARGETS
)
{
// The list of supported targets was requested
const
Atom
targets
[]
=
{
_glfw
.
x11
.
TARGETS
,
_glfw
.
x11
.
MULTIPLE
,
_glfw
.
x11
.
UTF8_STRING
,
_glfw
.
x11
.
COMPOUND_STRING
,
XA_STRING
};
XChangeProperty
(
_glfw
.
x11
.
display
,
request
->
requestor
,
request
->
property
,