summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/sdl/sdlos_unix.cpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2015-11-08 12:56:12 +0100
committer Miodrag Milanovic <mmicko@gmail.com>2015-11-08 12:56:12 +0100
commit7c19aac60e12d6f5ea301bdb34d7826a01e0b06f (patch)
treef310d86aa2c6bfc19d115307dedde4eb0cd52dad /src/osd/sdl/sdlos_unix.cpp
parenta57b46ae933badd7441ce1644711dbb851e2b504 (diff)
Rename *.c -> *.cpp in our source (nw)
Diffstat (limited to 'src/osd/sdl/sdlos_unix.cpp')
-rw-r--r--src/osd/sdl/sdlos_unix.cpp148
1 files changed, 148 insertions, 0 deletions
diff --git a/src/osd/sdl/sdlos_unix.cpp b/src/osd/sdl/sdlos_unix.cpp
new file mode 100644
index 00000000000..5811e0c7dc5
--- /dev/null
+++ b/src/osd/sdl/sdlos_unix.cpp
@@ -0,0 +1,148 @@
+// license:BSD-3-Clause
+// copyright-holders:Olivier Galibert, R. Belmont
+//============================================================
+//
+// sdlos_*.c - OS specific low level code
+//
+// SDLMAME by Olivier Galibert and R. Belmont
+//
+//============================================================
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#ifdef SDLMAME_EMSCRIPTEN
+#include <emscripten.h>
+#endif
+
+#include "sdlinc.h"
+
+// MAME headers
+#include "osdcore.h"
+
+
+
+
+#if (SDLMAME_SDL2)
+
+//============================================================
+// osd_get_clipboard_text
+//============================================================
+
+char *osd_get_clipboard_text(void)
+{
+ char *result = NULL;
+
+ if (SDL_HasClipboardText())
+ {
+ char *temp = SDL_GetClipboardText();
+ result = (char *) osd_malloc_array(strlen(temp) + 1);
+ strcpy(result, temp);
+ SDL_free(temp);
+ }
+ return result;
+}
+
+#elif defined(SDL_VIDEO_DRIVER_X11) && defined(SDLMAME_X11)
+
+//============================================================
+// osd_get_clipboard_text
+//============================================================
+
+char *osd_get_clipboard_text(void)
+{
+ SDL_SysWMinfo info;
+ Display* display;
+ Window our_win;
+ Window selection_win;
+ Atom data_type;
+ int data_format;
+ unsigned long nitems;
+ unsigned long bytes_remaining;
+ unsigned char* prop;
+ char* result;
+ XEvent event;
+ Uint32 t0, t1;
+ Atom types[2];
+ int i;
+
+ /* get & validate SDL sys-wm info */
+ SDL_VERSION(&info.version);
+ if ( ! SDL_GetWMInfo( &info ) )
+ return NULL;
+ if ( info.subsystem != SDL_SYSWM_X11 )
+ return NULL;
+ if ( (display = info.info.x11.display) == NULL )
+ return NULL;
+ if ( (our_win = info.info.x11.window) == None )
+ return NULL;
+
+ /* request data to owner */
+ selection_win = XGetSelectionOwner( display, XA_PRIMARY );
+ if ( selection_win == None )
+ return NULL;
+
+ /* first, try UTF-8, then latin-1 */
+ types[0] = XInternAtom( display, "UTF8_STRING", False );
+ types[1] = XA_STRING; /* latin-1 */
+
+ for ( i = 0; i < ARRAY_LENGTH(types); i++ )
+ {
+ XConvertSelection( display, XA_PRIMARY, types[i], types[i], our_win, CurrentTime );
+
+ /* wait for SelectionNotify, but no more than 100 ms */
+ t0 = t1 = SDL_GetTicks();
+ while ( 1 )
+ {
+ if ( XCheckTypedWindowEvent( display, our_win, SelectionNotify, &event ) ) break;
+ SDL_Delay( 1 );
+ t1 = SDL_GetTicks();
+ if ( t1 - t0 > 100 )
+ return NULL;
+ }
+ if ( event.xselection.property == None )
+ continue;
+
+ /* get property & check its type */
+ if ( XGetWindowProperty( display, our_win, types[i], 0, 65536, False, types[i],
+ &data_type, &data_format, &nitems, &bytes_remaining, &prop )
+ != Success )
+ continue;
+ if ( ! prop )
+ continue;
+ if ( (data_format != 8) || (data_type != types[i]) )
+ {
+ XFree( prop );
+ continue;
+ }
+
+ /* return a copy & free original */
+ if (prop != NULL)
+ {
+ result = (char *) osd_malloc_array(strlen((char *)prop)+1);
+ strcpy(result, (char *)prop);
+ }
+ else
+ result = NULL;
+ XFree( prop );
+ return result;
+ }
+
+ return NULL;
+}
+
+#else
+//============================================================
+// osd_get_clipboard_text
+//============================================================
+
+char *osd_get_clipboard_text(void)
+{
+ char *result = NULL;
+
+ return result;
+}
+#endif