2021-06-06 01:26:18 +00:00
|
|
|
/**
|
|
|
|
* Looking Glass
|
2022-01-05 08:42:46 +00:00
|
|
|
* Copyright © 2017-2022 The Looking Glass Authors
|
2021-06-06 01:26:18 +00:00
|
|
|
* https://looking-glass.io
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
|
|
|
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2021-01-25 08:58:36 +00:00
|
|
|
|
|
|
|
#include "clipboard.h"
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
#include "common/debug.h"
|
|
|
|
|
2021-12-28 11:03:48 +00:00
|
|
|
LG_ClipboardData cb_spiceTypeToLGType(const PSDataType type)
|
2021-01-25 08:58:36 +00:00
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case SPICE_DATA_TEXT: return LG_CLIPBOARD_DATA_TEXT; break;
|
|
|
|
case SPICE_DATA_PNG : return LG_CLIPBOARD_DATA_PNG ; break;
|
|
|
|
case SPICE_DATA_BMP : return LG_CLIPBOARD_DATA_BMP ; break;
|
|
|
|
case SPICE_DATA_TIFF: return LG_CLIPBOARD_DATA_TIFF; break;
|
|
|
|
case SPICE_DATA_JPEG: return LG_CLIPBOARD_DATA_JPEG; break;
|
|
|
|
default:
|
|
|
|
DEBUG_ERROR("invalid spice data type");
|
|
|
|
return LG_CLIPBOARD_DATA_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-28 11:03:48 +00:00
|
|
|
PSDataType cb_lgTypeToSpiceType(const LG_ClipboardData type)
|
2021-01-25 08:58:36 +00:00
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case LG_CLIPBOARD_DATA_TEXT: return SPICE_DATA_TEXT; break;
|
|
|
|
case LG_CLIPBOARD_DATA_PNG : return SPICE_DATA_PNG ; break;
|
|
|
|
case LG_CLIPBOARD_DATA_BMP : return SPICE_DATA_BMP ; break;
|
|
|
|
case LG_CLIPBOARD_DATA_TIFF: return SPICE_DATA_TIFF; break;
|
|
|
|
case LG_CLIPBOARD_DATA_JPEG: return SPICE_DATA_JPEG; break;
|
|
|
|
default:
|
|
|
|
DEBUG_ERROR("invalid clipboard data type");
|
|
|
|
return SPICE_DATA_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-28 11:03:48 +00:00
|
|
|
void cb_spiceNotice(const PSDataType type)
|
2021-01-25 08:58:36 +00:00
|
|
|
{
|
|
|
|
if (!g_params.clipboardToLocal)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_state.cbAvailable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_state.cbType = type;
|
|
|
|
g_state.ds->cbNotice(cb_spiceTypeToLGType(type));
|
|
|
|
}
|
|
|
|
|
2021-12-28 11:03:48 +00:00
|
|
|
void cb_spiceData(const PSDataType type, uint8_t * buffer, uint32_t size)
|
2021-01-25 08:58:36 +00:00
|
|
|
{
|
|
|
|
if (!g_params.clipboardToLocal)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (type == SPICE_DATA_TEXT)
|
|
|
|
{
|
|
|
|
// dos2unix
|
|
|
|
uint8_t * p = buffer;
|
|
|
|
uint32_t newSize = size;
|
|
|
|
for(uint32_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
uint8_t c = buffer[i];
|
|
|
|
if (c == '\r')
|
|
|
|
{
|
|
|
|
--newSize;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*p++ = c;
|
|
|
|
}
|
|
|
|
size = newSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct CBRequest * cbr;
|
|
|
|
if (ll_shift(g_state.cbRequestList, (void **)&cbr))
|
|
|
|
{
|
|
|
|
cbr->replyFn(cbr->opaque, cb_spiceTypeToLGType(type), buffer, size);
|
|
|
|
free(cbr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cb_spiceRelease(void)
|
|
|
|
{
|
|
|
|
if (!g_params.clipboardToLocal)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (g_state.cbAvailable)
|
|
|
|
g_state.ds->cbRelease();
|
|
|
|
}
|
|
|
|
|
2021-12-28 11:03:48 +00:00
|
|
|
void cb_spiceRequest(const PSDataType type)
|
2021-01-25 08:58:36 +00:00
|
|
|
{
|
|
|
|
if (!g_params.clipboardToVM)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (g_state.cbAvailable)
|
|
|
|
g_state.ds->cbRequest(cb_spiceTypeToLGType(type));
|
|
|
|
}
|