Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
783eb95795 | ||
|
|
7e21f28f2c | ||
|
|
ccfd4db370 | ||
|
|
6d26ed888e | ||
|
|
73afdaf251 | ||
|
|
bb1bf99c6e | ||
|
|
7aeec1c331 | ||
|
|
3bb2222a34 | ||
|
|
bdf2644664 | ||
|
|
1f8ba1ca79 | ||
|
|
129dabcfa4 | ||
|
|
f510f1de1c | ||
|
|
7d1932b907 | ||
|
|
795d103032 | ||
|
|
513d1ac96d |
2
BUILD.md
2
BUILD.md
@@ -43,7 +43,7 @@ Install the required packages from your package manager.
|
|||||||
sudo apt install ffmpeg libsdl2-2.0-0
|
sudo apt install ffmpeg libsdl2-2.0-0
|
||||||
|
|
||||||
# client build dependencies
|
# client build dependencies
|
||||||
sudo apt install make gcc git pkg-config meson ninja-build \
|
sudo apt install gcc git pkg-config meson ninja-build \
|
||||||
libavcodec-dev libavformat-dev libavutil-dev \
|
libavcodec-dev libavformat-dev libavutil-dev \
|
||||||
libsdl2-dev
|
libsdl2-dev
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
buffer_write16be(uint8_t *buf, uint16_t value) {
|
buffer_write16be(uint8_t *buf, uint16_t value) {
|
||||||
buf[0] = value >> 8;
|
buf[0] = value >> 8;
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
// To define a circular buffer type of 20 ints:
|
// To define a circular buffer type of 20 ints:
|
||||||
// struct cbuf_int CBUF(int, 20);
|
// struct cbuf_int CBUF(int, 20);
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "str_util.h"
|
#include "str_util.h"
|
||||||
|
|||||||
@@ -33,6 +33,8 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
# define NO_EXIT_CODE -1
|
# define NO_EXIT_CODE -1
|
||||||
|
|
||||||
enum process_result {
|
enum process_result {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
|
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
|
||||||
#define MIN(X,Y) (X) < (Y) ? (X) : (Y)
|
#define MIN(X,Y) (X) < (Y) ? (X) : (Y)
|
||||||
#define MAX(X,Y) (X) > (Y) ? (X) : (Y)
|
#define MAX(X,Y) (X) > (Y) ? (X) : (Y)
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#include "control_msg.h"
|
#include "control_msg.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <SDL_assert.h>
|
#include <SDL2/SDL_assert.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "buffer_util.h"
|
#include "buffer_util.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "str_util.h"
|
#include "str_util.h"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "android/input.h"
|
#include "android/input.h"
|
||||||
#include "android/keycodes.h"
|
#include "android/keycodes.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <SDL2/SDL_mutex.h>
|
#include <SDL2/SDL_mutex.h>
|
||||||
#include <SDL2/SDL_thread.h>
|
#include <SDL2/SDL_thread.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "cbuf.h"
|
#include "cbuf.h"
|
||||||
#include "control_msg.h"
|
#include "control_msg.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
#include <SDL2/SDL_thread.h>
|
#include <SDL2/SDL_thread.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "compat.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "compat.h"
|
||||||
#include "buffer_util.h"
|
#include "buffer_util.h"
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
#include "lock_util.h"
|
#include "lock_util.h"
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
struct video_buffer;
|
struct video_buffer;
|
||||||
|
|
||||||
struct decoder {
|
struct decoder {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <SDL2/SDL_assert.h>
|
#include <SDL2/SDL_assert.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "buffer_util.h"
|
#include "buffer_util.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#define DEVICE_MSG_TEXT_MAX_LENGTH 4093
|
#define DEVICE_MSG_TEXT_MAX_LENGTH 4093
|
||||||
#define DEVICE_MSG_SERIALIZED_MAX_SIZE (3 + DEVICE_MSG_TEXT_MAX_LENGTH)
|
#define DEVICE_MSG_SERIALIZED_MAX_SIZE (3 + DEVICE_MSG_TEXT_MAX_LENGTH)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "event_converter.h"
|
#include "event_converter.h"
|
||||||
|
|
||||||
|
#include "config.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
|
||||||
|
|
||||||
@@ -228,7 +230,7 @@ convert_touch(const SDL_TouchFingerEvent *from, struct size screen_size,
|
|||||||
to->inject_touch_event.position.screen_size = screen_size;
|
to->inject_touch_event.position.screen_size = screen_size;
|
||||||
// SDL touch event coordinates are normalized in the range [0; 1]
|
// 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.x = from->x * screen_size.width;
|
||||||
to->inject_touch_event.position.point.y = from->x * screen_size.height;
|
to->inject_touch_event.position.point.y = from->y * screen_size.height;
|
||||||
to->inject_touch_event.pressure = from->pressure;
|
to->inject_touch_event.pressure = from->pressure;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <SDL2/SDL_events.h>
|
#include <SDL2/SDL_events.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "control_msg.h"
|
#include "control_msg.h"
|
||||||
|
|
||||||
struct complete_mouse_motion_event {
|
struct complete_mouse_motion_event {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <SDL2/SDL_mutex.h>
|
#include <SDL2/SDL_mutex.h>
|
||||||
#include <SDL2/SDL_thread.h>
|
#include <SDL2/SDL_thread.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "cbuf.h"
|
#include "cbuf.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <SDL2/SDL_assert.h>
|
#include <SDL2/SDL_assert.h>
|
||||||
#include <SDL2/SDL_timer.h>
|
#include <SDL2/SDL_timer.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "lock_util.h"
|
#include "lock_util.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include <SDL2/SDL_mutex.h>
|
#include <SDL2/SDL_mutex.h>
|
||||||
#include <SDL2/SDL_thread.h>
|
#include <SDL2/SDL_thread.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
struct fps_counter {
|
struct fps_counter {
|
||||||
SDL_Thread *thread;
|
SDL_Thread *thread;
|
||||||
SDL_mutex *mutex;
|
SDL_mutex *mutex;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "input_manager.h"
|
#include "input_manager.h"
|
||||||
|
|
||||||
#include <SDL2/SDL_assert.h>
|
#include <SDL2/SDL_assert.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "event_converter.h"
|
#include "event_converter.h"
|
||||||
#include "lock_util.h"
|
#include "lock_util.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
@@ -102,7 +104,7 @@ press_back_or_turn_screen_on(struct controller *controller) {
|
|||||||
msg.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON;
|
msg.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON;
|
||||||
|
|
||||||
if (!controller_push_msg(controller, &msg)) {
|
if (!controller_push_msg(controller, &msg)) {
|
||||||
LOGW("Could not request 'turn screen on'");
|
LOGW("Could not request 'press back or turn screen on'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "fps_counter.h"
|
#include "fps_counter.h"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <SDL2/SDL_mutex.h>
|
#include <SDL2/SDL_mutex.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
#define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem
|
#define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
#include "compat.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "compat.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "recorder.h"
|
#include "recorder.h"
|
||||||
|
|
||||||
@@ -328,7 +328,7 @@ parse_args(struct args *args, int argc, char *argv[]) {
|
|||||||
{"push-target", required_argument, NULL,
|
{"push-target", required_argument, NULL,
|
||||||
OPT_PUSH_TARGET},
|
OPT_PUSH_TARGET},
|
||||||
{"record", required_argument, NULL, 'r'},
|
{"record", required_argument, NULL, 'r'},
|
||||||
{"record-format", required_argument, NULL, 'f'},
|
{"record-format", required_argument, NULL, 'F'},
|
||||||
{"render-expired-frames", no_argument, NULL,
|
{"render-expired-frames", no_argument, NULL,
|
||||||
OPT_RENDER_EXPIRED_FRAMES},
|
OPT_RENDER_EXPIRED_FRAMES},
|
||||||
{"serial", required_argument, NULL, 's'},
|
{"serial", required_argument, NULL, 's'},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
typedef int socket_t;
|
typedef int socket_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
bool
|
bool
|
||||||
net_init(void);
|
net_init(void);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <SDL2/SDL_assert.h>
|
#include <SDL2/SDL_assert.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
// To define a queue type of "struct foo":
|
// To define a queue type of "struct foo":
|
||||||
// struct queue_foo QUEUE(struct foo);
|
// struct queue_foo QUEUE(struct foo);
|
||||||
#define QUEUE(TYPE) { \
|
#define QUEUE(TYPE) { \
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <SDL2/SDL_mutex.h>
|
#include <SDL2/SDL_mutex.h>
|
||||||
#include <SDL2/SDL_thread.h>
|
#include <SDL2/SDL_thread.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
// receive events from the device
|
// receive events from the device
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
#include <libavutil/time.h>
|
#include <libavutil/time.h>
|
||||||
#include <SDL2/SDL_assert.h>
|
#include <SDL2/SDL_assert.h>
|
||||||
|
|
||||||
#include "compat.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "compat.h"
|
||||||
#include "lock_util.h"
|
#include "lock_util.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <SDL2/SDL_mutex.h>
|
#include <SDL2/SDL_mutex.h>
|
||||||
#include <SDL2/SDL_thread.h>
|
#include <SDL2/SDL_thread.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <recorder.h>
|
#include <recorder.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
struct scrcpy_options {
|
struct scrcpy_options {
|
||||||
const char *serial;
|
const char *serial;
|
||||||
const char *crop;
|
const char *crop;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "icon.xpm"
|
#include "icon.xpm"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
struct video_buffer;
|
struct video_buffer;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL_stdinc.h>
|
#include <SDL2/SDL_stdinc.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
xstrncpy(char *dest, const char *src, size_t n) {
|
xstrncpy(char *dest, const char *src, size_t n) {
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
// like strncpy, except:
|
// like strncpy, except:
|
||||||
// - it copies at most n-1 chars
|
// - it copies at most n-1 chars
|
||||||
// - the dest string is nul-terminated
|
// - the dest string is nul-terminated
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
#include <SDL2/SDL_thread.h>
|
#include <SDL2/SDL_thread.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "compat.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "compat.h"
|
||||||
#include "buffer_util.h"
|
#include "buffer_util.h"
|
||||||
#include "decoder.h"
|
#include "decoder.h"
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <SDL2/SDL_atomic.h>
|
#include <SDL2/SDL_atomic.h>
|
||||||
#include <SDL2/SDL_thread.h>
|
#include <SDL2/SDL_thread.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
struct video_buffer;
|
struct video_buffer;
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
bool
|
bool
|
||||||
net_init(void) {
|
net_init(void) {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
struct index {
|
struct index {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
SDL_Surface *
|
SDL_Surface *
|
||||||
read_xpm(char *xpm[]);
|
read_xpm(char *xpm[]);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <SDL2/SDL_mutex.h>
|
#include <SDL2/SDL_mutex.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "fps_counter.h"
|
#include "fps_counter.h"
|
||||||
|
|
||||||
// forward declarations
|
// forward declarations
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ public class Controller {
|
|||||||
MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords();
|
MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords();
|
||||||
coords.orientation = 0;
|
coords.orientation = 0;
|
||||||
coords.size = 1;
|
coords.size = 1;
|
||||||
|
|
||||||
|
touchPointerProperties[i] = props;
|
||||||
|
touchPointerCoords[i] = coords;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,6 +112,9 @@ public class Controller {
|
|||||||
case ControlMessage.TYPE_INJECT_MOUSE_EVENT:
|
case ControlMessage.TYPE_INJECT_MOUSE_EVENT:
|
||||||
injectMouse(msg.getAction(), msg.getButtons(), msg.getPosition());
|
injectMouse(msg.getAction(), msg.getButtons(), msg.getPosition());
|
||||||
break;
|
break;
|
||||||
|
case ControlMessage.TYPE_INJECT_TOUCH_EVENT:
|
||||||
|
injectTouch(msg.getAction(), msg.getFingerId(), msg.getPosition(), msg.getPressure());
|
||||||
|
break;
|
||||||
case ControlMessage.TYPE_INJECT_SCROLL_EVENT:
|
case ControlMessage.TYPE_INJECT_SCROLL_EVENT:
|
||||||
injectScroll(msg.getPosition(), msg.getHScroll(), msg.getVScroll());
|
injectScroll(msg.getPosition(), msg.getHScroll(), msg.getVScroll());
|
||||||
break;
|
break;
|
||||||
@@ -183,29 +189,45 @@ public class Controller {
|
|||||||
return injectEvent(event);
|
return injectEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean injectTouch(int action, int fingerId, Position position, float pressure) {
|
private boolean injectTouch(int action, long fingerId, Position position, float pressure) {
|
||||||
long now = SystemClock.uptimeMillis();
|
long now = SystemClock.uptimeMillis();
|
||||||
if (action == MotionEvent.ACTION_DOWN) {
|
|
||||||
lastTouchDown = now;
|
|
||||||
}
|
|
||||||
Point point = device.getPhysicalPoint(position);
|
Point point = device.getPhysicalPoint(position);
|
||||||
if (point == null) {
|
if (point == null) {
|
||||||
// ignore event
|
// ignore event
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (action == MotionEvent.ACTION_UP) {
|
|
||||||
if (!fingersState.unset(fingerId)) {
|
int fingerIndex = fingersState.getFingerIndex(fingerId);
|
||||||
Ln.w("Unexpected ACTION_UP on unknown finger");
|
if (fingerIndex == -1) {
|
||||||
return false;
|
Ln.w("Too many fingers for touch event");
|
||||||
}
|
return false;
|
||||||
} else {
|
|
||||||
// ACTION_DOWN or ACTION_MOVE
|
|
||||||
if (!fingersState.set(fingerId, point, pressure)) {
|
|
||||||
Ln.w("Too many fingers for touch event");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Finger finger = fingersState.get(fingerIndex);
|
||||||
|
finger.setPoint(point);
|
||||||
|
finger.setPressure(pressure);
|
||||||
|
finger.setUp(action == MotionEvent.ACTION_UP);
|
||||||
|
|
||||||
|
// FAIL: action_up will always remove the finger, and the event will not be written!
|
||||||
int pointerCount = fingersState.update(touchPointerProperties, touchPointerCoords);
|
int pointerCount = fingersState.update(touchPointerProperties, touchPointerCoords);
|
||||||
|
fingersState.cleanUp();
|
||||||
|
|
||||||
|
Ln.d("pointerCount = " + pointerCount);
|
||||||
|
for (int i = 0; i < pointerCount; ++i) {
|
||||||
|
Ln.d("props = " + touchPointerProperties[i].id);
|
||||||
|
Ln.d("coords = " + touchPointerCoords[i].x + "," + touchPointerCoords[i].y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pointerCount > 1) {
|
||||||
|
if (action == MotionEvent.ACTION_UP) {
|
||||||
|
action = MotionEvent.ACTION_POINTER_UP | (fingerIndex << MotionEvent.ACTION_POINTER_INDEX_SHIFT);
|
||||||
|
} else if (action == MotionEvent.ACTION_DOWN) {
|
||||||
|
action = MotionEvent.ACTION_POINTER_DOWN | (fingerIndex << MotionEvent.ACTION_POINTER_INDEX_SHIFT);
|
||||||
|
}
|
||||||
|
} else if (action == MotionEvent.ACTION_DOWN) {
|
||||||
|
lastTouchDown = now;
|
||||||
|
}
|
||||||
|
|
||||||
MotionEvent event = MotionEvent.obtain(lastTouchDown, now, action, pointerCount, touchPointerProperties, touchPointerCoords, 0, 0, 1f, 1f, 0, 0,
|
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);
|
||||||
|
|||||||
@@ -3,17 +3,24 @@ package com.genymobile.scrcpy;
|
|||||||
public class Finger {
|
public class Finger {
|
||||||
|
|
||||||
private final long id;
|
private final long id;
|
||||||
|
private final int localId;
|
||||||
private Point point;
|
private Point point;
|
||||||
private float pressure;
|
private float pressure;
|
||||||
|
private boolean up;
|
||||||
|
|
||||||
public Finger(long id) {
|
public Finger(long id, int localId) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.localId = localId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getLocalId() {
|
||||||
|
return localId;
|
||||||
|
}
|
||||||
|
|
||||||
public Point getPoint() {
|
public Point getPoint() {
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
@@ -29,4 +36,12 @@ public class Finger {
|
|||||||
public void setPressure(float pressure) {
|
public void setPressure(float pressure) {
|
||||||
this.pressure = pressure;
|
this.pressure = pressure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isUp() {
|
||||||
|
return up;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUp(boolean up) {
|
||||||
|
this.up = up;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,73 +2,70 @@ package com.genymobile.scrcpy;
|
|||||||
|
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class FingersState {
|
public class FingersState {
|
||||||
|
|
||||||
/**
|
private final List<Finger> fingers = new ArrayList<>();
|
||||||
* Array of enabled fingers (can contain "null" holes).
|
private int maxFingers;
|
||||||
* <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) {
|
public FingersState(int maxFingers) {
|
||||||
fingers = new Finger[maxFingers];
|
this.maxFingers = maxFingers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int indexOf(long id) {
|
private int indexOf(long id) {
|
||||||
for (int i = 0; i < fingers.length; ++i) {
|
for (int i = 0; i < fingers.size(); ++i) {
|
||||||
Finger finger = fingers[i];
|
Finger finger = fingers.get(i);
|
||||||
if (finger != null && finger.getId() == id) {
|
if (finger.getId() == id) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int indexOfFirstEmpty() {
|
private boolean isLocalIdAvailable(int localId) {
|
||||||
for (int i = 0; i < fingers.length; ++i) {
|
for (int i = 0; i < fingers.size(); ++i) {
|
||||||
if (fingers[i] == null) {
|
Finger finger = fingers.get(i);
|
||||||
return i;
|
if (finger.getLocalId() == localId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int nextUnusedLocalId() {
|
||||||
|
for (int localId = 0; localId < maxFingers; ++localId) {
|
||||||
|
if (isLocalIdAvailable(localId)) {
|
||||||
|
return localId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Finger create(long id) {
|
public Finger get(int index) {
|
||||||
|
return fingers.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFingerIndex(long id) {
|
||||||
int index = indexOf(id);
|
int index = indexOf(id);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
// already exists, return it
|
// already exists, return it
|
||||||
return fingers[index];
|
return index;
|
||||||
}
|
}
|
||||||
int firstEmpty = indexOfFirstEmpty();
|
if (fingers.size() >= maxFingers) {
|
||||||
if (firstEmpty == -1) {
|
|
||||||
// it's full
|
// it's full
|
||||||
return null;
|
return -1;
|
||||||
}
|
}
|
||||||
Finger finger = new Finger(id);
|
// id 0 is reserved for mouse events
|
||||||
fingers[firstEmpty] = finger;
|
int localId = nextUnusedLocalId();
|
||||||
return finger;
|
if (localId == -1) {
|
||||||
}
|
throw new AssertionError("fingers.size() < maxFingers implies that a local id is available");
|
||||||
|
|
||||||
public boolean unset(int id) {
|
|
||||||
int index = indexOf(id);
|
|
||||||
if (index == -1) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
fingers[index] = null;
|
Finger finger = new Finger(id, localId);
|
||||||
return true;
|
fingers.add(finger);
|
||||||
}
|
// return the index of the finger
|
||||||
|
return fingers.size() - 1;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,21 +76,26 @@ public class FingersState {
|
|||||||
* @return The number of items initialized (the number of fingers).
|
* @return The number of items initialized (the number of fingers).
|
||||||
*/
|
*/
|
||||||
public int update(MotionEvent.PointerProperties[] props, MotionEvent.PointerCoords[] coords) {
|
public int update(MotionEvent.PointerProperties[] props, MotionEvent.PointerCoords[] coords) {
|
||||||
int count = 0;
|
for (int i = 0; i < fingers.size(); ++i) {
|
||||||
for (int i = 0; i < fingers.length; ++i) {
|
Finger finger = fingers.get(i);
|
||||||
Finger finger = fingers[i];
|
|
||||||
if (finger != null) {
|
|
||||||
// id 0 is reserved for mouse events
|
|
||||||
props[count].id = i + 1;
|
|
||||||
|
|
||||||
Point point = finger.getPoint();
|
// id 0 is reserved for mouse events
|
||||||
coords[i].x = point.getX();
|
props[i].id = finger.getLocalId();
|
||||||
coords[i].y = point.getY();
|
|
||||||
coords[i].pressure = finger.getPressure();
|
|
||||||
|
|
||||||
++count;
|
Point point = finger.getPoint();
|
||||||
|
coords[i].x = point.getX();
|
||||||
|
coords[i].y = point.getY();
|
||||||
|
coords[i].pressure = finger.getPressure();
|
||||||
|
}
|
||||||
|
return fingers.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cleanUp() {
|
||||||
|
for (int i = fingers.size() - 1; i >= 0; --i) {
|
||||||
|
Finger finger = fingers.get(i);
|
||||||
|
if (finger.isUp()) {
|
||||||
|
fingers.remove(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ public class ControlMessageReaderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@SuppressWarnings("checkstyle:MagicNumber")
|
||||||
public void testParseMouseEvent() throws IOException {
|
public void testParseMouseEvent() throws IOException {
|
||||||
ControlMessageReader reader = new ControlMessageReader();
|
ControlMessageReader reader = new ControlMessageReader();
|
||||||
|
|
||||||
@@ -105,6 +106,7 @@ public class ControlMessageReaderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@SuppressWarnings("checkstyle:MagicNumber")
|
||||||
public void testParseTouchEvent() throws IOException {
|
public void testParseTouchEvent() throws IOException {
|
||||||
ControlMessageReader reader = new ControlMessageReader();
|
ControlMessageReader reader = new ControlMessageReader();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user