2021-09-10 10:57:35 +00:00
|
|
|
#include "util/log.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "aoa_hid.h"
|
2021-11-24 21:06:11 +00:00
|
|
|
#include "util/log.h"
|
2021-09-10 10:57:35 +00:00
|
|
|
|
|
|
|
// See <https://source.android.com/devices/accessories/aoa2#hid-support>.
|
|
|
|
#define ACCESSORY_REGISTER_HID 54
|
|
|
|
#define ACCESSORY_SET_HID_REPORT_DESC 56
|
|
|
|
#define ACCESSORY_SEND_HID_EVENT 57
|
|
|
|
#define ACCESSORY_UNREGISTER_HID 55
|
|
|
|
|
|
|
|
#define DEFAULT_TIMEOUT 1000
|
|
|
|
|
2023-03-01 21:50:56 +00:00
|
|
|
#define SC_HID_EVENT_QUEUE_MAX 64
|
|
|
|
|
2021-09-10 10:57:35 +00:00
|
|
|
static void
|
|
|
|
sc_hid_event_log(const struct sc_hid_event *event) {
|
|
|
|
// HID Event: [00] FF FF FF FF...
|
|
|
|
assert(event->size);
|
|
|
|
unsigned buffer_size = event->size * 3 + 1;
|
|
|
|
char *buffer = malloc(buffer_size);
|
|
|
|
if (!buffer) {
|
2021-11-24 21:06:11 +00:00
|
|
|
LOG_OOM();
|
2021-09-10 10:57:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (unsigned i = 0; i < event->size; ++i) {
|
|
|
|
snprintf(buffer + i * 3, 4, " %02x", event->buffer[i]);
|
|
|
|
}
|
|
|
|
LOGV("HID Event: [%d]%s", event->accessory_id, buffer);
|
|
|
|
free(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_hid_event_init(struct sc_hid_event *hid_event, uint16_t accessory_id,
|
|
|
|
unsigned char *buffer, uint16_t buffer_size) {
|
|
|
|
hid_event->accessory_id = accessory_id;
|
|
|
|
hid_event->buffer = buffer;
|
|
|
|
hid_event->size = buffer_size;
|
Wait SET_CLIPBOARD ack before Ctrl+v via HID
To allow seamless copy-paste, on Ctrl+v, a SET_CLIPBOARD request is
performed before injecting Ctrl+v.
But when HID keyboard is enabled, the Ctrl+v injection is not sent on
the same channel as the clipboard request, so they are not serialized,
and may occur in any order. If Ctrl+v happens to be injected before the
new clipboard content is set, then the old content is pasted instead,
which is incorrect.
To minimize the probability of occurrence of the wrong order, a delay of
2 milliseconds was added before injecting Ctrl+v. Then 5ms. But even
with 5ms, the wrong behavior sometimes happens.
To handle it properly, add an acknowledgement mechanism, so that Ctrl+v
is injected over AOA only after the SET_CLIPBOARD request has been
performed and acknowledged by the server.
Refs e4163321f00bb3830c6049bdb6c1515e7cc668a0
Refs 45b0f8123a52f5c73a5860d616f4ceba2766ca6a
PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
2021-11-21 16:40:11 +00:00
|
|
|
hid_event->ack_to_wait = SC_SEQUENCE_INVALID;
|
2021-09-10 10:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_hid_event_destroy(struct sc_hid_event *hid_event) {
|
|
|
|
free(hid_event->buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2022-01-24 22:11:42 +00:00
|
|
|
sc_aoa_init(struct sc_aoa *aoa, struct sc_usb *usb,
|
Wait SET_CLIPBOARD ack before Ctrl+v via HID
To allow seamless copy-paste, on Ctrl+v, a SET_CLIPBOARD request is
performed before injecting Ctrl+v.
But when HID keyboard is enabled, the Ctrl+v injection is not sent on
the same channel as the clipboard request, so they are not serialized,
and may occur in any order. If Ctrl+v happens to be injected before the
new clipboard content is set, then the old content is pasted instead,
which is incorrect.
To minimize the probability of occurrence of the wrong order, a delay of
2 milliseconds was added before injecting Ctrl+v. Then 5ms. But even
with 5ms, the wrong behavior sometimes happens.
To handle it properly, add an acknowledgement mechanism, so that Ctrl+v
is injected over AOA only after the SET_CLIPBOARD request has been
performed and acknowledged by the server.
Refs e4163321f00bb3830c6049bdb6c1515e7cc668a0
Refs 45b0f8123a52f5c73a5860d616f4ceba2766ca6a
PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
2021-11-21 16:40:11 +00:00
|
|
|
struct sc_acksync *acksync) {
|
2023-03-01 21:50:56 +00:00
|
|
|
sc_vecdeque_init(&aoa->queue);
|
|
|
|
|
|
|
|
if (!sc_vecdeque_reserve(&aoa->queue, SC_HID_EVENT_QUEUE_MAX)) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-10 10:57:35 +00:00
|
|
|
|
|
|
|
if (!sc_mutex_init(&aoa->mutex)) {
|
2023-03-01 21:50:56 +00:00
|
|
|
sc_vecdeque_destroy(&aoa->queue);
|
2021-09-10 10:57:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sc_cond_init(&aoa->event_cond)) {
|
2022-01-24 22:11:42 +00:00
|
|
|
sc_mutex_destroy(&aoa->mutex);
|
2023-03-01 21:50:56 +00:00
|
|
|
sc_vecdeque_destroy(&aoa->queue);
|
2022-01-24 22:11:42 +00:00
|
|
|
return false;
|
2021-09-10 10:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aoa->stopped = false;
|
Wait SET_CLIPBOARD ack before Ctrl+v via HID
To allow seamless copy-paste, on Ctrl+v, a SET_CLIPBOARD request is
performed before injecting Ctrl+v.
But when HID keyboard is enabled, the Ctrl+v injection is not sent on
the same channel as the clipboard request, so they are not serialized,
and may occur in any order. If Ctrl+v happens to be injected before the
new clipboard content is set, then the old content is pasted instead,
which is incorrect.
To minimize the probability of occurrence of the wrong order, a delay of
2 milliseconds was added before injecting Ctrl+v. Then 5ms. But even
with 5ms, the wrong behavior sometimes happens.
To handle it properly, add an acknowledgement mechanism, so that Ctrl+v
is injected over AOA only after the SET_CLIPBOARD request has been
performed and acknowledged by the server.
Refs e4163321f00bb3830c6049bdb6c1515e7cc668a0
Refs 45b0f8123a52f5c73a5860d616f4ceba2766ca6a
PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
2021-11-21 16:40:11 +00:00
|
|
|
aoa->acksync = acksync;
|
2022-01-24 22:11:42 +00:00
|
|
|
aoa->usb = usb;
|
2021-09-10 10:57:35 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_aoa_destroy(struct sc_aoa *aoa) {
|
|
|
|
// Destroy remaining events
|
2023-03-01 21:50:56 +00:00
|
|
|
while (!sc_vecdeque_is_empty(&aoa->queue)) {
|
|
|
|
struct sc_hid_event *event = sc_vecdeque_popref(&aoa->queue);
|
|
|
|
assert(event);
|
|
|
|
sc_hid_event_destroy(event);
|
2021-09-10 10:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sc_cond_destroy(&aoa->event_cond);
|
|
|
|
sc_mutex_destroy(&aoa->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
sc_aoa_register_hid(struct sc_aoa *aoa, uint16_t accessory_id,
|
|
|
|
uint16_t report_desc_size) {
|
|
|
|
uint8_t request_type = LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR;
|
|
|
|
uint8_t request = ACCESSORY_REGISTER_HID;
|
|
|
|
// <https://source.android.com/devices/accessories/aoa2.html#hid-support>
|
|
|
|
// value (arg0): accessory assigned ID for the HID device
|
|
|
|
// index (arg1): total length of the HID report descriptor
|
|
|
|
uint16_t value = accessory_id;
|
|
|
|
uint16_t index = report_desc_size;
|
2024-01-25 18:45:21 +00:00
|
|
|
unsigned char *data = NULL;
|
2021-09-10 10:57:35 +00:00
|
|
|
uint16_t length = 0;
|
2022-01-24 22:11:42 +00:00
|
|
|
int result = libusb_control_transfer(aoa->usb->handle, request_type,
|
2024-01-25 18:45:21 +00:00
|
|
|
request, value, index, data, length,
|
2021-09-10 10:57:35 +00:00
|
|
|
DEFAULT_TIMEOUT);
|
|
|
|
if (result < 0) {
|
2022-02-07 11:56:25 +00:00
|
|
|
LOGE("REGISTER_HID: libusb error: %s", libusb_strerror(result));
|
2022-02-10 06:57:18 +00:00
|
|
|
sc_usb_check_disconnected(aoa->usb, result);
|
2021-09-10 10:57:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
sc_aoa_set_hid_report_desc(struct sc_aoa *aoa, uint16_t accessory_id,
|
2024-02-23 18:59:54 +00:00
|
|
|
const uint8_t *report_desc,
|
2021-09-10 10:57:35 +00:00
|
|
|
uint16_t report_desc_size) {
|
|
|
|
uint8_t request_type = LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR;
|
|
|
|
uint8_t request = ACCESSORY_SET_HID_REPORT_DESC;
|
|
|
|
/**
|
|
|
|
* If the HID descriptor is longer than the endpoint zero max packet size,
|
|
|
|
* the descriptor will be sent in multiple ACCESSORY_SET_HID_REPORT_DESC
|
|
|
|
* commands. The data for the descriptor must be sent sequentially
|
|
|
|
* if multiple packets are needed.
|
|
|
|
* <https://source.android.com/devices/accessories/aoa2.html#hid-support>
|
|
|
|
*
|
|
|
|
* libusb handles packet abstraction internally, so we don't need to care
|
|
|
|
* about bMaxPacketSize0 here.
|
|
|
|
*
|
|
|
|
* See <https://libusb.sourceforge.io/api-1.0/libusb_packetoverflow.html>
|
|
|
|
*/
|
|
|
|
// value (arg0): accessory assigned ID for the HID device
|
2024-01-25 18:45:21 +00:00
|
|
|
// index (arg1): offset of data in descriptor
|
2021-09-10 10:57:35 +00:00
|
|
|
uint16_t value = accessory_id;
|
|
|
|
uint16_t index = 0;
|
|
|
|
// libusb_control_transfer expects a pointer to non-const
|
2024-01-25 18:45:21 +00:00
|
|
|
unsigned char *data = (unsigned char *) report_desc;
|
2021-09-10 10:57:35 +00:00
|
|
|
uint16_t length = report_desc_size;
|
2022-01-24 22:11:42 +00:00
|
|
|
int result = libusb_control_transfer(aoa->usb->handle, request_type,
|
2024-01-25 18:45:21 +00:00
|
|
|
request, value, index, data, length,
|
2021-09-10 10:57:35 +00:00
|
|
|
DEFAULT_TIMEOUT);
|
|
|
|
if (result < 0) {
|
2022-02-07 11:56:25 +00:00
|
|
|
LOGE("SET_HID_REPORT_DESC: libusb error: %s", libusb_strerror(result));
|
2022-02-10 06:57:18 +00:00
|
|
|
sc_usb_check_disconnected(aoa->usb, result);
|
2021-09-10 10:57:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
sc_aoa_setup_hid(struct sc_aoa *aoa, uint16_t accessory_id,
|
2024-02-23 18:59:54 +00:00
|
|
|
const uint8_t *report_desc, uint16_t report_desc_size) {
|
2021-09-10 10:57:35 +00:00
|
|
|
bool ok = sc_aoa_register_hid(aoa, accessory_id, report_desc_size);
|
|
|
|
if (!ok) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok = sc_aoa_set_hid_report_desc(aoa, accessory_id, report_desc,
|
|
|
|
report_desc_size);
|
|
|
|
if (!ok) {
|
|
|
|
if (!sc_aoa_unregister_hid(aoa, accessory_id)) {
|
|
|
|
LOGW("Could not unregister HID");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
sc_aoa_send_hid_event(struct sc_aoa *aoa, const struct sc_hid_event *event) {
|
|
|
|
uint8_t request_type = LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR;
|
|
|
|
uint8_t request = ACCESSORY_SEND_HID_EVENT;
|
|
|
|
// <https://source.android.com/devices/accessories/aoa2.html#hid-support>
|
|
|
|
// value (arg0): accessory assigned ID for the HID device
|
|
|
|
// index (arg1): 0 (unused)
|
|
|
|
uint16_t value = event->accessory_id;
|
|
|
|
uint16_t index = 0;
|
2024-01-25 18:45:21 +00:00
|
|
|
unsigned char *data = event->buffer;
|
2021-09-10 10:57:35 +00:00
|
|
|
uint16_t length = event->size;
|
2022-01-24 22:11:42 +00:00
|
|
|
int result = libusb_control_transfer(aoa->usb->handle, request_type,
|
2024-01-25 18:45:21 +00:00
|
|
|
request, value, index, data, length,
|
2021-09-10 10:57:35 +00:00
|
|
|
DEFAULT_TIMEOUT);
|
|
|
|
if (result < 0) {
|
2022-02-07 11:56:25 +00:00
|
|
|
LOGE("SEND_HID_EVENT: libusb error: %s", libusb_strerror(result));
|
2022-02-10 06:57:18 +00:00
|
|
|
sc_usb_check_disconnected(aoa->usb, result);
|
2021-09-10 10:57:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
sc_aoa_unregister_hid(struct sc_aoa *aoa, const uint16_t accessory_id) {
|
|
|
|
uint8_t request_type = LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR;
|
|
|
|
uint8_t request = ACCESSORY_UNREGISTER_HID;
|
|
|
|
// <https://source.android.com/devices/accessories/aoa2.html#hid-support>
|
|
|
|
// value (arg0): accessory assigned ID for the HID device
|
|
|
|
// index (arg1): 0
|
|
|
|
uint16_t value = accessory_id;
|
|
|
|
uint16_t index = 0;
|
2024-01-25 18:45:21 +00:00
|
|
|
unsigned char *data = NULL;
|
2021-09-10 10:57:35 +00:00
|
|
|
uint16_t length = 0;
|
2022-01-24 22:11:42 +00:00
|
|
|
int result = libusb_control_transfer(aoa->usb->handle, request_type,
|
2024-01-25 18:45:21 +00:00
|
|
|
request, value, index, data, length,
|
2021-09-10 10:57:35 +00:00
|
|
|
DEFAULT_TIMEOUT);
|
|
|
|
if (result < 0) {
|
2022-02-07 11:56:25 +00:00
|
|
|
LOGE("UNREGISTER_HID: libusb error: %s", libusb_strerror(result));
|
2022-02-10 06:57:18 +00:00
|
|
|
sc_usb_check_disconnected(aoa->usb, result);
|
2021-09-10 10:57:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
sc_aoa_push_hid_event(struct sc_aoa *aoa, const struct sc_hid_event *event) {
|
|
|
|
if (sc_get_log_level() <= SC_LOG_LEVEL_VERBOSE) {
|
|
|
|
sc_hid_event_log(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc_mutex_lock(&aoa->mutex);
|
2023-03-01 21:50:56 +00:00
|
|
|
bool full = sc_vecdeque_is_full(&aoa->queue);
|
|
|
|
if (!full) {
|
|
|
|
bool was_empty = sc_vecdeque_is_empty(&aoa->queue);
|
|
|
|
sc_vecdeque_push_noresize(&aoa->queue, *event);
|
|
|
|
if (was_empty) {
|
|
|
|
sc_cond_signal(&aoa->event_cond);
|
|
|
|
}
|
2021-09-10 10:57:35 +00:00
|
|
|
}
|
2023-03-01 21:50:56 +00:00
|
|
|
// Otherwise (if the queue is full), the event is discarded
|
|
|
|
|
2021-09-10 10:57:35 +00:00
|
|
|
sc_mutex_unlock(&aoa->mutex);
|
2023-03-01 21:50:56 +00:00
|
|
|
|
|
|
|
return !full;
|
2021-09-10 10:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
run_aoa_thread(void *data) {
|
|
|
|
struct sc_aoa *aoa = data;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
sc_mutex_lock(&aoa->mutex);
|
2023-03-01 21:50:56 +00:00
|
|
|
while (!aoa->stopped && sc_vecdeque_is_empty(&aoa->queue)) {
|
2021-09-10 10:57:35 +00:00
|
|
|
sc_cond_wait(&aoa->event_cond, &aoa->mutex);
|
|
|
|
}
|
|
|
|
if (aoa->stopped) {
|
|
|
|
// Stop immediately, do not process further events
|
|
|
|
sc_mutex_unlock(&aoa->mutex);
|
|
|
|
break;
|
|
|
|
}
|
2021-10-21 19:33:15 +00:00
|
|
|
|
2023-03-01 21:50:56 +00:00
|
|
|
assert(!sc_vecdeque_is_empty(&aoa->queue));
|
|
|
|
struct sc_hid_event event = sc_vecdeque_pop(&aoa->queue);
|
Wait SET_CLIPBOARD ack before Ctrl+v via HID
To allow seamless copy-paste, on Ctrl+v, a SET_CLIPBOARD request is
performed before injecting Ctrl+v.
But when HID keyboard is enabled, the Ctrl+v injection is not sent on
the same channel as the clipboard request, so they are not serialized,
and may occur in any order. If Ctrl+v happens to be injected before the
new clipboard content is set, then the old content is pasted instead,
which is incorrect.
To minimize the probability of occurrence of the wrong order, a delay of
2 milliseconds was added before injecting Ctrl+v. Then 5ms. But even
with 5ms, the wrong behavior sometimes happens.
To handle it properly, add an acknowledgement mechanism, so that Ctrl+v
is injected over AOA only after the SET_CLIPBOARD request has been
performed and acknowledged by the server.
Refs e4163321f00bb3830c6049bdb6c1515e7cc668a0
Refs 45b0f8123a52f5c73a5860d616f4ceba2766ca6a
PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
2021-11-21 16:40:11 +00:00
|
|
|
uint64_t ack_to_wait = event.ack_to_wait;
|
|
|
|
sc_mutex_unlock(&aoa->mutex);
|
|
|
|
|
|
|
|
if (ack_to_wait != SC_SEQUENCE_INVALID) {
|
|
|
|
LOGD("Waiting ack from server sequence=%" PRIu64_, ack_to_wait);
|
2022-01-22 09:52:13 +00:00
|
|
|
|
|
|
|
// If some events have ack_to_wait set, then sc_aoa must have been
|
|
|
|
// initialized with a non NULL acksync
|
|
|
|
assert(aoa->acksync);
|
|
|
|
|
2022-01-14 19:57:03 +00:00
|
|
|
// Do not block the loop indefinitely if the ack never comes (it
|
|
|
|
// should never happen)
|
Wait SET_CLIPBOARD ack before Ctrl+v via HID
To allow seamless copy-paste, on Ctrl+v, a SET_CLIPBOARD request is
performed before injecting Ctrl+v.
But when HID keyboard is enabled, the Ctrl+v injection is not sent on
the same channel as the clipboard request, so they are not serialized,
and may occur in any order. If Ctrl+v happens to be injected before the
new clipboard content is set, then the old content is pasted instead,
which is incorrect.
To minimize the probability of occurrence of the wrong order, a delay of
2 milliseconds was added before injecting Ctrl+v. Then 5ms. But even
with 5ms, the wrong behavior sometimes happens.
To handle it properly, add an acknowledgement mechanism, so that Ctrl+v
is injected over AOA only after the SET_CLIPBOARD request has been
performed and acknowledged by the server.
Refs e4163321f00bb3830c6049bdb6c1515e7cc668a0
Refs 45b0f8123a52f5c73a5860d616f4ceba2766ca6a
PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
2021-11-21 16:40:11 +00:00
|
|
|
sc_tick deadline = sc_tick_now() + SC_TICK_FROM_MS(500);
|
|
|
|
enum sc_acksync_wait_result result =
|
|
|
|
sc_acksync_wait(aoa->acksync, ack_to_wait, deadline);
|
|
|
|
|
|
|
|
if (result == SC_ACKSYNC_WAIT_TIMEOUT) {
|
|
|
|
LOGW("Ack not received after 500ms, discarding HID event");
|
|
|
|
sc_hid_event_destroy(&event);
|
|
|
|
continue;
|
|
|
|
} else if (result == SC_ACKSYNC_WAIT_INTR) {
|
|
|
|
// stopped
|
|
|
|
sc_hid_event_destroy(&event);
|
2021-10-21 19:33:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 10:57:35 +00:00
|
|
|
bool ok = sc_aoa_send_hid_event(aoa, &event);
|
|
|
|
sc_hid_event_destroy(&event);
|
|
|
|
if (!ok) {
|
|
|
|
LOGW("Could not send HID event to USB device");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
sc_aoa_start(struct sc_aoa *aoa) {
|
|
|
|
LOGD("Starting AOA thread");
|
|
|
|
|
2021-12-09 20:32:11 +00:00
|
|
|
bool ok = sc_thread_create(&aoa->thread, run_aoa_thread, "scrcpy-aoa", aoa);
|
2021-09-10 10:57:35 +00:00
|
|
|
if (!ok) {
|
2022-02-05 13:06:03 +00:00
|
|
|
LOGE("Could not start AOA thread");
|
2021-09-10 10:57:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_aoa_stop(struct sc_aoa *aoa) {
|
|
|
|
sc_mutex_lock(&aoa->mutex);
|
|
|
|
aoa->stopped = true;
|
|
|
|
sc_cond_signal(&aoa->event_cond);
|
|
|
|
sc_mutex_unlock(&aoa->mutex);
|
Wait SET_CLIPBOARD ack before Ctrl+v via HID
To allow seamless copy-paste, on Ctrl+v, a SET_CLIPBOARD request is
performed before injecting Ctrl+v.
But when HID keyboard is enabled, the Ctrl+v injection is not sent on
the same channel as the clipboard request, so they are not serialized,
and may occur in any order. If Ctrl+v happens to be injected before the
new clipboard content is set, then the old content is pasted instead,
which is incorrect.
To minimize the probability of occurrence of the wrong order, a delay of
2 milliseconds was added before injecting Ctrl+v. Then 5ms. But even
with 5ms, the wrong behavior sometimes happens.
To handle it properly, add an acknowledgement mechanism, so that Ctrl+v
is injected over AOA only after the SET_CLIPBOARD request has been
performed and acknowledged by the server.
Refs e4163321f00bb3830c6049bdb6c1515e7cc668a0
Refs 45b0f8123a52f5c73a5860d616f4ceba2766ca6a
PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814>
2021-11-21 16:40:11 +00:00
|
|
|
|
2022-01-22 09:52:13 +00:00
|
|
|
if (aoa->acksync) {
|
|
|
|
sc_acksync_interrupt(aoa->acksync);
|
|
|
|
}
|
2021-09-10 10:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_aoa_join(struct sc_aoa *aoa) {
|
|
|
|
sc_thread_join(&aoa->thread, NULL);
|
|
|
|
}
|