Commit b47e7044 authored by Richard Gobeille's avatar Richard Gobeille
Browse files

engine: allow pasting into the console from the system clipboard with RMB

Disable with "osdclipboard 0".
parent c465145b
......@@ -128,6 +128,8 @@ typedef struct
int32_t pos; // position next character will be written at
int32_t lines; // total number of lines in buffer
int32_t maxlines; // max lines in buffer
int32_t useclipboard;
} osdtext_t;
// history display
......@@ -259,6 +261,8 @@ void OSD_CaptureKey(uint8_t scanCode);
int OSD_HandleScanCode(uint8_t scanCode, int keyDown);
int OSD_HandleChar(char ch);
void OSD_HandleWheel(void);
void OSD_HandleClipboard(char* const text);
// handles the readjustment when screen resolution changes
void OSD_ResizeDisplay(int w,int h);
......
......@@ -165,6 +165,27 @@ const char * OSD_StripColors(char *outBuf, const char *inBuf)
return ptr;
}
void OSD_HandleClipboard(char* const text)
{
if (!osd->text.useclipboard) return;
auto buf = (char*) Xcalloc(1, Bstrlen(text));
char const* cp = strtok(text, "\r\n");
int cnt = 0;
while (cp != NULL)
{
++osd->execdepth;
OSD_Dispatch(cp);
--osd->execdepth;
cp = strtok(NULL, "\r\n");
cnt++;
}
OSD_Printf("Pasted %d lines.\n", cnt);
Xfree(buf);
g_mouseBits &= ~2;
}
int OSD_Exec(const char *szScript)
{
int err = 0;
......@@ -770,6 +791,7 @@ void OSD_Init(void)
osd->numcvars = 0;
osd->text.lines = 1;
osd->text.maxlines = OSDDEFAULTMAXLINES; // overwritten later
osd->text.useclipboard = 1;
osd->draw.cols = OSDDEFAULTCOLS;
osd->log.cutoff = OSDMAXERRORS;
......@@ -780,6 +802,8 @@ void OSD_Init(void)
static osdcvardata_t cvars_osd [] =
{
{ "osdclipboard", "paste text into console from system clipboard with RMB", (void *) &osd->text.useclipboard, CVAR_BOOL, 0, 1 },
{ "osdeditpal", "console input text palette", (void *) &osd->draw.editpal, CVAR_INT, 0, MAXPALOOKUPS-1 },
{ "osdeditshade", "console input text shade", (void *) &osd->draw.editshade, CVAR_INT, 0, 7 },
......
......@@ -2561,6 +2561,13 @@ int32_t handleevents(void)
int32_t rv;
if (g_mouseBits & 2 && osd->flags & OSD_CAPTURE && SDL_HasClipboardText())
{
auto text = SDL_GetClipboardText();
OSD_HandleClipboard(text);
SDL_free(text);
}
if (inputchecked && g_mouseEnabled)
{
if (g_mouseCallback)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment