ui/vdagent: split clipboard recv message handling
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20210805135715.857938-12-marcandre.lureau@redhat.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
5fb2e8d99b
commit
3b99bb4c3a
85
ui/vdagent.c
85
ui/vdagent.c
|
@ -433,28 +433,10 @@ static void vdagent_clipboard_request(QemuClipboardInfo *info,
|
||||||
vdagent_send_msg(vd, msg);
|
vdagent_send_msg(vd, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vdagent_chr_recv_clipboard(VDAgentChardev *vd, VDAgentMessage *msg)
|
static void vdagent_clipboard_recv_grab(VDAgentChardev *vd, uint8_t s, uint32_t size, void *data)
|
||||||
{
|
{
|
||||||
uint8_t s = VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD;
|
|
||||||
uint32_t size = msg->size;
|
|
||||||
void *data = msg->data;
|
|
||||||
g_autoptr(QemuClipboardInfo) info = NULL;
|
g_autoptr(QemuClipboardInfo) info = NULL;
|
||||||
QemuClipboardType type;
|
|
||||||
|
|
||||||
if (have_selection(vd)) {
|
|
||||||
if (size < 4) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
s = *(uint8_t *)data;
|
|
||||||
if (s >= QEMU_CLIPBOARD_SELECTION__COUNT) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
data += 4;
|
|
||||||
size -= 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (msg->type) {
|
|
||||||
case VD_AGENT_CLIPBOARD_GRAB:
|
|
||||||
trace_vdagent_cb_grab_selection(GET_NAME(sel_name, s));
|
trace_vdagent_cb_grab_selection(GET_NAME(sel_name, s));
|
||||||
info = qemu_clipboard_info_new(&vd->cbpeer, s);
|
info = qemu_clipboard_info_new(&vd->cbpeer, s);
|
||||||
if (size > sizeof(uint32_t) * 10) {
|
if (size > sizeof(uint32_t) * 10) {
|
||||||
|
@ -477,8 +459,12 @@ static void vdagent_chr_recv_clipboard(VDAgentChardev *vd, VDAgentMessage *msg)
|
||||||
size -= sizeof(uint32_t);
|
size -= sizeof(uint32_t);
|
||||||
}
|
}
|
||||||
qemu_clipboard_update(info);
|
qemu_clipboard_update(info);
|
||||||
break;
|
}
|
||||||
case VD_AGENT_CLIPBOARD_REQUEST:
|
|
||||||
|
static void vdagent_clipboard_recv_request(VDAgentChardev *vd, uint8_t s, uint32_t size, void *data)
|
||||||
|
{
|
||||||
|
QemuClipboardType type;
|
||||||
|
|
||||||
if (size < sizeof(uint32_t)) {
|
if (size < sizeof(uint32_t)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -489,8 +475,7 @@ static void vdagent_chr_recv_clipboard(VDAgentChardev *vd, VDAgentMessage *msg)
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (vd->cbinfo[s] &&
|
if (vd->cbinfo[s] && vd->cbinfo[s]->types[type].available &&
|
||||||
vd->cbinfo[s]->types[type].available &&
|
|
||||||
vd->cbinfo[s]->owner != &vd->cbpeer) {
|
vd->cbinfo[s]->owner != &vd->cbpeer) {
|
||||||
if (vd->cbinfo[s]->types[type].data) {
|
if (vd->cbinfo[s]->types[type].data) {
|
||||||
vdagent_send_clipboard_data(vd, vd->cbinfo[s], type);
|
vdagent_send_clipboard_data(vd, vd->cbinfo[s], type);
|
||||||
|
@ -499,8 +484,12 @@ static void vdagent_chr_recv_clipboard(VDAgentChardev *vd, VDAgentMessage *msg)
|
||||||
qemu_clipboard_request(vd->cbinfo[s], type);
|
qemu_clipboard_request(vd->cbinfo[s], type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case VD_AGENT_CLIPBOARD: /* data */
|
|
||||||
|
static void vdagent_clipboard_recv_data(VDAgentChardev *vd, uint8_t s, uint32_t size, void *data)
|
||||||
|
{
|
||||||
|
QemuClipboardType type;
|
||||||
|
|
||||||
if (size < sizeof(uint32_t)) {
|
if (size < sizeof(uint32_t)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -513,17 +502,49 @@ static void vdagent_chr_recv_clipboard(VDAgentChardev *vd, VDAgentMessage *msg)
|
||||||
}
|
}
|
||||||
data += 4;
|
data += 4;
|
||||||
size -= 4;
|
size -= 4;
|
||||||
qemu_clipboard_set_data(&vd->cbpeer, vd->cbinfo[s], type,
|
qemu_clipboard_set_data(&vd->cbpeer, vd->cbinfo[s], type, size, data, true);
|
||||||
size, data, true);
|
}
|
||||||
break;
|
|
||||||
case VD_AGENT_CLIPBOARD_RELEASE:
|
static void vdagent_clipboard_recv_release(VDAgentChardev *vd, uint8_t s)
|
||||||
if (vd->cbinfo[s] &&
|
{
|
||||||
vd->cbinfo[s]->owner == &vd->cbpeer) {
|
g_autoptr(QemuClipboardInfo) info = NULL;
|
||||||
|
|
||||||
|
if (vd->cbinfo[s] && vd->cbinfo[s]->owner == &vd->cbpeer) {
|
||||||
/* set empty clipboard info */
|
/* set empty clipboard info */
|
||||||
info = qemu_clipboard_info_new(NULL, s);
|
info = qemu_clipboard_info_new(NULL, s);
|
||||||
qemu_clipboard_update(info);
|
qemu_clipboard_update(info);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
static void vdagent_chr_recv_clipboard(VDAgentChardev *vd, VDAgentMessage *msg)
|
||||||
|
{
|
||||||
|
uint8_t s = VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD;
|
||||||
|
uint32_t size = msg->size;
|
||||||
|
void *data = msg->data;
|
||||||
|
|
||||||
|
if (have_selection(vd)) {
|
||||||
|
if (size < 4) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
s = *(uint8_t *)data;
|
||||||
|
if (s >= QEMU_CLIPBOARD_SELECTION__COUNT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
data += 4;
|
||||||
|
size -= 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (msg->type) {
|
||||||
|
case VD_AGENT_CLIPBOARD_GRAB:
|
||||||
|
return vdagent_clipboard_recv_grab(vd, s, size, data);
|
||||||
|
case VD_AGENT_CLIPBOARD_REQUEST:
|
||||||
|
return vdagent_clipboard_recv_request(vd, s, size, data);
|
||||||
|
case VD_AGENT_CLIPBOARD: /* data */
|
||||||
|
return vdagent_clipboard_recv_data(vd, s, size, data);
|
||||||
|
case VD_AGENT_CLIPBOARD_RELEASE:
|
||||||
|
return vdagent_clipboard_recv_release(vd, s);
|
||||||
|
default:
|
||||||
|
g_assert_not_reached();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue