Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
907e55a66b | ||
|
|
6d98ab5d29 | ||
|
|
91ba44b653 | ||
|
|
7b143b8fbd | ||
|
|
8d1f58278e | ||
|
|
b2d815bfc7 | ||
|
|
ffdbf5990b | ||
|
|
9463850c24 | ||
|
|
6e38e0cbfe | ||
|
|
7040e8abc4 | ||
|
|
da5b0ec0d5 | ||
|
|
a9c8fa305d | ||
|
|
20b3f101a4 | ||
|
|
686733023b | ||
|
|
27eacc3c11 | ||
|
|
8507fea271 |
44
FAQ.md
44
FAQ.md
@@ -1,10 +1,5 @@
|
|||||||
# Frequently Asked Questions
|
# Frequently Asked Questions
|
||||||
|
|
||||||
## Common issues
|
|
||||||
|
|
||||||
The application is very young, it is not unlikely that you encounter problems
|
|
||||||
with it.
|
|
||||||
|
|
||||||
Here are the common reported problems and their status.
|
Here are the common reported problems and their status.
|
||||||
|
|
||||||
|
|
||||||
@@ -20,9 +15,13 @@ Windows may need some [drivers] to detect your device.
|
|||||||
[drivers]: https://developer.android.com/studio/run/oem-usb.html
|
[drivers]: https://developer.android.com/studio/run/oem-usb.html
|
||||||
|
|
||||||
|
|
||||||
### Mouse clicks do not work
|
### I can only mirror, I cannot interact with the device
|
||||||
|
|
||||||
On some devices, you may need to enable an option to allow [simulating input].
|
On some devices, you may need to enable an option to allow [simulating input].
|
||||||
|
In developer options, enable:
|
||||||
|
|
||||||
|
> **USB debugging (Security settings)**
|
||||||
|
> _Allow granting permissions and simulating input via USB debugging_
|
||||||
|
|
||||||
[simulating input]: https://github.com/Genymobile/scrcpy/issues/70#issuecomment-373286323
|
[simulating input]: https://github.com/Genymobile/scrcpy/issues/70#issuecomment-373286323
|
||||||
|
|
||||||
@@ -43,6 +42,16 @@ meson x --buildtype release -Dhidpi_support=false
|
|||||||
However, the video will be displayed at lower resolution.
|
However, the video will be displayed at lower resolution.
|
||||||
|
|
||||||
|
|
||||||
|
### The quality is low on HiDPI display
|
||||||
|
|
||||||
|
On Windows, you may need to configure the [scaling behavior].
|
||||||
|
|
||||||
|
> `scrcpy.exe` > Properties > Compatibility > Change high DPI settings >
|
||||||
|
> Override high DPI scaling behavior > Scaling performed by: _Application_.
|
||||||
|
|
||||||
|
[scaling behavior]: https://github.com/Genymobile/scrcpy/issues/40#issuecomment-424466723
|
||||||
|
|
||||||
|
|
||||||
### KWin compositor crashes
|
### KWin compositor crashes
|
||||||
|
|
||||||
On Plasma Desktop, compositor is disabled while _scrcpy_ is running.
|
On Plasma Desktop, compositor is disabled while _scrcpy_ is running.
|
||||||
@@ -50,3 +59,26 @@ On Plasma Desktop, compositor is disabled while _scrcpy_ is running.
|
|||||||
As a workaround, [disable "Block compositing"][kwin].
|
As a workaround, [disable "Block compositing"][kwin].
|
||||||
|
|
||||||
[kwin]: https://github.com/Genymobile/scrcpy/issues/114#issuecomment-378778613
|
[kwin]: https://github.com/Genymobile/scrcpy/issues/114#issuecomment-378778613
|
||||||
|
|
||||||
|
|
||||||
|
### I get an error "Could not open video stream"
|
||||||
|
|
||||||
|
There may be many reasons. One common cause is that the hardware encoder of your
|
||||||
|
device is not able to encode at the given definition:
|
||||||
|
|
||||||
|
```
|
||||||
|
ERROR: Exception on thread Thread[main,5,main]
|
||||||
|
android.media.MediaCodec$CodecException: Error 0xfffffc0e
|
||||||
|
...
|
||||||
|
Exit due to uncaughtException in main thread:
|
||||||
|
ERROR: Could not open video stream
|
||||||
|
INFO: Initial texture: 1080x2336
|
||||||
|
```
|
||||||
|
|
||||||
|
Just try with a lower definition:
|
||||||
|
|
||||||
|
```
|
||||||
|
scrcpy -m 1920
|
||||||
|
scrcpy -m 1024
|
||||||
|
scrcpy -m 800
|
||||||
|
```
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ src = [
|
|||||||
'src/command.c',
|
'src/command.c',
|
||||||
'src/control_msg.c',
|
'src/control_msg.c',
|
||||||
'src/controller.c',
|
'src/controller.c',
|
||||||
'src/convert.c',
|
|
||||||
'src/decoder.c',
|
'src/decoder.c',
|
||||||
'src/device.c',
|
'src/device.c',
|
||||||
'src/device_msg.c',
|
'src/device_msg.c',
|
||||||
|
'src/event_converter.c',
|
||||||
'src/file_handler.c',
|
'src/file_handler.c',
|
||||||
'src/fps_counter.c',
|
'src/fps_counter.c',
|
||||||
'src/input_manager.c',
|
'src/input_manager.c',
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ buffer_write32be(uint8_t *buf, uint32_t value) {
|
|||||||
buf[3] = value;
|
buf[3] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
buffer_write64be(uint8_t *buf, uint64_t value) {
|
||||||
|
buffer_write32be(buf, value >> 32);
|
||||||
|
buffer_write32be(&buf[4], (uint32_t) value);
|
||||||
|
}
|
||||||
|
|
||||||
static inline uint16_t
|
static inline uint16_t
|
||||||
buffer_read16be(const uint8_t *buf) {
|
buffer_read16be(const uint8_t *buf) {
|
||||||
return (buf[0] << 8) | buf[1];
|
return (buf[0] << 8) | buf[1];
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "control_msg.h"
|
#include "control_msg.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <SDL_assert.h>
|
||||||
|
|
||||||
#include "buffer_util.h"
|
#include "buffer_util.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
@@ -23,6 +24,16 @@ write_string(const char *utf8, size_t max_len, unsigned char *buf) {
|
|||||||
return 2 + len;
|
return 2 + len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint16_t
|
||||||
|
to_fixed_point_16(float f) {
|
||||||
|
SDL_assert(f >= 0.0f && f <= 1.0f);
|
||||||
|
uint32_t u = f * 0x1p16f; // 2^16
|
||||||
|
if (u >= 0xffff) {
|
||||||
|
u = 0xffff;
|
||||||
|
}
|
||||||
|
return (uint16_t) u;
|
||||||
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
||||||
buf[0] = msg->type;
|
buf[0] = msg->type;
|
||||||
@@ -42,6 +53,14 @@ control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
|||||||
buffer_write32be(&buf[2], msg->inject_mouse_event.buttons);
|
buffer_write32be(&buf[2], msg->inject_mouse_event.buttons);
|
||||||
write_position(&buf[6], &msg->inject_mouse_event.position);
|
write_position(&buf[6], &msg->inject_mouse_event.position);
|
||||||
return 18;
|
return 18;
|
||||||
|
case CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT:
|
||||||
|
buf[1] = msg->inject_touch_event.action;
|
||||||
|
buffer_write64be(&buf[2], msg->inject_touch_event.finger_id);
|
||||||
|
write_position(&buf[10], &msg->inject_touch_event.position);
|
||||||
|
uint16_t pressure =
|
||||||
|
to_fixed_point_16(msg->inject_touch_event.pressure);
|
||||||
|
buffer_write16be(&buf[22], pressure);
|
||||||
|
return 24;
|
||||||
case CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT:
|
case CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT:
|
||||||
write_position(&buf[1], &msg->inject_scroll_event.position);
|
write_position(&buf[1], &msg->inject_scroll_event.position);
|
||||||
buffer_write32be(&buf[13],
|
buffer_write32be(&buf[13],
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ enum control_msg_type {
|
|||||||
CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
||||||
CONTROL_MSG_TYPE_INJECT_TEXT,
|
CONTROL_MSG_TYPE_INJECT_TEXT,
|
||||||
CONTROL_MSG_TYPE_INJECT_MOUSE_EVENT,
|
CONTROL_MSG_TYPE_INJECT_MOUSE_EVENT,
|
||||||
|
CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||||
CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
||||||
CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
||||||
CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
||||||
@@ -49,6 +50,12 @@ struct control_msg {
|
|||||||
enum android_motionevent_buttons buttons;
|
enum android_motionevent_buttons buttons;
|
||||||
struct position position;
|
struct position position;
|
||||||
} inject_mouse_event;
|
} inject_mouse_event;
|
||||||
|
struct {
|
||||||
|
enum android_motionevent_action action;
|
||||||
|
uint64_t finger_id;
|
||||||
|
struct position position;
|
||||||
|
float pressure;
|
||||||
|
} inject_touch_event;
|
||||||
struct {
|
struct {
|
||||||
struct position position;
|
struct position position;
|
||||||
int32_t hscroll;
|
int32_t hscroll;
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
#ifndef CONVERT_H
|
|
||||||
#define CONVERT_H
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <SDL2/SDL_events.h>
|
|
||||||
|
|
||||||
#include "control_msg.h"
|
|
||||||
|
|
||||||
struct complete_mouse_motion_event {
|
|
||||||
SDL_MouseMotionEvent *mouse_motion_event;
|
|
||||||
struct size screen_size;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct complete_mouse_wheel_event {
|
|
||||||
SDL_MouseWheelEvent *mouse_wheel_event;
|
|
||||||
struct point position;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool
|
|
||||||
input_key_from_sdl_to_android(const SDL_KeyboardEvent *from,
|
|
||||||
struct control_msg *to);
|
|
||||||
|
|
||||||
bool
|
|
||||||
mouse_button_from_sdl_to_android(const SDL_MouseButtonEvent *from,
|
|
||||||
struct size screen_size,
|
|
||||||
struct control_msg *to);
|
|
||||||
|
|
||||||
// the video size may be different from the real device size, so we need the
|
|
||||||
// size to which the absolute position apply, to scale it accordingly
|
|
||||||
bool
|
|
||||||
mouse_motion_from_sdl_to_android(const SDL_MouseMotionEvent *from,
|
|
||||||
struct size screen_size,
|
|
||||||
struct control_msg *to);
|
|
||||||
|
|
||||||
// on Android, a scroll event requires the current mouse position
|
|
||||||
bool
|
|
||||||
mouse_wheel_from_sdl_to_android(const SDL_MouseWheelEvent *from,
|
|
||||||
struct position position,
|
|
||||||
struct control_msg *to);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "convert.h"
|
#include "event_converter.h"
|
||||||
|
|
||||||
#define MAP(FROM, TO) case FROM: *to = TO; return true
|
#define MAP(FROM, TO) case FROM: *to = TO; return true
|
||||||
#define FAIL default: return false
|
#define FAIL default: return false
|
||||||
@@ -31,7 +31,6 @@ autocomplete_metastate(enum android_metastate metastate) {
|
|||||||
return metastate;
|
return metastate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static enum android_metastate
|
static enum android_metastate
|
||||||
convert_meta_state(SDL_Keymod mod) {
|
convert_meta_state(SDL_Keymod mod) {
|
||||||
enum android_metastate metastate = 0;
|
enum android_metastate metastate = 0;
|
||||||
@@ -158,8 +157,7 @@ convert_mouse_buttons(uint32_t state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
input_key_from_sdl_to_android(const SDL_KeyboardEvent *from,
|
convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to) {
|
||||||
struct control_msg *to) {
|
|
||||||
to->type = CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
to->type = CONTROL_MSG_TYPE_INJECT_KEYCODE;
|
||||||
|
|
||||||
if (!convert_keycode_action(from->type, &to->inject_keycode.action)) {
|
if (!convert_keycode_action(from->type, &to->inject_keycode.action)) {
|
||||||
@@ -177,8 +175,7 @@ input_key_from_sdl_to_android(const SDL_KeyboardEvent *from,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
mouse_button_from_sdl_to_android(const SDL_MouseButtonEvent *from,
|
convert_mouse_button(const SDL_MouseButtonEvent *from, struct size screen_size,
|
||||||
struct size screen_size,
|
|
||||||
struct control_msg *to) {
|
struct control_msg *to) {
|
||||||
to->type = CONTROL_MSG_TYPE_INJECT_MOUSE_EVENT;
|
to->type = CONTROL_MSG_TYPE_INJECT_MOUSE_EVENT;
|
||||||
|
|
||||||
@@ -196,8 +193,7 @@ mouse_button_from_sdl_to_android(const SDL_MouseButtonEvent *from,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
mouse_motion_from_sdl_to_android(const SDL_MouseMotionEvent *from,
|
convert_mouse_motion(const SDL_MouseMotionEvent *from, struct size screen_size,
|
||||||
struct size screen_size,
|
|
||||||
struct control_msg *to) {
|
struct control_msg *to) {
|
||||||
to->type = CONTROL_MSG_TYPE_INJECT_MOUSE_EVENT;
|
to->type = CONTROL_MSG_TYPE_INJECT_MOUSE_EVENT;
|
||||||
to->inject_mouse_event.action = AMOTION_EVENT_ACTION_MOVE;
|
to->inject_mouse_event.action = AMOTION_EVENT_ACTION_MOVE;
|
||||||
@@ -209,9 +205,36 @@ mouse_motion_from_sdl_to_android(const SDL_MouseMotionEvent *from,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
convert_touch_action(SDL_EventType from, enum android_motionevent_action *to) {
|
||||||
|
switch (from) {
|
||||||
|
MAP(SDL_FINGERMOTION, AMOTION_EVENT_ACTION_MOVE);
|
||||||
|
MAP(SDL_FINGERDOWN, AMOTION_EVENT_ACTION_DOWN);
|
||||||
|
MAP(SDL_FINGERUP, AMOTION_EVENT_ACTION_UP);
|
||||||
|
FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
mouse_wheel_from_sdl_to_android(const SDL_MouseWheelEvent *from,
|
convert_touch(const SDL_TouchFingerEvent *from, struct size screen_size,
|
||||||
struct position position,
|
struct control_msg *to) {
|
||||||
|
to->type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT;
|
||||||
|
|
||||||
|
if (!convert_touch_action(from->type, &to->inject_touch_event.action)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
to->inject_touch_event.finger_id = from->fingerId;
|
||||||
|
to->inject_touch_event.position.screen_size = screen_size;
|
||||||
|
// SDL touch event coordinates are normalized in the range [0; 1]
|
||||||
|
to->inject_touch_event.position.point.x = from->x * screen_size.width;
|
||||||
|
to->inject_touch_event.position.point.y = from->x * screen_size.height;
|
||||||
|
to->inject_touch_event.pressure = from->pressure;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
convert_mouse_wheel(const SDL_MouseWheelEvent *from, struct position position,
|
||||||
struct control_msg *to) {
|
struct control_msg *to) {
|
||||||
to->type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT;
|
to->type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT;
|
||||||
|
|
||||||
41
app/src/event_converter.h
Normal file
41
app/src/event_converter.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#ifndef CONVERT_H
|
||||||
|
#define CONVERT_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <SDL2/SDL_events.h>
|
||||||
|
|
||||||
|
#include "control_msg.h"
|
||||||
|
|
||||||
|
struct complete_mouse_motion_event {
|
||||||
|
SDL_MouseMotionEvent *mouse_motion_event;
|
||||||
|
struct size screen_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct complete_mouse_wheel_event {
|
||||||
|
SDL_MouseWheelEvent *mouse_wheel_event;
|
||||||
|
struct point position;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool
|
||||||
|
convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to);
|
||||||
|
|
||||||
|
bool
|
||||||
|
convert_mouse_button(const SDL_MouseButtonEvent *from, struct size screen_size,
|
||||||
|
struct control_msg *to);
|
||||||
|
|
||||||
|
// the video size may be different from the real device size, so we need the
|
||||||
|
// size to which the absolute position apply, to scale it accordingly
|
||||||
|
bool
|
||||||
|
convert_mouse_motion(const SDL_MouseMotionEvent *from, struct size screen_size,
|
||||||
|
struct control_msg *to);
|
||||||
|
|
||||||
|
bool
|
||||||
|
convert_touch(const SDL_TouchFingerEvent *from, struct size screen_size,
|
||||||
|
struct control_msg *to);
|
||||||
|
|
||||||
|
// on Android, a scroll event requires the current mouse position
|
||||||
|
bool
|
||||||
|
convert_mouse_wheel(const SDL_MouseWheelEvent *from, struct position position,
|
||||||
|
struct control_msg *to);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "input_manager.h"
|
#include "input_manager.h"
|
||||||
|
|
||||||
#include <SDL2/SDL_assert.h>
|
#include <SDL2/SDL_assert.h>
|
||||||
#include "convert.h"
|
#include "event_converter.h"
|
||||||
#include "lock_util.h"
|
#include "lock_util.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
@@ -373,7 +373,7 @@ input_manager_process_key(struct input_manager *input_manager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct control_msg msg;
|
struct control_msg msg;
|
||||||
if (input_key_from_sdl_to_android(event, &msg)) {
|
if (convert_input_key(event, &msg)) {
|
||||||
if (!controller_push_msg(controller, &msg)) {
|
if (!controller_push_msg(controller, &msg)) {
|
||||||
LOGW("Could not request 'inject keycode'");
|
LOGW("Could not request 'inject keycode'");
|
||||||
}
|
}
|
||||||
@@ -387,16 +387,29 @@ input_manager_process_mouse_motion(struct input_manager *input_manager,
|
|||||||
// do not send motion events when no button is pressed
|
// do not send motion events when no button is pressed
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (event->which == SDL_TOUCH_MOUSEID) {
|
||||||
|
// simulated from touch events, so it's a duplicate
|
||||||
|
return;
|
||||||
|
}
|
||||||
struct control_msg msg;
|
struct control_msg msg;
|
||||||
if (mouse_motion_from_sdl_to_android(event,
|
if (convert_mouse_motion(event, input_manager->screen->frame_size, &msg)) {
|
||||||
input_manager->screen->frame_size,
|
|
||||||
&msg)) {
|
|
||||||
if (!controller_push_msg(input_manager->controller, &msg)) {
|
if (!controller_push_msg(input_manager->controller, &msg)) {
|
||||||
LOGW("Could not request 'inject mouse motion event'");
|
LOGW("Could not request 'inject mouse motion event'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
input_manager_process_touch(struct input_manager *input_manager,
|
||||||
|
const SDL_TouchFingerEvent *event) {
|
||||||
|
struct control_msg msg;
|
||||||
|
if (convert_touch(event, input_manager->screen->frame_size, &msg)) {
|
||||||
|
if (!controller_push_msg(input_manager->controller, &msg)) {
|
||||||
|
LOGW("Could not request 'inject touch event'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
is_outside_device_screen(struct input_manager *input_manager, int x, int y)
|
is_outside_device_screen(struct input_manager *input_manager, int x, int y)
|
||||||
{
|
{
|
||||||
@@ -434,9 +447,7 @@ input_manager_process_mouse_button(struct input_manager *input_manager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct control_msg msg;
|
struct control_msg msg;
|
||||||
if (mouse_button_from_sdl_to_android(event,
|
if (convert_mouse_button(event, input_manager->screen->frame_size, &msg)) {
|
||||||
input_manager->screen->frame_size,
|
|
||||||
&msg)) {
|
|
||||||
if (!controller_push_msg(input_manager->controller, &msg)) {
|
if (!controller_push_msg(input_manager->controller, &msg)) {
|
||||||
LOGW("Could not request 'inject mouse button event'");
|
LOGW("Could not request 'inject mouse button event'");
|
||||||
}
|
}
|
||||||
@@ -451,7 +462,7 @@ input_manager_process_mouse_wheel(struct input_manager *input_manager,
|
|||||||
.point = get_mouse_point(input_manager->screen),
|
.point = get_mouse_point(input_manager->screen),
|
||||||
};
|
};
|
||||||
struct control_msg msg;
|
struct control_msg msg;
|
||||||
if (mouse_wheel_from_sdl_to_android(event, position, &msg)) {
|
if (convert_mouse_wheel(event, position, &msg)) {
|
||||||
if (!controller_push_msg(input_manager->controller, &msg)) {
|
if (!controller_push_msg(input_manager->controller, &msg)) {
|
||||||
LOGW("Could not request 'inject mouse wheel event'");
|
LOGW("Could not request 'inject mouse wheel event'");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ void
|
|||||||
input_manager_process_mouse_motion(struct input_manager *input_manager,
|
input_manager_process_mouse_motion(struct input_manager *input_manager,
|
||||||
const SDL_MouseMotionEvent *event);
|
const SDL_MouseMotionEvent *event);
|
||||||
|
|
||||||
|
void
|
||||||
|
input_manager_process_touch(struct input_manager *input_manager,
|
||||||
|
const SDL_TouchFingerEvent *event);
|
||||||
|
|
||||||
void
|
void
|
||||||
input_manager_process_mouse_button(struct input_manager *input_manager,
|
input_manager_process_mouse_button(struct input_manager *input_manager,
|
||||||
const SDL_MouseButtonEvent *event,
|
const SDL_MouseButtonEvent *event,
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ record_packet_new(const AVPacket *packet) {
|
|||||||
if (!rec) {
|
if (!rec) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// av_packet_ref() does not initialize all fields in old FFmpeg versions
|
||||||
|
// See <https://github.com/Genymobile/scrcpy/issues/707>
|
||||||
|
av_init_packet(&rec->packet);
|
||||||
|
|
||||||
if (av_packet_ref(&rec->packet, packet)) {
|
if (av_packet_ref(&rec->packet, packet)) {
|
||||||
SDL_free(rec);
|
SDL_free(rec);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -87,6 +92,7 @@ recorder_init(struct recorder *recorder,
|
|||||||
recorder->format = format;
|
recorder->format = format;
|
||||||
recorder->declared_frame_size = declared_frame_size;
|
recorder->declared_frame_size = declared_frame_size;
|
||||||
recorder->header_written = false;
|
recorder->header_written = false;
|
||||||
|
recorder->previous = NULL;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -219,13 +225,22 @@ recorder_rescale_packet(struct recorder *recorder, AVPacket *packet) {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
recorder_write(struct recorder *recorder, AVPacket *packet) {
|
recorder_write(struct recorder *recorder, AVPacket *packet) {
|
||||||
SDL_assert(packet->pts != AV_NOPTS_VALUE);
|
|
||||||
if (!recorder->header_written) {
|
if (!recorder->header_written) {
|
||||||
|
if (packet->pts != AV_NOPTS_VALUE) {
|
||||||
|
LOGE("The first packet is not a config packet");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
bool ok = recorder_write_header(recorder, packet);
|
bool ok = recorder_write_header(recorder, packet);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
recorder->header_written = true;
|
recorder->header_written = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packet->pts == AV_NOPTS_VALUE) {
|
||||||
|
// ignore config packets
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
recorder_rescale_packet(recorder, packet);
|
recorder_rescale_packet(recorder, packet);
|
||||||
@@ -248,6 +263,19 @@ run_recorder(void *data) {
|
|||||||
|
|
||||||
if (recorder->stopped && queue_is_empty(&recorder->queue)) {
|
if (recorder->stopped && queue_is_empty(&recorder->queue)) {
|
||||||
mutex_unlock(recorder->mutex);
|
mutex_unlock(recorder->mutex);
|
||||||
|
struct record_packet *last = recorder->previous;
|
||||||
|
if (last) {
|
||||||
|
// assign an arbitrary duration to the last packet
|
||||||
|
last->packet.duration = 100000;
|
||||||
|
bool ok = recorder_write(recorder, &last->packet);
|
||||||
|
if (!ok) {
|
||||||
|
// failing to write the last frame is not very serious, no
|
||||||
|
// future frame may depend on it, so the resulting file
|
||||||
|
// will still be valid
|
||||||
|
LOGW("Could not record last packet");
|
||||||
|
}
|
||||||
|
record_packet_delete(last);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,8 +284,20 @@ run_recorder(void *data) {
|
|||||||
|
|
||||||
mutex_unlock(recorder->mutex);
|
mutex_unlock(recorder->mutex);
|
||||||
|
|
||||||
bool ok = recorder_write(recorder, &rec->packet);
|
// recorder->previous is only written from this thread, no need to lock
|
||||||
record_packet_delete(rec);
|
struct record_packet *previous = recorder->previous;
|
||||||
|
recorder->previous = rec;
|
||||||
|
|
||||||
|
if (!previous) {
|
||||||
|
// we just received the first packet
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we now know the duration of the previous packet
|
||||||
|
previous->packet.duration = rec->packet.pts - previous->packet.pts;
|
||||||
|
|
||||||
|
bool ok = recorder_write(recorder, &previous->packet);
|
||||||
|
record_packet_delete(previous);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGE("Could not record packet");
|
LOGE("Could not record packet");
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ struct recorder {
|
|||||||
bool stopped; // set on recorder_stop() by the stream reader
|
bool stopped; // set on recorder_stop() by the stream reader
|
||||||
bool failed; // set on packet write failure
|
bool failed; // set on packet write failure
|
||||||
struct recorder_queue queue;
|
struct recorder_queue queue;
|
||||||
|
|
||||||
|
// we can write a packet only once we received the next one so that we can
|
||||||
|
// set its duration (next_pts - current_pts)
|
||||||
|
// "previous" is only accessed from the recorder thread, so it does not
|
||||||
|
// need to be protected by the mutex
|
||||||
|
struct record_packet *previous;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -180,6 +180,11 @@ handle_event(SDL_Event *event, bool control) {
|
|||||||
input_manager_process_mouse_button(&input_manager, &event->button,
|
input_manager_process_mouse_button(&input_manager, &event->button,
|
||||||
control);
|
control);
|
||||||
break;
|
break;
|
||||||
|
case SDL_FINGERMOTION:
|
||||||
|
case SDL_FINGERDOWN:
|
||||||
|
case SDL_FINGERUP:
|
||||||
|
input_manager_process_touch(&input_manager, &event->tfinger);
|
||||||
|
break;
|
||||||
case SDL_DROPFILE: {
|
case SDL_DROPFILE: {
|
||||||
if (!control) {
|
if (!control) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -69,6 +69,15 @@ notify_stopped(void) {
|
|||||||
SDL_PushEvent(&stop_event);
|
SDL_PushEvent(&stop_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
process_config_packet(struct stream *stream, AVPacket *packet) {
|
||||||
|
if (stream->recorder && !recorder_push(stream->recorder, packet)) {
|
||||||
|
LOGE("Could not send config packet to recorder");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
process_frame(struct stream *stream, AVPacket *packet) {
|
process_frame(struct stream *stream, AVPacket *packet) {
|
||||||
if (stream->decoder && !decoder_push(stream->decoder, packet)) {
|
if (stream->decoder && !decoder_push(stream->decoder, packet)) {
|
||||||
@@ -148,7 +157,13 @@ stream_push_packet(struct stream *stream, AVPacket *packet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_config) {
|
if (is_config) {
|
||||||
|
// config packet
|
||||||
|
bool ok = process_config_packet(stream, packet);
|
||||||
|
if (!ok) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// data packet
|
// data packet
|
||||||
bool ok = stream_parse(stream, packet);
|
bool ok = stream_parse(stream, packet);
|
||||||
|
|
||||||
|
|||||||
@@ -99,6 +99,41 @@ static void test_serialize_inject_mouse_event(void) {
|
|||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
}
|
}
|
||||||
|
#include <stdio.h>
|
||||||
|
static void test_serialize_inject_touch_event(void) {
|
||||||
|
struct control_msg msg = {
|
||||||
|
.type = CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||||
|
.inject_touch_event = {
|
||||||
|
.action = AMOTION_EVENT_ACTION_DOWN,
|
||||||
|
.finger_id = 0x1234567887654321L,
|
||||||
|
.position = {
|
||||||
|
.point = {
|
||||||
|
.x = 100,
|
||||||
|
.y = 200,
|
||||||
|
},
|
||||||
|
.screen_size = {
|
||||||
|
.width = 1080,
|
||||||
|
.height = 1920,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.pressure = 1.0f,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned char buf[CONTROL_MSG_SERIALIZED_MAX_SIZE];
|
||||||
|
int size = control_msg_serialize(&msg, buf);
|
||||||
|
assert(size == 24);
|
||||||
|
|
||||||
|
const unsigned char expected[] = {
|
||||||
|
CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||||
|
0x00, // AKEY_EVENT_ACTION_DOWN
|
||||||
|
0x12, 0x34, 0x56, 0x78, 0x87, 0x65, 0x43, 0x21, // finger id
|
||||||
|
0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0xc8, // 100 200
|
||||||
|
0x04, 0x38, 0x07, 0x80, // 1080 1920
|
||||||
|
0xff, 0xff, // pressure
|
||||||
|
};
|
||||||
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
|
}
|
||||||
|
|
||||||
static void test_serialize_inject_scroll_event(void) {
|
static void test_serialize_inject_scroll_event(void) {
|
||||||
struct control_msg msg = {
|
struct control_msg msg = {
|
||||||
@@ -237,6 +272,7 @@ int main(void) {
|
|||||||
test_serialize_inject_text();
|
test_serialize_inject_text();
|
||||||
test_serialize_inject_text_long();
|
test_serialize_inject_text_long();
|
||||||
test_serialize_inject_mouse_event();
|
test_serialize_inject_mouse_event();
|
||||||
|
test_serialize_inject_touch_event();
|
||||||
test_serialize_inject_scroll_event();
|
test_serialize_inject_scroll_event();
|
||||||
test_serialize_back_or_screen_on();
|
test_serialize_back_or_screen_on();
|
||||||
test_serialize_expand_notification_panel();
|
test_serialize_expand_notification_panel();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ if prebuilt_server == ''
|
|||||||
build_always: true, # gradle is responsible for tracking source changes
|
build_always: true, # gradle is responsible for tracking source changes
|
||||||
output: 'scrcpy-server.jar',
|
output: 'scrcpy-server.jar',
|
||||||
command: [find_program('./scripts/build-wrapper.sh'), meson.current_source_dir(), '@OUTPUT@', get_option('buildtype')],
|
command: [find_program('./scripts/build-wrapper.sh'), meson.current_source_dir(), '@OUTPUT@', get_option('buildtype')],
|
||||||
|
console: true,
|
||||||
install: true,
|
install: true,
|
||||||
install_dir: 'share/scrcpy')
|
install_dir: 'share/scrcpy')
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -8,13 +8,14 @@ public final class ControlMessage {
|
|||||||
public static final int TYPE_INJECT_KEYCODE = 0;
|
public static final int TYPE_INJECT_KEYCODE = 0;
|
||||||
public static final int TYPE_INJECT_TEXT = 1;
|
public static final int TYPE_INJECT_TEXT = 1;
|
||||||
public static final int TYPE_INJECT_MOUSE_EVENT = 2;
|
public static final int TYPE_INJECT_MOUSE_EVENT = 2;
|
||||||
public static final int TYPE_INJECT_SCROLL_EVENT = 3;
|
public static final int TYPE_INJECT_TOUCH_EVENT = 3;
|
||||||
public static final int TYPE_BACK_OR_SCREEN_ON = 4;
|
public static final int TYPE_INJECT_SCROLL_EVENT = 4;
|
||||||
public static final int TYPE_EXPAND_NOTIFICATION_PANEL = 5;
|
public static final int TYPE_BACK_OR_SCREEN_ON = 5;
|
||||||
public static final int TYPE_COLLAPSE_NOTIFICATION_PANEL = 6;
|
public static final int TYPE_EXPAND_NOTIFICATION_PANEL = 6;
|
||||||
public static final int TYPE_GET_CLIPBOARD = 7;
|
public static final int TYPE_COLLAPSE_NOTIFICATION_PANEL = 7;
|
||||||
public static final int TYPE_SET_CLIPBOARD = 8;
|
public static final int TYPE_GET_CLIPBOARD = 8;
|
||||||
public static final int TYPE_SET_SCREEN_POWER_MODE = 9;
|
public static final int TYPE_SET_CLIPBOARD = 9;
|
||||||
|
public static final int TYPE_SET_SCREEN_POWER_MODE = 10;
|
||||||
|
|
||||||
private int type;
|
private int type;
|
||||||
private String text;
|
private String text;
|
||||||
@@ -22,6 +23,8 @@ public final class ControlMessage {
|
|||||||
private int action; // KeyEvent.ACTION_* or MotionEvent.ACTION_* or POWER_MODE_*
|
private int action; // KeyEvent.ACTION_* or MotionEvent.ACTION_* or POWER_MODE_*
|
||||||
private int keycode; // KeyEvent.KEYCODE_*
|
private int keycode; // KeyEvent.KEYCODE_*
|
||||||
private int buttons; // MotionEvent.BUTTON_*
|
private int buttons; // MotionEvent.BUTTON_*
|
||||||
|
private long fingerId;
|
||||||
|
private float pressure;
|
||||||
private Position position;
|
private Position position;
|
||||||
private int hScroll;
|
private int hScroll;
|
||||||
private int vScroll;
|
private int vScroll;
|
||||||
@@ -30,60 +33,70 @@ public final class ControlMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ControlMessage createInjectKeycode(int action, int keycode, int metaState) {
|
public static ControlMessage createInjectKeycode(int action, int keycode, int metaState) {
|
||||||
ControlMessage event = new ControlMessage();
|
ControlMessage msg = new ControlMessage();
|
||||||
event.type = TYPE_INJECT_KEYCODE;
|
msg.type = TYPE_INJECT_KEYCODE;
|
||||||
event.action = action;
|
msg.action = action;
|
||||||
event.keycode = keycode;
|
msg.keycode = keycode;
|
||||||
event.metaState = metaState;
|
msg.metaState = metaState;
|
||||||
return event;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlMessage createInjectText(String text) {
|
public static ControlMessage createInjectText(String text) {
|
||||||
ControlMessage event = new ControlMessage();
|
ControlMessage msg = new ControlMessage();
|
||||||
event.type = TYPE_INJECT_TEXT;
|
msg.type = TYPE_INJECT_TEXT;
|
||||||
event.text = text;
|
msg.text = text;
|
||||||
return event;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlMessage createInjectMouseEvent(int action, int buttons, Position position) {
|
public static ControlMessage createInjectMouseEvent(int action, int buttons, Position position) {
|
||||||
ControlMessage event = new ControlMessage();
|
ControlMessage msg = new ControlMessage();
|
||||||
event.type = TYPE_INJECT_MOUSE_EVENT;
|
msg.type = TYPE_INJECT_MOUSE_EVENT;
|
||||||
event.action = action;
|
msg.action = action;
|
||||||
event.buttons = buttons;
|
msg.buttons = buttons;
|
||||||
event.position = position;
|
msg.position = position;
|
||||||
return event;
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ControlMessage createInjectTouchEvent(int action, long fingerId, Position position, float pressure) {
|
||||||
|
ControlMessage msg = new ControlMessage();
|
||||||
|
msg.type = TYPE_INJECT_TOUCH_EVENT;
|
||||||
|
msg.action = action;
|
||||||
|
msg.fingerId = fingerId;
|
||||||
|
msg.pressure = pressure;
|
||||||
|
msg.position = position;
|
||||||
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlMessage createInjectScrollEvent(Position position, int hScroll, int vScroll) {
|
public static ControlMessage createInjectScrollEvent(Position position, int hScroll, int vScroll) {
|
||||||
ControlMessage event = new ControlMessage();
|
ControlMessage msg = new ControlMessage();
|
||||||
event.type = TYPE_INJECT_SCROLL_EVENT;
|
msg.type = TYPE_INJECT_SCROLL_EVENT;
|
||||||
event.position = position;
|
msg.position = position;
|
||||||
event.hScroll = hScroll;
|
msg.hScroll = hScroll;
|
||||||
event.vScroll = vScroll;
|
msg.vScroll = vScroll;
|
||||||
return event;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlMessage createSetClipboard(String text) {
|
public static ControlMessage createSetClipboard(String text) {
|
||||||
ControlMessage event = new ControlMessage();
|
ControlMessage msg = new ControlMessage();
|
||||||
event.type = TYPE_SET_CLIPBOARD;
|
msg.type = TYPE_SET_CLIPBOARD;
|
||||||
event.text = text;
|
msg.text = text;
|
||||||
return event;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mode one of the {@code Device.SCREEN_POWER_MODE_*} constants
|
* @param mode one of the {@code Device.SCREEN_POWER_MODE_*} constants
|
||||||
*/
|
*/
|
||||||
public static ControlMessage createSetScreenPowerMode(int mode) {
|
public static ControlMessage createSetScreenPowerMode(int mode) {
|
||||||
ControlMessage event = new ControlMessage();
|
ControlMessage msg = new ControlMessage();
|
||||||
event.type = TYPE_SET_SCREEN_POWER_MODE;
|
msg.type = TYPE_SET_SCREEN_POWER_MODE;
|
||||||
event.action = mode;
|
msg.action = mode;
|
||||||
return event;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlMessage createEmpty(int type) {
|
public static ControlMessage createEmpty(int type) {
|
||||||
ControlMessage event = new ControlMessage();
|
ControlMessage msg = new ControlMessage();
|
||||||
event.type = type;
|
msg.type = type;
|
||||||
return event;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getType() {
|
public int getType() {
|
||||||
@@ -110,6 +123,14 @@ public final class ControlMessage {
|
|||||||
return buttons;
|
return buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getFingerId() {
|
||||||
|
return fingerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPressure() {
|
||||||
|
return pressure;
|
||||||
|
}
|
||||||
|
|
||||||
public Position getPosition() {
|
public Position getPosition() {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ public class ControlMessageReader {
|
|||||||
|
|
||||||
private static final int INJECT_KEYCODE_PAYLOAD_LENGTH = 9;
|
private static final int INJECT_KEYCODE_PAYLOAD_LENGTH = 9;
|
||||||
private static final int INJECT_MOUSE_EVENT_PAYLOAD_LENGTH = 17;
|
private static final int INJECT_MOUSE_EVENT_PAYLOAD_LENGTH = 17;
|
||||||
|
private static final int INJECT_TOUCH_EVENT_PAYLOAD_LENGTH = 21;
|
||||||
private static final int INJECT_SCROLL_EVENT_PAYLOAD_LENGTH = 20;
|
private static final int INJECT_SCROLL_EVENT_PAYLOAD_LENGTH = 20;
|
||||||
private static final int SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH = 1;
|
private static final int SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH = 1;
|
||||||
|
|
||||||
@@ -62,6 +63,9 @@ public class ControlMessageReader {
|
|||||||
case ControlMessage.TYPE_INJECT_MOUSE_EVENT:
|
case ControlMessage.TYPE_INJECT_MOUSE_EVENT:
|
||||||
msg = parseInjectMouseEvent();
|
msg = parseInjectMouseEvent();
|
||||||
break;
|
break;
|
||||||
|
case ControlMessage.TYPE_INJECT_TOUCH_EVENT:
|
||||||
|
msg = parseInjectTouchEvent();
|
||||||
|
break;
|
||||||
case ControlMessage.TYPE_INJECT_SCROLL_EVENT:
|
case ControlMessage.TYPE_INJECT_SCROLL_EVENT:
|
||||||
msg = parseInjectScrollEvent();
|
msg = parseInjectScrollEvent();
|
||||||
break;
|
break;
|
||||||
@@ -130,6 +134,20 @@ public class ControlMessageReader {
|
|||||||
return ControlMessage.createInjectMouseEvent(action, buttons, position);
|
return ControlMessage.createInjectMouseEvent(action, buttons, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ControlMessage parseInjectTouchEvent() {
|
||||||
|
if (buffer.remaining() < INJECT_TOUCH_EVENT_PAYLOAD_LENGTH) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int action = toUnsigned(buffer.get());
|
||||||
|
long fingerId = buffer.getLong();
|
||||||
|
Position position = readPosition(buffer);
|
||||||
|
// 16 bits fixed-point
|
||||||
|
int pressureInt = toUnsigned(buffer.getShort());
|
||||||
|
// convert it to a float between 0 and 1 (0x1p16f is 2^16 as float)
|
||||||
|
float pressure = pressureInt == 0xffff ? 1f : (pressureInt / 0x1p16f);
|
||||||
|
return ControlMessage.createInjectTouchEvent(action, fingerId, position, pressure);
|
||||||
|
}
|
||||||
|
|
||||||
private ControlMessage parseInjectScrollEvent() {
|
private ControlMessage parseInjectScrollEvent() {
|
||||||
if (buffer.remaining() < INJECT_SCROLL_EVENT_PAYLOAD_LENGTH) {
|
if (buffer.remaining() < INJECT_SCROLL_EVENT_PAYLOAD_LENGTH) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class Controller {
|
public class Controller {
|
||||||
|
|
||||||
|
private static final int MAX_FINGERS = 10;
|
||||||
|
|
||||||
private final Device device;
|
private final Device device;
|
||||||
private final DesktopConnection connection;
|
private final DesktopConnection connection;
|
||||||
private final DeviceMessageSender sender;
|
private final DeviceMessageSender sender;
|
||||||
@@ -20,35 +22,52 @@ public class Controller {
|
|||||||
private final KeyCharacterMap charMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
|
private final KeyCharacterMap charMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
|
||||||
|
|
||||||
private long lastMouseDown;
|
private long lastMouseDown;
|
||||||
private final MotionEvent.PointerProperties[] pointerProperties = {new MotionEvent.PointerProperties()};
|
private final MotionEvent.PointerProperties[] mousePointerProperties = {new MotionEvent.PointerProperties()};
|
||||||
private final MotionEvent.PointerCoords[] pointerCoords = {new MotionEvent.PointerCoords()};
|
private final MotionEvent.PointerCoords[] mousePointerCoords = {new MotionEvent.PointerCoords()};
|
||||||
|
|
||||||
|
private long lastTouchDown;
|
||||||
|
private final FingersState fingersState = new FingersState(MAX_FINGERS);
|
||||||
|
private final MotionEvent.PointerProperties[] touchPointerProperties = new MotionEvent.PointerProperties[MAX_FINGERS];
|
||||||
|
private final MotionEvent.PointerCoords[] touchPointerCoords = new MotionEvent.PointerCoords[MAX_FINGERS];
|
||||||
|
|
||||||
public Controller(Device device, DesktopConnection connection) {
|
public Controller(Device device, DesktopConnection connection) {
|
||||||
this.device = device;
|
this.device = device;
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
initPointer();
|
initMousePointer();
|
||||||
|
initTouchPointers();
|
||||||
sender = new DeviceMessageSender(connection);
|
sender = new DeviceMessageSender(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPointer() {
|
private void initMousePointer() {
|
||||||
MotionEvent.PointerProperties props = pointerProperties[0];
|
MotionEvent.PointerProperties props = mousePointerProperties[0];
|
||||||
props.id = 0;
|
props.id = 0;
|
||||||
props.toolType = MotionEvent.TOOL_TYPE_FINGER;
|
props.toolType = MotionEvent.TOOL_TYPE_FINGER;
|
||||||
|
|
||||||
MotionEvent.PointerCoords coords = pointerCoords[0];
|
MotionEvent.PointerCoords coords = mousePointerCoords[0];
|
||||||
coords.orientation = 0;
|
coords.orientation = 0;
|
||||||
coords.pressure = 1;
|
coords.pressure = 1;
|
||||||
coords.size = 1;
|
coords.size = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPointerCoords(Point point) {
|
private void initTouchPointers() {
|
||||||
MotionEvent.PointerCoords coords = pointerCoords[0];
|
for (int i = 0; i < MAX_FINGERS; ++i) {
|
||||||
|
MotionEvent.PointerProperties props = new MotionEvent.PointerProperties();
|
||||||
|
props.toolType = MotionEvent.TOOL_TYPE_FINGER;
|
||||||
|
|
||||||
|
MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords();
|
||||||
|
coords.orientation = 0;
|
||||||
|
coords.size = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMousePointerCoords(Point point) {
|
||||||
|
MotionEvent.PointerCoords coords = mousePointerCoords[0];
|
||||||
coords.x = point.getX();
|
coords.x = point.getX();
|
||||||
coords.y = point.getY();
|
coords.y = point.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setScroll(int hScroll, int vScroll) {
|
private void setScroll(int hScroll, int vScroll) {
|
||||||
MotionEvent.PointerCoords coords = pointerCoords[0];
|
MotionEvent.PointerCoords coords = mousePointerCoords[0];
|
||||||
coords.setAxisValue(MotionEvent.AXIS_HSCROLL, hScroll);
|
coords.setAxisValue(MotionEvent.AXIS_HSCROLL, hScroll);
|
||||||
coords.setAxisValue(MotionEvent.AXIS_VSCROLL, vScroll);
|
coords.setAxisValue(MotionEvent.AXIS_VSCROLL, vScroll);
|
||||||
}
|
}
|
||||||
@@ -158,8 +177,36 @@ public class Controller {
|
|||||||
// ignore event
|
// ignore event
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
setPointerCoords(point);
|
setMousePointerCoords(point);
|
||||||
MotionEvent event = MotionEvent.obtain(lastMouseDown, now, action, 1, pointerProperties, pointerCoords, 0, buttons, 1f, 1f, 0, 0,
|
MotionEvent event = MotionEvent.obtain(lastMouseDown, now, action, 1, mousePointerProperties, mousePointerCoords, 0, buttons, 1f, 1f, 0, 0,
|
||||||
|
InputDevice.SOURCE_TOUCHSCREEN, 0);
|
||||||
|
return injectEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean injectTouch(int action, int fingerId, Position position, float pressure) {
|
||||||
|
long now = SystemClock.uptimeMillis();
|
||||||
|
if (action == MotionEvent.ACTION_DOWN) {
|
||||||
|
lastTouchDown = now;
|
||||||
|
}
|
||||||
|
Point point = device.getPhysicalPoint(position);
|
||||||
|
if (point == null) {
|
||||||
|
// ignore event
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (action == MotionEvent.ACTION_UP) {
|
||||||
|
if (!fingersState.unset(fingerId)) {
|
||||||
|
Ln.w("Unexpected ACTION_UP on unknown finger");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// ACTION_DOWN or ACTION_MOVE
|
||||||
|
if (!fingersState.set(fingerId, point, pressure)) {
|
||||||
|
Ln.w("Too many fingers for touch event");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int pointerCount = fingersState.update(touchPointerProperties, touchPointerCoords);
|
||||||
|
MotionEvent event = MotionEvent.obtain(lastTouchDown, now, action, pointerCount, touchPointerProperties, touchPointerCoords, 0, 0, 1f, 1f, 0, 0,
|
||||||
InputDevice.SOURCE_TOUCHSCREEN, 0);
|
InputDevice.SOURCE_TOUCHSCREEN, 0);
|
||||||
return injectEvent(event);
|
return injectEvent(event);
|
||||||
}
|
}
|
||||||
@@ -171,9 +218,9 @@ public class Controller {
|
|||||||
// ignore event
|
// ignore event
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
setPointerCoords(point);
|
setMousePointerCoords(point);
|
||||||
setScroll(hScroll, vScroll);
|
setScroll(hScroll, vScroll);
|
||||||
MotionEvent event = MotionEvent.obtain(lastMouseDown, now, MotionEvent.ACTION_SCROLL, 1, pointerProperties, pointerCoords, 0, 0, 1f, 1f, 0,
|
MotionEvent event = MotionEvent.obtain(lastMouseDown, now, MotionEvent.ACTION_SCROLL, 1, mousePointerProperties, mousePointerCoords, 0, 0, 1f, 1f, 0,
|
||||||
0, InputDevice.SOURCE_MOUSE, 0);
|
0, InputDevice.SOURCE_MOUSE, 0);
|
||||||
return injectEvent(event);
|
return injectEvent(event);
|
||||||
}
|
}
|
||||||
|
|||||||
32
server/src/main/java/com/genymobile/scrcpy/Finger.java
Normal file
32
server/src/main/java/com/genymobile/scrcpy/Finger.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
|
public class Finger {
|
||||||
|
|
||||||
|
private final long id;
|
||||||
|
private Point point;
|
||||||
|
private float pressure;
|
||||||
|
|
||||||
|
public Finger(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point getPoint() {
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPoint(Point point) {
|
||||||
|
this.point = point;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPressure() {
|
||||||
|
return pressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPressure(float pressure) {
|
||||||
|
this.pressure = pressure;
|
||||||
|
}
|
||||||
|
}
|
||||||
99
server/src/main/java/com/genymobile/scrcpy/FingersState.java
Normal file
99
server/src/main/java/com/genymobile/scrcpy/FingersState.java
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
public class FingersState {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of enabled fingers (can contain "null" holes).
|
||||||
|
* <p>
|
||||||
|
* Once a Finger (identified by its id received from the client) is enabled, it is never moved.
|
||||||
|
* <p>
|
||||||
|
* Its index is its local identifier injected into MotionEvents.
|
||||||
|
*/
|
||||||
|
private final Finger[] fingers;
|
||||||
|
|
||||||
|
public FingersState(int maxFingers) {
|
||||||
|
fingers = new Finger[maxFingers];
|
||||||
|
}
|
||||||
|
|
||||||
|
private int indexOf(long id) {
|
||||||
|
for (int i = 0; i < fingers.length; ++i) {
|
||||||
|
Finger finger = fingers[i];
|
||||||
|
if (finger != null && finger.getId() == id) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int indexOfFirstEmpty() {
|
||||||
|
for (int i = 0; i < fingers.length; ++i) {
|
||||||
|
if (fingers[i] == null) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Finger create(long id) {
|
||||||
|
int index = indexOf(id);
|
||||||
|
if (index != -1) {
|
||||||
|
// already exists, return it
|
||||||
|
return fingers[index];
|
||||||
|
}
|
||||||
|
int firstEmpty = indexOfFirstEmpty();
|
||||||
|
if (firstEmpty == -1) {
|
||||||
|
// it's full
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Finger finger = new Finger(id);
|
||||||
|
fingers[firstEmpty] = finger;
|
||||||
|
return finger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean unset(int id) {
|
||||||
|
int index = indexOf(id);
|
||||||
|
if (index == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fingers[index] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean set(int id, Point point, float pressure) {
|
||||||
|
Finger finger = create(id);
|
||||||
|
if (finger == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finger.setPoint(point);
|
||||||
|
finger.setPressure(pressure);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the motion event parameters.
|
||||||
|
*
|
||||||
|
* @param props the pointer properties
|
||||||
|
* @param coords the pointer coordinates
|
||||||
|
* @return The number of items initialized (the number of fingers).
|
||||||
|
*/
|
||||||
|
public int update(MotionEvent.PointerProperties[] props, MotionEvent.PointerCoords[] coords) {
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < fingers.length; ++i) {
|
||||||
|
Finger finger = fingers[i];
|
||||||
|
if (finger != null) {
|
||||||
|
// id 0 is reserved for mouse events
|
||||||
|
props[count].id = i + 1;
|
||||||
|
|
||||||
|
Point point = finger.getPoint();
|
||||||
|
coords[i].x = point.getX();
|
||||||
|
coords[i].y = point.getY();
|
||||||
|
coords[i].pressure = finger.getPressure();
|
||||||
|
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ public final class WindowManager {
|
|||||||
try {
|
try {
|
||||||
Class<?> cls = manager.getClass();
|
Class<?> cls = manager.getClass();
|
||||||
try {
|
try {
|
||||||
return (Integer) manager.getClass().getMethod("getRotation").invoke(manager);
|
return (Integer) cls.getMethod("getRotation").invoke(manager);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
// method changed since this commit:
|
// method changed since this commit:
|
||||||
// https://android.googlesource.com/platform/frameworks/base/+/8ee7285128c3843401d4c4d0412cd66e86ba49e3%5E%21/#F2
|
// https://android.googlesource.com/platform/frameworks/base/+/8ee7285128c3843401d4c4d0412cd66e86ba49e3%5E%21/#F2
|
||||||
|
|||||||
@@ -82,19 +82,56 @@ public class ControlMessageReaderTest {
|
|||||||
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
DataOutputStream dos = new DataOutputStream(bos);
|
DataOutputStream dos = new DataOutputStream(bos);
|
||||||
dos.writeByte(ControlMessage.TYPE_INJECT_KEYCODE);
|
dos.writeByte(ControlMessage.TYPE_INJECT_MOUSE_EVENT);
|
||||||
dos.writeByte(MotionEvent.ACTION_DOWN);
|
dos.writeByte(MotionEvent.ACTION_DOWN);
|
||||||
dos.writeInt(MotionEvent.BUTTON_PRIMARY);
|
dos.writeInt(MotionEvent.BUTTON_PRIMARY);
|
||||||
dos.writeInt(KeyEvent.META_CTRL_ON);
|
dos.writeInt(100);
|
||||||
|
dos.writeInt(200);
|
||||||
|
dos.writeShort(1080);
|
||||||
|
dos.writeShort(1920);
|
||||||
|
|
||||||
byte[] packet = bos.toByteArray();
|
byte[] packet = bos.toByteArray();
|
||||||
|
|
||||||
reader.readFrom(new ByteArrayInputStream(packet));
|
reader.readFrom(new ByteArrayInputStream(packet));
|
||||||
ControlMessage event = reader.next();
|
ControlMessage event = reader.next();
|
||||||
|
|
||||||
Assert.assertEquals(ControlMessage.TYPE_INJECT_KEYCODE, event.getType());
|
Assert.assertEquals(ControlMessage.TYPE_INJECT_MOUSE_EVENT, event.getType());
|
||||||
Assert.assertEquals(MotionEvent.ACTION_DOWN, event.getAction());
|
Assert.assertEquals(MotionEvent.ACTION_DOWN, event.getAction());
|
||||||
Assert.assertEquals(MotionEvent.BUTTON_PRIMARY, event.getKeycode());
|
Assert.assertEquals(MotionEvent.BUTTON_PRIMARY, event.getButtons());
|
||||||
Assert.assertEquals(KeyEvent.META_CTRL_ON, event.getMetaState());
|
Assert.assertEquals(100, event.getPosition().getPoint().getX());
|
||||||
|
Assert.assertEquals(200, event.getPosition().getPoint().getY());
|
||||||
|
Assert.assertEquals(1080, event.getPosition().getScreenSize().getWidth());
|
||||||
|
Assert.assertEquals(1920, event.getPosition().getScreenSize().getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseTouchEvent() throws IOException {
|
||||||
|
ControlMessageReader reader = new ControlMessageReader();
|
||||||
|
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream dos = new DataOutputStream(bos);
|
||||||
|
dos.writeByte(ControlMessage.TYPE_INJECT_TOUCH_EVENT);
|
||||||
|
dos.writeByte(MotionEvent.ACTION_DOWN);
|
||||||
|
dos.writeLong(-42); // fingerId
|
||||||
|
dos.writeInt(100);
|
||||||
|
dos.writeInt(200);
|
||||||
|
dos.writeShort(1080);
|
||||||
|
dos.writeShort(1920);
|
||||||
|
dos.writeShort(0xffff); // pressure
|
||||||
|
|
||||||
|
byte[] packet = bos.toByteArray();
|
||||||
|
|
||||||
|
reader.readFrom(new ByteArrayInputStream(packet));
|
||||||
|
ControlMessage event = reader.next();
|
||||||
|
|
||||||
|
Assert.assertEquals(ControlMessage.TYPE_INJECT_TOUCH_EVENT, event.getType());
|
||||||
|
Assert.assertEquals(MotionEvent.ACTION_DOWN, event.getAction());
|
||||||
|
Assert.assertEquals(-42, event.getFingerId());
|
||||||
|
Assert.assertEquals(100, event.getPosition().getPoint().getX());
|
||||||
|
Assert.assertEquals(200, event.getPosition().getPoint().getY());
|
||||||
|
Assert.assertEquals(1080, event.getPosition().getScreenSize().getWidth());
|
||||||
|
Assert.assertEquals(1920, event.getPosition().getScreenSize().getHeight());
|
||||||
|
Assert.assertEquals(1f, event.getPressure(), 0f); // must be exact
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user