diff options
author | Zack Middleton <zturtleman@gmail.com> | 2014-08-27 04:17:39 -0500 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2014-08-28 11:20:29 +0100 |
commit | ac9e52d5d4e8e63699393aa4b4ad962b6f61f763 (patch) | |
tree | 4e572f2b4bec19a6c6c2198578724501947b14e0 | |
parent | 54191e809310574ffe629bb10126e51e04503e3d (diff) |
Get clipboard data from SDL
This makes pasting in client console and UI edit fields work on X11 and OS X.
Sys_GetClipboardData is only used by client, so returning NULL in dedicated is fine.
-rw-r--r-- | src/sys/sys_main.c | 29 | ||||
-rw-r--r-- | src/sys/sys_unix.c | 10 | ||||
-rw-r--r-- | src/sys/sys_win32.c | 27 |
3 files changed, 29 insertions, 37 deletions
diff --git a/src/sys/sys_main.c b/src/sys/sys_main.c index 8d495bdd..ed5f8e5a 100644 --- a/src/sys/sys_main.c +++ b/src/sys/sys_main.c @@ -128,6 +128,35 @@ char *Sys_ConsoleInput(void) return CON_Input( ); } +/* +================== +Sys_GetClipboardData +================== +*/ +char *Sys_GetClipboardData(void) +{ +#ifdef DEDICATED + return NULL; +#else + char *data = NULL; + char *cliptext; + + if ( ( cliptext = SDL_GetClipboardText() ) != NULL ) { + if ( cliptext[0] != '\0' ) { + size_t bufsize = strlen( cliptext ) + 1; + + data = Z_Malloc( bufsize ); + Q_strncpyz( data, cliptext, bufsize ); + + // find first listed char and set to '\0' + strtok( data, "\n\r\b" ); + } + SDL_free( cliptext ); + } + return data; +#endif +} + #ifdef DEDICATED # define PID_FILENAME PRODUCT_NAME "_server.pid" #else diff --git a/src/sys/sys_unix.c b/src/sys/sys_unix.c index 31c53b88..734a1e2c 100644 --- a/src/sys/sys_unix.c +++ b/src/sys/sys_unix.c @@ -141,16 +141,6 @@ char *Sys_GetCurrentUser( void ) return p->pw_name; } -/* -================== -Sys_GetClipboardData -================== -*/ -char *Sys_GetClipboardData(void) -{ - return NULL; -} - #define MEM_THRESHOLD 96*1024*1024 /* diff --git a/src/sys/sys_win32.c b/src/sys/sys_win32.c index 034d1572..a2554b89 100644 --- a/src/sys/sys_win32.c +++ b/src/sys/sys_win32.c @@ -192,33 +192,6 @@ char *Sys_GetCurrentUser( void ) return s_userName; } -/* -================ -Sys_GetClipboardData -================ -*/ -char *Sys_GetClipboardData( void ) -{ - char *data = NULL; - char *cliptext; - - if ( OpenClipboard( NULL ) != 0 ) { - HANDLE hClipboardData; - - if ( ( hClipboardData = GetClipboardData( CF_TEXT ) ) != 0 ) { - if ( ( cliptext = GlobalLock( hClipboardData ) ) != 0 ) { - data = Z_Malloc( GlobalSize( hClipboardData ) + 1 ); - Q_strncpyz( data, cliptext, GlobalSize( hClipboardData ) ); - GlobalUnlock( hClipboardData ); - - strtok( data, "\n\r\b" ); - } - } - CloseClipboard(); - } - return data; -} - #define MEM_THRESHOLD 96*1024*1024 /* |