mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-21 03:55:05 +00:00
Adding intent broadcasts cli options from the client
This commit is contained in:
parent
eae1c7e5d6
commit
5190bf8289
5 changed files with 69 additions and 0 deletions
|
@ -656,6 +656,51 @@ guess_record_format(const char *filename) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
parse_intent_broadcast(const char *s, uint32_t *intents) {
|
||||
|
||||
// if no arg provided activates all intents for all intents and purposes
|
||||
if(!s){
|
||||
*intents = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
char *comma = strchr(s, ',');
|
||||
|
||||
assert(!comma || comma > s);
|
||||
size_t limit = comma ? (size_t) (comma - s) : strlen(s);
|
||||
|
||||
|
||||
#define STREQ(literal, s, len) \
|
||||
((sizeof(literal)-1 == len) && !memcmp(literal, s, len))
|
||||
|
||||
if (STREQ("start", s, limit)) {
|
||||
*intents |= SC_INTENT_BROADCAST_START;
|
||||
} else if (STREQ("stop", s, limit)) {
|
||||
*intents |= SC_INTENT_BROADCAST_STOP;
|
||||
} else if (STREQ("cleaned", s, limit)) {
|
||||
*intents |= SC_INTENT_BROADCAST_CLEANED;
|
||||
} else {
|
||||
LOGE("Unknown broadcast intent: %.*s "
|
||||
"(must be one of: start, stop, cleaned)",
|
||||
(int) limit, s);
|
||||
return false;
|
||||
}
|
||||
#undef STREQ
|
||||
|
||||
if (!comma) {
|
||||
break;
|
||||
}
|
||||
|
||||
s = comma + 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#define OPT_RENDER_EXPIRED_FRAMES 1000
|
||||
#define OPT_WINDOW_TITLE 1001
|
||||
#define OPT_PUSH_TARGET 1002
|
||||
|
@ -684,6 +729,7 @@ guess_record_format(const char *filename) {
|
|||
#define OPT_ENCODER_NAME 1025
|
||||
#define OPT_POWER_OFF_ON_CLOSE 1026
|
||||
#define OPT_V4L2_SINK 1027
|
||||
#define OPT_INTENT_BROADCAST 1028
|
||||
|
||||
bool
|
||||
scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
||||
|
@ -739,6 +785,8 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||
OPT_WINDOW_BORDERLESS},
|
||||
{"power-off-on-close", no_argument, NULL,
|
||||
OPT_POWER_OFF_ON_CLOSE},
|
||||
{"intent-broadcast", optional_argument, NULL,
|
||||
OPT_INTENT_BROADCAST},
|
||||
{NULL, 0, NULL, 0 },
|
||||
};
|
||||
|
||||
|
@ -917,6 +965,12 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
|||
opts->v4l2_device = optarg;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case OPT_INTENT_BROADCAST:
|
||||
if (!parse_intent_broadcast(optarg, &opts->intent_broadcasts)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// getopt prints the error message on stderr
|
||||
return false;
|
||||
|
|
|
@ -278,6 +278,7 @@ scrcpy(const struct scrcpy_options *options) {
|
|||
.encoder_name = options->encoder_name,
|
||||
.force_adb_forward = options->force_adb_forward,
|
||||
.power_off_on_close = options->power_off_on_close,
|
||||
.intent_broadcasts = options->intent_broadcasts,
|
||||
};
|
||||
if (!server_start(&s->server, ¶ms)) {
|
||||
goto end;
|
||||
|
|
|
@ -53,6 +53,14 @@ struct sc_port_range {
|
|||
|
||||
#define SC_WINDOW_POSITION_UNDEFINED (-0x8000)
|
||||
|
||||
|
||||
enum sc_intent_broadcast {
|
||||
SC_INTENT_BROADCAST_START = 1 << 0,
|
||||
SC_INTENT_BROADCAST_STOP = 1 << 30,
|
||||
SC_INTENT_BROADCAST_CLEANED = 1 << 31,
|
||||
};
|
||||
|
||||
|
||||
struct scrcpy_options {
|
||||
const char *serial;
|
||||
const char *crop;
|
||||
|
@ -93,6 +101,7 @@ struct scrcpy_options {
|
|||
bool forward_all_clicks;
|
||||
bool legacy_paste;
|
||||
bool power_off_on_close;
|
||||
uint32_t intent_broadcasts;
|
||||
};
|
||||
|
||||
#define SCRCPY_OPTIONS_DEFAULT { \
|
||||
|
@ -141,6 +150,7 @@ struct scrcpy_options {
|
|||
.forward_all_clicks = false, \
|
||||
.legacy_paste = false, \
|
||||
.power_off_on_close = false, \
|
||||
.intent_broadcasts = 0, \
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -256,11 +256,13 @@ execute_server(struct server *server, const struct server_params *params) {
|
|||
char max_fps_string[6];
|
||||
char lock_video_orientation_string[5];
|
||||
char display_id_string[11];
|
||||
char intent_broadcasts_string[11];
|
||||
sprintf(max_size_string, "%"PRIu16, params->max_size);
|
||||
sprintf(bit_rate_string, "%"PRIu32, params->bit_rate);
|
||||
sprintf(max_fps_string, "%"PRIu16, params->max_fps);
|
||||
sprintf(lock_video_orientation_string, "%"PRIi8, params->lock_video_orientation);
|
||||
sprintf(display_id_string, "%"PRIu32, params->display_id);
|
||||
sprintf(intent_broadcasts_string, "%"PRIu32, params->intent_broadcasts);
|
||||
const char *const cmd[] = {
|
||||
"shell",
|
||||
"CLASSPATH=" DEVICE_SERVER_PATH,
|
||||
|
@ -294,6 +296,7 @@ execute_server(struct server *server, const struct server_params *params) {
|
|||
params->codec_options ? params->codec_options : "-",
|
||||
params->encoder_name ? params->encoder_name : "-",
|
||||
params->power_off_on_close ? "true" : "false",
|
||||
intent_broadcasts_string,
|
||||
};
|
||||
#ifdef SERVER_DEBUGGER
|
||||
LOGI("Server debugger waiting for a client on device port "
|
||||
|
|
|
@ -49,6 +49,7 @@ struct server_params {
|
|||
bool stay_awake;
|
||||
bool force_adb_forward;
|
||||
bool power_off_on_close;
|
||||
uint32_t intent_broadcasts;
|
||||
};
|
||||
|
||||
// init default values
|
||||
|
|
Loading…
Add table
Reference in a new issue