From 61a49a2547e9f23f981188af2c844dd8464d15bf Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sat, 26 Jun 2021 01:07:00 +0200 Subject: [PATCH] Implement clipboard support on POSIX platforms with SDL2 Added Sys_FreeClipboardData(char*) so I don't have to copy the string from SDL_GetClipboardText() into a Mem_Alloc() buffer, but can just do the right thing per platform, which in case of POSIX/SDL2 is SDL_free(). SDL1.2 doesn't have clipboard support, otherwise I'd have removed all platform-specific implementations and used SDL_Get/SetClipboardText() everywhere (IIRC AROS only supports SDL1.2?) --- neo/framework/EditField.cpp | 2 +- neo/sys/aros/aros_dos.cpp | 4 ++++ neo/sys/posix/posix_main.cpp | 18 ++++++++++++++++++ neo/sys/sys_public.h | 1 + neo/sys/win32/win_main.cpp | 4 ++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/neo/framework/EditField.cpp b/neo/framework/EditField.cpp index ada5d064..4df80690 100644 --- a/neo/framework/EditField.cpp +++ b/neo/framework/EditField.cpp @@ -504,7 +504,7 @@ void idEditField::Paste( void ) { CharEvent( cbd[i] ); } - Mem_Free( cbd ); + Sys_FreeClipboardData( cbd ); } /* diff --git a/neo/sys/aros/aros_dos.cpp b/neo/sys/aros/aros_dos.cpp index ed135cbd..679e70b2 100644 --- a/neo/sys/aros/aros_dos.cpp +++ b/neo/sys/aros/aros_dos.cpp @@ -238,6 +238,10 @@ char *Sys_GetClipboardData(void) { return NULL; } +void Sys_FreeClipboardData( char* data ) { + // as Sys_GetClipboardData() returns a static buffer, there's nothing to free +} + void Sys_SetClipboardData( const char *string ) { struct IFFHandle *IFFHandle; BOOL written = FALSE; diff --git a/neo/sys/posix/posix_main.cpp b/neo/sys/posix/posix_main.cpp index e05a2030..58c878f5 100644 --- a/neo/sys/posix/posix_main.cpp +++ b/neo/sys/posix/posix_main.cpp @@ -49,6 +49,8 @@ If you have questions concerning this license or the applicable additional terms #include "sys/posix/posix_public.h" +#include // clipboard + #define COMMAND_HISTORY 64 static int input_hide = 0; @@ -331,12 +333,28 @@ ID_TIME_T Sys_FileTimeStamp(FILE * fp) { } char *Sys_GetClipboardData(void) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + return SDL_GetClipboardText(); +#else Sys_Printf( "TODO: Sys_GetClipboardData\n" ); return NULL; +#endif +} + +void Sys_FreeClipboardData( char* data ) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_free( data ); +#else + assert( 0 && "why is this called, Sys_GetClipboardData() isn't implemented for SDL1.2" ); +#endif } void Sys_SetClipboardData( const char *string ) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_SetClipboardText( string ); +#else Sys_Printf( "TODO: Sys_SetClipboardData\n" ); +#endif } /* diff --git a/neo/sys/sys_public.h b/neo/sys/sys_public.h index fe2bde14..189a51ef 100644 --- a/neo/sys/sys_public.h +++ b/neo/sys/sys_public.h @@ -101,6 +101,7 @@ void Sys_Quit( void ); // note that this isn't journaled... char * Sys_GetClipboardData( void ); +void Sys_FreeClipboardData( char* data ); void Sys_SetClipboardData( const char *string ); // will go to the various text consoles diff --git a/neo/sys/win32/win_main.cpp b/neo/sys/win32/win_main.cpp index fccbc42f..8562da0b 100644 --- a/neo/sys/win32/win_main.cpp +++ b/neo/sys/win32/win_main.cpp @@ -570,6 +570,10 @@ char *Sys_GetClipboardData( void ) { return data; } +void Sys_FreeClipboardData( char* data ) { + Mem_Free( data ); +} + /* ================ Sys_SetClipboardData