2021-09-10 10:57:35 +00:00
|
|
|
#ifndef SC_AOA_HID_H
|
|
|
|
#define SC_AOA_HID_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <libusb-1.0/libusb.h>
|
|
|
|
|
2022-01-24 21:56:12 +00:00
|
|
|
#include "usb.h"
|
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
|
|
|
#include "util/acksync.h"
|
2021-09-10 10:57:35 +00:00
|
|
|
#include "util/thread.h"
|
2021-10-21 19:33:15 +00:00
|
|
|
#include "util/tick.h"
|
2023-03-01 21:50:56 +00:00
|
|
|
#include "util/vecdeque.h"
|
2021-09-10 10:57:35 +00:00
|
|
|
|
|
|
|
struct sc_hid_event {
|
|
|
|
uint16_t accessory_id;
|
2024-01-25 19:01:34 +00:00
|
|
|
unsigned char *data;
|
2021-09-10 10:57:35 +00:00
|
|
|
uint16_t 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
|
|
|
uint64_t ack_to_wait;
|
2021-09-10 10:57:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Takes ownership of buffer
|
|
|
|
void
|
|
|
|
sc_hid_event_init(struct sc_hid_event *hid_event, uint16_t accessory_id,
|
2024-01-25 19:01:34 +00:00
|
|
|
unsigned char *data, uint16_t size);
|
2021-09-10 10:57:35 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
sc_hid_event_destroy(struct sc_hid_event *hid_event);
|
|
|
|
|
2023-03-01 21:50:56 +00:00
|
|
|
struct sc_hid_event_queue SC_VECDEQUE(struct sc_hid_event);
|
2021-09-10 10:57:35 +00:00
|
|
|
|
|
|
|
struct sc_aoa {
|
2022-01-24 22:11:42 +00:00
|
|
|
struct sc_usb *usb;
|
2021-09-10 10:57:35 +00:00
|
|
|
sc_thread thread;
|
|
|
|
sc_mutex mutex;
|
|
|
|
sc_cond event_cond;
|
|
|
|
bool stopped;
|
|
|
|
struct sc_hid_event_queue 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
|
|
|
|
|
|
|
struct sc_acksync *acksync;
|
2021-09-10 10:57:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
2022-01-24 22:11:42 +00:00
|
|
|
sc_aoa_init(struct sc_aoa *aoa, struct sc_usb *usb, struct sc_acksync *acksync);
|
2021-09-10 10:57:35 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
sc_aoa_destroy(struct sc_aoa *aoa);
|
|
|
|
|
|
|
|
bool
|
|
|
|
sc_aoa_start(struct sc_aoa *aoa);
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_aoa_stop(struct sc_aoa *aoa);
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_aoa_join(struct sc_aoa *aoa);
|
|
|
|
|
|
|
|
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
|
|
|
|
sc_aoa_unregister_hid(struct sc_aoa *aoa, uint16_t accessory_id);
|
|
|
|
|
|
|
|
bool
|
|
|
|
sc_aoa_push_hid_event(struct sc_aoa *aoa, const struct sc_hid_event *event);
|
|
|
|
|
|
|
|
#endif
|