Add an option to enable "show touches"
Add -t/--show-touches option to show physical touches while scrcpy is running. See <https://github.com/Genymobile/scrcpy/issues/96>.
This commit is contained in:
parent
b13d25b9f4
commit
66ec252893
6 changed files with 48 additions and 11 deletions
|
@ -247,6 +247,12 @@ If several devices are listed in `adb devices`, you must specify the _serial_:
|
|||
scrcpy -s 0123456789abcdef
|
||||
```
|
||||
|
||||
To show physical touches while scrcpy is running:
|
||||
|
||||
```bash
|
||||
scrcpy -t
|
||||
```
|
||||
|
||||
To run without installing:
|
||||
|
||||
```bash
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
|
||||
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
static const char *adb_command;
|
||||
|
||||
static inline const char *get_adb_command() {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
|
||||
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
|
||||
#define MIN(X,Y) (X) < (Y) ? (X) : (Y)
|
||||
#define MAX(X,Y) (X) > (Y) ? (X) : (Y)
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ struct args {
|
|||
const char *serial;
|
||||
SDL_bool help;
|
||||
SDL_bool version;
|
||||
SDL_bool show_touches;
|
||||
Uint16 port;
|
||||
Uint16 max_size;
|
||||
Uint32 bit_rate;
|
||||
|
@ -45,6 +46,10 @@ static void usage(const char *arg0) {
|
|||
" The device serial number. Mandatory only if several devices\n"
|
||||
" are connected to adb.\n"
|
||||
"\n"
|
||||
" -t, --show-touches\n"
|
||||
" Enable \"show touches\" on start, disable on quit.\n"
|
||||
" It only shows physical touches (not clicks from scrcpy).\n"
|
||||
"\n"
|
||||
" -v, --version\n"
|
||||
" Print the version of scrcpy.\n"
|
||||
"\n"
|
||||
|
@ -183,16 +188,17 @@ static SDL_bool parse_port(char *optarg, Uint16 *port) {
|
|||
|
||||
static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
|
||||
static const struct option long_options[] = {
|
||||
{"bit-rate", required_argument, NULL, 'b'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"max-size", required_argument, NULL, 'm'},
|
||||
{"port", required_argument, NULL, 'p'},
|
||||
{"serial", required_argument, NULL, 's'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{NULL, 0, NULL, 0 },
|
||||
{"bit-rate", required_argument, NULL, 'b'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"max-size", required_argument, NULL, 'm'},
|
||||
{"port", required_argument, NULL, 'p'},
|
||||
{"serial", required_argument, NULL, 's'},
|
||||
{"show-touches", no_argument, NULL, 't'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{NULL, 0, NULL, 0 },
|
||||
};
|
||||
int c;
|
||||
while ((c = getopt_long(argc, argv, "b:hm:p:s:v", long_options, NULL)) != -1) {
|
||||
while ((c = getopt_long(argc, argv, "b:hm:p:s:tv", long_options, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'b':
|
||||
if (!parse_bit_rate(optarg, &args->bit_rate)) {
|
||||
|
@ -215,6 +221,9 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
|
|||
case 's':
|
||||
args->serial = optarg;
|
||||
break;
|
||||
case 't':
|
||||
args->show_touches = SDL_TRUE;
|
||||
break;
|
||||
case 'v':
|
||||
args->version = SDL_TRUE;
|
||||
break;
|
||||
|
@ -243,6 +252,7 @@ int main(int argc, char *argv[]) {
|
|||
.serial = NULL,
|
||||
.help = SDL_FALSE,
|
||||
.version = SDL_FALSE,
|
||||
.show_touches = SDL_FALSE,
|
||||
.port = DEFAULT_LOCAL_PORT,
|
||||
.max_size = DEFAULT_MAX_SIZE,
|
||||
.bit_rate = DEFAULT_BIT_RATE,
|
||||
|
@ -276,6 +286,7 @@ int main(int argc, char *argv[]) {
|
|||
.port = args.port,
|
||||
.max_size = args.max_size,
|
||||
.bit_rate = args.bit_rate,
|
||||
.show_touches = args.show_touches,
|
||||
};
|
||||
int res = scrcpy(&options) ? 0 : 1;
|
||||
|
||||
|
|
|
@ -106,6 +106,15 @@ static void event_loop(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static SDL_bool set_show_touches_enabled(const char *serial, SDL_bool enabled) {
|
||||
const char *value = enabled ? "1" : "0";
|
||||
const char *const adb_cmd[] = {
|
||||
"shell", "settings", "put", "system", "show_touches", value
|
||||
};
|
||||
process_t proc = adb_execute(serial, adb_cmd, ARRAY_LEN(adb_cmd));
|
||||
return process_check_success(proc, "show_touches");
|
||||
}
|
||||
|
||||
SDL_bool scrcpy(const struct scrcpy_options *options) {
|
||||
if (!server_start(&server, options->serial, options->port,
|
||||
options->max_size, options->bit_rate)) {
|
||||
|
@ -173,9 +182,19 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
|
|||
goto finally_stop_and_join_controller;
|
||||
}
|
||||
|
||||
event_loop();
|
||||
if (options->show_touches) {
|
||||
LOGI("Enable show_touches");
|
||||
set_show_touches_enabled(options->serial, SDL_TRUE);
|
||||
}
|
||||
|
||||
event_loop();
|
||||
LOGD("quit...");
|
||||
|
||||
if (options->show_touches) {
|
||||
LOGI("Disable show_touches");
|
||||
set_show_touches_enabled(options->serial, SDL_FALSE);
|
||||
}
|
||||
|
||||
screen_destroy(&screen);
|
||||
finally_stop_and_join_controller:
|
||||
controller_stop(&controller);
|
||||
|
|
|
@ -8,6 +8,7 @@ struct scrcpy_options {
|
|||
Uint16 port;
|
||||
Uint16 max_size;
|
||||
Uint32 bit_rate;
|
||||
SDL_bool show_touches;
|
||||
};
|
||||
|
||||
SDL_bool scrcpy(const struct scrcpy_options *options);
|
||||
|
|
Loading…
Reference in a new issue