2
0
mirror of https://github.com/arnavbhatt288/sdl-2.30.3-kolibri.git synced 2025-09-21 02:50:08 +02:00

add clipboard support

Signed-off-by: Arnav Bhatt <arnav@ghativega.in>
This commit is contained in:
Arnav Bhatt
2024-06-20 02:31:25 +05:30
parent 74a68f581a
commit 50983eac06
4 changed files with 78 additions and 1 deletions

View File

@@ -82,7 +82,7 @@ video_OBJS = src/video/SDL_blit_0.o src/video/SDL_blit_1.o src/video/SDL_blit_A.
src/video/yuv2rgb/yuv_rgb_sse.o src/video/yuv2rgb/yuv_rgb_std.o \
src/video/kolibri/SDL_kolibrievents.o src/video/kolibri/SDL_kolibriframebuffer.o \
src/video/kolibri/SDL_kolibrivideo.o src/video/kolibri/SDL_kolibriwindow.o \
src/video/kolibri/SDL_kolibrimouse.o
src/video/kolibri/SDL_kolibrimouse.o src/video/kolibri/SDL_kolibriclipboard.o
curr_OBJS = src/SDL_assert.o src/SDL_dataqueue.o src/SDL_error.o src/SDL_guid.o \
src/SDL_hints.o src/SDL_list.o src/SDL_log.o src/SDL_utils.o src/SDL.o

View File

@@ -0,0 +1,60 @@
#include "../../SDL_internal.h"
#ifdef SDL_VIDEO_DRIVER_KOLIBRI
#include <sys/ksys.h>
#define string_length(x) SDL_strlen(x) + 1
#include "../SDL_sysvideo.h"
char *KOLIBRI_GetClipboardText(_THIS)
{
int clip_num = _ksys_clip_num();
char *clip_buf, *result;
if (clip_num > 0) {
clip_buf = _ksys_clip_get(clip_num - 1);
if ((int)*clip_buf > 0 && (int)*(clip_buf + 4) == KSYS_CLIP_TEXT && ((int)*(clip_buf + 8) == KSYS_CLIP_CP866)) {
char *clip_text = clip_buf + 12;
result = SDL_calloc((int)*clip_buf, sizeof(char));
SDL_strlcpy(result, clip_text, (int)*clip_buf);
_ksys_free(clip_buf);
}
}
if (!result)
result = SDL_strdup("");
return result;
}
int KOLIBRI_SetClipboardText(_THIS, const char *text)
{
char *temp_buffer = SDL_calloc(string_length(text) + 12, sizeof(char));
*temp_buffer = string_length(text);
*(temp_buffer + 4) = KSYS_CLIP_TEXT;
*(temp_buffer + 8) = KSYS_CLIP_CP866;
SDL_strlcpy(temp_buffer + 12, text, string_length(text));
_ksys_clip_set(string_length(text) + 12, temp_buffer);
SDL_free(temp_buffer);
return 0;
}
SDL_bool KOLIBRI_HasClipboardText(_THIS)
{
SDL_bool result = SDL_FALSE;
char *text = KOLIBRI_GetClipboardText(_this);
if (text) {
result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
SDL_free(text);
}
return result;
}
#endif

View File

@@ -0,0 +1,11 @@
#include "../../SDL_internal.h"
#ifndef SDL_kolibriclipboard_h_
#define SDL_kolibriclipboard_h_
extern char *KOLIBRI_GetClipboardText(_THIS);
extern int KOLIBRI_SetClipboardText(_THIS, const char *text);
extern SDL_bool KOLIBRI_HasClipboardText(_THIS);
#endif

View File

@@ -10,6 +10,7 @@
#include "../SDL_sysvideo.h"
#include "SDL_video.h"
#include "SDL_kolibriclipboard.h"
#include "SDL_kolibrievents.h"
#include "SDL_kolibriframebuffer.h"
#include "SDL_kolibrimouse.h"
@@ -95,6 +96,11 @@ static SDL_VideoDevice *KOLIBRI_CreateDevice(void)
device->SetWindowTitle = KOLIBRI_SetWindowTitle;
device->DestroyWindow = KOLIBRI_DestroyWindow;
/* Clipboard */
device->HasClipboardText = KOLIBRI_HasClipboardText;
device->GetClipboardText = KOLIBRI_GetClipboardText;
device->SetClipboardText = KOLIBRI_SetClipboardText;
/* KolibriOS specific data */
device->driverdata = data;