summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/sdl/sdlos_unix.c
diff options
context:
space:
mode:
author Couriersud <couriersud@users.noreply.github.com>2010-02-12 21:21:42 +0000
committer Couriersud <couriersud@users.noreply.github.com>2010-02-12 21:21:42 +0000
commitf529fad8b39c5c881ba9ca6e91ada919b7a39602 (patch)
tree99e31a34f35d281de769feb3427a62f93518f976 /src/osd/sdl/sdlos_unix.c
parent0ca347634e08b100c389480fb613adeb0d39c9f1 (diff)
Move functions from sdlclip.c to sdlos_*
- X11 clipboard code will now be compiled and will honor -DNO_X11
Diffstat (limited to 'src/osd/sdl/sdlos_unix.c')
-rw-r--r--src/osd/sdl/sdlos_unix.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/osd/sdl/sdlos_unix.c b/src/osd/sdl/sdlos_unix.c
index 8b489727081..cb1d619f492 100644
--- a/src/osd/sdl/sdlos_unix.c
+++ b/src/osd/sdl/sdlos_unix.c
@@ -15,6 +15,9 @@
#include <time.h>
#include <sys/time.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_syswm.h>
+
// MAME headers
#include "osdcore.h"
@@ -119,3 +122,106 @@ int osd_setenv(const char *name, const char *value, int overwrite)
{
return setenv(name, value, overwrite);
}
+
+
+#if 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(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