mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 06:47:19 +00:00
[client] added streaming clipboard support for large transfers
This commit is contained in:
parent
d700e19a32
commit
e57f084c93
@ -38,6 +38,9 @@ struct state
|
||||
LG_ClipboardDataFn dataFn;
|
||||
LG_ClipboardData type;
|
||||
|
||||
bool incrStart;
|
||||
unsigned int lowerBound;
|
||||
|
||||
// XFixes vars
|
||||
int eventBase;
|
||||
int errorBase;
|
||||
@ -77,10 +80,10 @@ static bool x11_cb_init(
|
||||
|
||||
this->display = wminfo->info.x11.display;
|
||||
this->window = wminfo->info.x11.window;
|
||||
this->aSelection = XInternAtom(this->display, "CLIPBOARD", False);
|
||||
this->aTargets = XInternAtom(this->display, "TARGETS" , False);
|
||||
this->aSelData = XInternAtom(this->display, "SEL_DATA" , False);
|
||||
this->aIncr = XInternAtom(this->display, "INCR" , False);
|
||||
this->aSelection = XInternAtom(this->display, "CLIPBOARD" , False);
|
||||
this->aTargets = XInternAtom(this->display, "TARGETS" , False);
|
||||
this->aSelData = XInternAtom(this->display, "SEL_DATA" , False);
|
||||
this->aIncr = XInternAtom(this->display, "INCR" , False);
|
||||
this->aCurSelection = BadValue;
|
||||
this->releaseFn = releaseFn;
|
||||
this->notifyFn = notifyFn;
|
||||
@ -225,6 +228,81 @@ static void x11_cb_xfixes_selection_notify(const XFixesSelectionNotifyEvent e)
|
||||
return;
|
||||
}
|
||||
|
||||
static void x11_cb_selection_incr(const XPropertyEvent e)
|
||||
{
|
||||
Atom type;
|
||||
int format;
|
||||
unsigned long itemCount, after;
|
||||
unsigned char *data;
|
||||
|
||||
if (XGetWindowProperty(
|
||||
e.display,
|
||||
e.window,
|
||||
e.atom,
|
||||
0, ~0L, // start and length
|
||||
True, // delete the property
|
||||
this->aIncr,
|
||||
&type,
|
||||
&format,
|
||||
&itemCount,
|
||||
&after,
|
||||
&data) != Success)
|
||||
{
|
||||
DEBUG_INFO("GetProp Failed");
|
||||
this->notifyFn(LG_CLIPBOARD_DATA_NONE, 0);
|
||||
goto out;
|
||||
}
|
||||
|
||||
LG_ClipboardData dataType;
|
||||
for(dataType = 0; dataType < LG_CLIPBOARD_DATA_NONE; ++dataType)
|
||||
if (this->aTypes[dataType] == type)
|
||||
break;
|
||||
|
||||
if (dataType == LG_CLIPBOARD_DATA_NONE)
|
||||
{
|
||||
DEBUG_WARN("clipboard data (%s) not in a supported format",
|
||||
XGetAtomName(this->display, type));
|
||||
|
||||
this->lowerBound = 0;
|
||||
this->notifyFn(LG_CLIPBOARD_DATA_NONE, 0);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (this->incrStart)
|
||||
{
|
||||
this->notifyFn(dataType, this->lowerBound);
|
||||
this->incrStart = false;
|
||||
}
|
||||
|
||||
XFree(data);
|
||||
data = NULL;
|
||||
|
||||
if (XGetWindowProperty(
|
||||
e.display,
|
||||
e.window,
|
||||
e.atom,
|
||||
0, ~0L, // start and length
|
||||
True, // delete the property
|
||||
type,
|
||||
&type,
|
||||
&format,
|
||||
&itemCount,
|
||||
&after,
|
||||
&data) != Success)
|
||||
{
|
||||
DEBUG_ERROR("XGetWindowProperty Failed");
|
||||
this->notifyFn(LG_CLIPBOARD_DATA_NONE, 0);
|
||||
goto out;
|
||||
}
|
||||
|
||||
this->dataFn(dataType, data, itemCount);
|
||||
this->lowerBound -= itemCount;
|
||||
|
||||
out:
|
||||
if (data)
|
||||
XFree(data);
|
||||
}
|
||||
|
||||
static void x11_cb_selection_notify(const XSelectionEvent e)
|
||||
{
|
||||
if (e.property == None)
|
||||
@ -235,9 +313,9 @@ static void x11_cb_selection_notify(const XSelectionEvent e)
|
||||
unsigned long itemCount, after;
|
||||
unsigned char *data;
|
||||
|
||||
XGetWindowProperty(
|
||||
this->display,
|
||||
this->window,
|
||||
if (XGetWindowProperty(
|
||||
e.display,
|
||||
e.requestor,
|
||||
e.property,
|
||||
0, ~0L, // start and length
|
||||
True , // delete the property
|
||||
@ -246,12 +324,16 @@ static void x11_cb_selection_notify(const XSelectionEvent e)
|
||||
&format,
|
||||
&itemCount,
|
||||
&after,
|
||||
&data);
|
||||
&data) != Success)
|
||||
{
|
||||
this->notifyFn(LG_CLIPBOARD_DATA_NONE, 0);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (type == this->aIncr)
|
||||
{
|
||||
DEBUG_WARN("fixme: large paste buffers are not yet supported");
|
||||
this->notifyFn(LG_CLIPBOARD_DATA_NONE);
|
||||
this->incrStart = true;
|
||||
this->lowerBound = *(unsigned int *)data;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -272,26 +354,31 @@ static void x11_cb_selection_notify(const XSelectionEvent e)
|
||||
if (this->aTypes[n] == targets[i])
|
||||
{
|
||||
// we have a match, so send the notification
|
||||
this->notifyFn(n);
|
||||
this->notifyFn(n, 0);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
// no matches
|
||||
this->notifyFn(LG_CLIPBOARD_DATA_NONE);
|
||||
this->notifyFn(LG_CLIPBOARD_DATA_NONE, 0);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (e.property == this->aSelData)
|
||||
{
|
||||
for(int i = 0; i < LG_CLIPBOARD_DATA_NONE; ++i)
|
||||
if (this->aTypes[i] == type)
|
||||
{
|
||||
this->dataFn(i, data, itemCount);
|
||||
goto out;
|
||||
}
|
||||
LG_ClipboardData dataType;
|
||||
for(dataType = 0; dataType < LG_CLIPBOARD_DATA_NONE; ++dataType)
|
||||
if (this->aTypes[dataType] == type)
|
||||
break;
|
||||
|
||||
DEBUG_WARN("clipboard data (%s) not in a supported format", XGetAtomName(this->display, type));
|
||||
if (dataType == LG_CLIPBOARD_DATA_NONE)
|
||||
{
|
||||
DEBUG_WARN("clipboard data (%s) not in a supported format",
|
||||
XGetAtomName(this->display, type));
|
||||
goto out;
|
||||
}
|
||||
|
||||
this->dataFn(dataType, data, itemCount);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -318,6 +405,17 @@ static void x11_cb_wmevent(SDL_SysWMmsg * msg)
|
||||
x11_cb_selection_notify(e.xselection);
|
||||
break;
|
||||
|
||||
case PropertyNotify:
|
||||
if (e.xproperty.display != this->display ||
|
||||
e.xproperty.window != this->window ||
|
||||
e.xproperty.atom != this->aSelData ||
|
||||
e.xproperty.state != PropertyNewValue ||
|
||||
this->lowerBound == 0)
|
||||
break;
|
||||
|
||||
x11_cb_selection_incr(e.xproperty);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (e.type == this->eventBase + XFixesSelectionNotify)
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ LG_ClipboardData;
|
||||
typedef void (* LG_ClipboardReplyFn )(void * opaque, const LG_ClipboardData type, uint8_t * data, uint32_t size);
|
||||
typedef void (* LG_ClipboardRequestFn)(LG_ClipboardReplyFn replyFn, void * opaque);
|
||||
typedef void (* LG_ClipboardReleaseFn)();
|
||||
typedef void (* LG_ClipboardNotifyFn)(LG_ClipboardData type);
|
||||
typedef void (* LG_ClipboardNotifyFn)(LG_ClipboardData type, size_t size);
|
||||
typedef void (* LG_ClipboardDataFn )(const LG_ClipboardData type, uint8_t * data, size_t size);
|
||||
|
||||
typedef const char * (* LG_ClipboardGetName)();
|
||||
|
@ -644,7 +644,7 @@ void clipboardRelease()
|
||||
spice_clipboard_release();
|
||||
}
|
||||
|
||||
void clipboardNotify(const LG_ClipboardData type)
|
||||
void clipboardNotify(const LG_ClipboardData type, size_t size)
|
||||
{
|
||||
if (!params.clipboardToVM)
|
||||
return;
|
||||
@ -655,7 +655,14 @@ void clipboardNotify(const LG_ClipboardData type)
|
||||
return;
|
||||
}
|
||||
|
||||
spice_clipboard_grab(clipboard_type_to_spice_type(type));
|
||||
state.cbType = clipboard_type_to_spice_type(type);
|
||||
state.cbChunked = size > 0;
|
||||
state.cbXfer = size;
|
||||
|
||||
spice_clipboard_grab(state.cbType);
|
||||
|
||||
if (size)
|
||||
spice_clipboard_data_start(state.cbType, size);
|
||||
}
|
||||
|
||||
void clipboardData(const LG_ClipboardData type, uint8_t * data, size_t size)
|
||||
@ -663,32 +670,17 @@ void clipboardData(const LG_ClipboardData type, uint8_t * data, size_t size)
|
||||
if (!params.clipboardToVM)
|
||||
return;
|
||||
|
||||
uint8_t * buffer = data;
|
||||
|
||||
// unix2dos
|
||||
if (type == LG_CLIPBOARD_DATA_TEXT)
|
||||
if (state.cbChunked && size > state.cbXfer)
|
||||
{
|
||||
// TODO: make this more memory efficent
|
||||
size_t newSize = 0;
|
||||
buffer = malloc(size * 2);
|
||||
uint8_t * p = buffer;
|
||||
for(uint32_t i = 0; i < size; ++i)
|
||||
{
|
||||
uint8_t c = data[i];
|
||||
if (c == '\n')
|
||||
{
|
||||
*p++ = '\r';
|
||||
++newSize;
|
||||
}
|
||||
*p++ = c;
|
||||
++newSize;
|
||||
}
|
||||
size = newSize;
|
||||
DEBUG_ERROR("refusing to send more then cbXfer bytes for chunked xfer");
|
||||
size = state.cbXfer;
|
||||
}
|
||||
|
||||
spice_clipboard_data(clipboard_type_to_spice_type(type), buffer, (uint32_t)size);
|
||||
if (buffer != data)
|
||||
free(buffer);
|
||||
if (!state.cbChunked)
|
||||
spice_clipboard_data_start(state.cbType, size);
|
||||
|
||||
spice_clipboard_data(state.cbType, data, (uint32_t)size);
|
||||
state.cbXfer -= size;
|
||||
}
|
||||
|
||||
void clipboardRequest(const LG_ClipboardReplyFn replyFn, void * opaque)
|
||||
|
@ -92,6 +92,8 @@ struct AppState
|
||||
|
||||
const LG_Clipboard * lgc;
|
||||
SpiceDataType cbType;
|
||||
bool cbChunked;
|
||||
size_t cbXfer;
|
||||
struct ll * cbRequestList;
|
||||
|
||||
SDL_SysWMinfo wminfo;
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit c83a899ffd99c2d7de458ce15a39e4dc13211076
|
||||
Subproject commit 749395f1f5a806cd03d0b0816004d89a58dc8c38
|
Loading…
Reference in New Issue
Block a user