2021-10-03 23:11:20 +08:00
|
|
|
#ifndef SC_KEY_PROCESSOR_H
|
|
|
|
#define SC_KEY_PROCESSOR_H
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <SDL2/SDL_events.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Key processor trait.
|
|
|
|
*
|
|
|
|
* Component able to process and inject keys should implement this trait.
|
|
|
|
*/
|
|
|
|
struct sc_key_processor {
|
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-22 00:40:11 +08:00
|
|
|
/**
|
|
|
|
* Set by the implementation to indicate that it must explicitly wait for
|
|
|
|
* the clipboard to be set on the device before injecting Ctrl+v to avoid
|
|
|
|
* race conditions. If it is set, the input_manager will pass a valid
|
|
|
|
* ack_to_wait to process_key() in case of clipboard synchronization
|
|
|
|
* resulting of the key event.
|
|
|
|
*/
|
|
|
|
bool async_paste;
|
|
|
|
|
2021-10-03 23:11:20 +08:00
|
|
|
const struct sc_key_processor_ops *ops;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sc_key_processor_ops {
|
2021-11-22 00:24:34 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the keyboard event
|
|
|
|
*
|
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-22 00:40:11 +08:00
|
|
|
* The `sequence` number (if different from `SC_SEQUENCE_INVALID`) indicates
|
|
|
|
* the acknowledgement number to wait for before injecting this event.
|
|
|
|
* This allows to ensure that the device clipboard is set before injecting
|
|
|
|
* Ctrl+v on the device.
|
2021-11-22 00:24:34 +08:00
|
|
|
*/
|
2021-10-03 23:11:20 +08:00
|
|
|
void
|
2021-11-22 00:24:34 +08:00
|
|
|
(*process_key)(struct sc_key_processor *kp, const SDL_KeyboardEvent *event,
|
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-22 00:40:11 +08:00
|
|
|
uint64_t ack_to_wait);
|
2021-10-03 23:11:20 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
(*process_text)(struct sc_key_processor *kp,
|
|
|
|
const SDL_TextInputEvent *event);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|