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?)
This commit is contained in:
Daniel Gibson 2021-06-26 01:07:00 +02:00
parent 1d6ae1acc1
commit 61a49a2547
5 changed files with 28 additions and 1 deletions

View file

@ -504,7 +504,7 @@ void idEditField::Paste( void ) {
CharEvent( cbd[i] );
}
Mem_Free( cbd );
Sys_FreeClipboardData( cbd );
}
/*

View file

@ -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;

View file

@ -49,6 +49,8 @@ If you have questions concerning this license or the applicable additional terms
#include "sys/posix/posix_public.h"
#include <SDL.h> // 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
}
/*

View file

@ -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

View file

@ -570,6 +570,10 @@ char *Sys_GetClipboardData( void ) {
return data;
}
void Sys_FreeClipboardData( char* data ) {
Mem_Free( data );
}
/*
================
Sys_SetClipboardData