Applied coding conventions.

This commit is contained in:
Camilla Berglund 2012-03-28 15:05:17 +02:00
parent d022e54934
commit 7f470065fc
2 changed files with 34 additions and 21 deletions

View File

@ -76,3 +76,4 @@ GLFWAPI size_t glfwGetClipboardData(void *data, size_t size, int format)
return _glfwPlatformGetClipboardData(data, size, format); return _glfwPlatformGetClipboardData(data, size, format);
} }

View File

@ -36,18 +36,15 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//======================================================================== //========================================================================
// Get the corresponding X11 format for a given GLFW format. // Get the corresponding X11 format for a given GLFW format.
//======================================================================== //========================================================================
static Atom *getInternalFormat(int fmt) static Atom* getInternalFormat(int format)
{ {
// Get the necessary atoms // Get the necessary atoms
switch (fmt) switch (format)
{ {
case GLFW_CLIPBOARD_FORMAT_STRING: case GLFW_CLIPBOARD_FORMAT_STRING:
return _glfwLibrary.X11.selection.atoms.string; return _glfwLibrary.X11.selection.atoms.string;
@ -56,13 +53,18 @@ static Atom *getInternalFormat(int fmt)
} }
} }
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//======================================================================== //========================================================================
// X11 selection request event // X11 selection request event
//======================================================================== //========================================================================
Atom _glfwSelectionRequest(XSelectionRequestEvent *request) Atom _glfwSelectionRequest(XSelectionRequestEvent* request)
{ {
Atom *atoms = _glfwLibrary.X11.selection.atoms.string; Atom* atoms = _glfwLibrary.X11.selection.atoms.string;
if (request->target == XA_STRING) if (request->target == XA_STRING)
{ {
// TODO: ISO Latin-1 specific characters don't get converted // TODO: ISO Latin-1 specific characters don't get converted
@ -73,7 +75,7 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent *request)
request->target, request->target,
8, 8,
PropModeReplace, PropModeReplace,
(unsigned char *)_glfwLibrary.X11.selection.clipboard.string, (unsigned char*) _glfwLibrary.X11.selection.clipboard.string,
8); 8);
} }
else if (request->target == atoms[_GLFW_STRING_ATOM_COMPOUND] || else if (request->target == atoms[_GLFW_STRING_ATOM_COMPOUND] ||
@ -85,7 +87,7 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent *request)
request->target, request->target,
8, 8,
PropModeReplace, PropModeReplace,
(unsigned char *)_glfwLibrary.X11.selection.clipboard.string, (unsigned char*) _glfwLibrary.X11.selection.clipboard.string,
_glfwLibrary.X11.selection.clipboard.stringlen); _glfwLibrary.X11.selection.clipboard.stringlen);
} }
else else
@ -93,9 +95,15 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent *request)
// TODO: Should we set an error? Probably not. // TODO: Should we set an error? Probably not.
return None; return None;
} }
return request->target; return request->target;
} }
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//======================================================================== //========================================================================
// Set the clipboard contents // Set the clipboard contents
//======================================================================== //========================================================================
@ -132,14 +140,15 @@ void _glfwPlatformSetClipboardData(void *data, size_t size, int format)
// 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); _glfwLibrary.activeWindow->X11.handle, CurrentTime);
XSetSelectionOwner(_glfwLibrary.X11.display, XSetSelectionOwner(_glfwLibrary.X11.display,
_glfwLibrary.X11.selection.atoms.clipboard _glfwLibrary.X11.selection.atoms.clipboard
[_GLFW_CLIPBOARD_ATOM_CLIPBOARD], [_GLFW_CLIPBOARD_ATOM_CLIPBOARD],
_glfwLibrary.activeWindow->X11.handle, CurrentTime); _glfwLibrary.activeWindow->X11.handle, CurrentTime);
XFlush(_glfwLibrary.X11.display); XFlush(_glfwLibrary.X11.display);
} }
//======================================================================== //========================================================================
// Return the current clipboard contents // Return the current clipboard contents
//======================================================================== //========================================================================
@ -155,16 +164,16 @@ size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format)
// format with preference for more appropriate formats first // format with preference for more appropriate formats first
Atom *xcbrd = _glfwLibrary.X11.selection.atoms.clipboard; Atom *xcbrd = _glfwLibrary.X11.selection.atoms.clipboard;
Atom *xcbrdend = _glfwLibrary.X11.selection.atoms.clipboard + Atom *xcbrdend = _glfwLibrary.X11.selection.atoms.clipboard +
_GLFW_CLIPBOARD_ATOM_COUNT; _GLFW_CLIPBOARD_ATOM_COUNT;
Atom *xfmt = getInternalFormat(format); Atom *xfmt = getInternalFormat(format);
Atom *xfmtend = xfmt + _GLFW_STRING_ATOM_COUNT; Atom *xfmtend = xfmt + _GLFW_STRING_ATOM_COUNT;
// Get the currently active window // Get the currently active window
Window window = _glfwLibrary.activeWindow->X11.handle; Window window = _glfwLibrary.activeWindow->X11.handle;
for (; xcbrd != xcbrdend; xcbrd++) for ( ; xcbrd != xcbrdend; xcbrd++)
{ {
for (; xfmt != xfmtend; xfmt++) for ( ; xfmt != xfmtend; xfmt++)
{ {
// Specify the format we would like. // Specify the format we would like.
_glfwLibrary.X11.selection.request = *xfmt; _glfwLibrary.X11.selection.request = *xfmt;
@ -218,21 +227,23 @@ size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format)
if (rembytes > 0) if (rembytes > 0)
{ {
int result = XGetWindowProperty(_glfwLibrary.X11.display, window, int result = XGetWindowProperty(_glfwLibrary.X11.display, window,
*xfmt, 0, rembytes, 0, *xfmt, 0, rembytes, 0,
AnyPropertyType, &type, &fmt, AnyPropertyType, &type, &fmt,
&len, &dummy, &d); &len, &dummy, &d);
if (result == Success) if (result == Success)
{ {
size_t s = size - 1 > rembytes ? rembytes : size - 1; size_t s = size - 1 > rembytes ? rembytes : size - 1;
// Copy the data out. // Copy the data out.
memcpy(data, d, s); memcpy(data, d, s);
// Null-terminate strings. // Null-terminate strings.
if (format == GLFW_CLIPBOARD_FORMAT_STRING) if (format == GLFW_CLIPBOARD_FORMAT_STRING)
{
((char *)data)[s] = '\0'; ((char *)data)[s] = '\0';
}
// Free the data allocated using X11. // Free the data allocated using X11.
XFree(d); XFree(d);
// Return the actual number of bytes. // Return the actual number of bytes.
return rembytes; return rembytes;
} }
@ -243,6 +254,7 @@ size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format)
return 0; return 0;
} }
} }
return 0; return 0;
} }