mirror of
https://github.com/Genymobile/scrcpy
synced 2024-12-28 10:12:19 +00:00
Add option to specify the initial window position
Add --window-x and --window-y parameters. Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
parent
771bd8404d
commit
ce5635f28c
@ -110,6 +110,14 @@ static void usage(const char *arg0) {
|
||||
" --window-title text\n"
|
||||
" Set a custom window title.\n"
|
||||
"\n"
|
||||
" --window-x value\n"
|
||||
" Set the initial window horizontal position.\n"
|
||||
" Default is -1 (automatic).\n"
|
||||
"\n"
|
||||
" --window-y value\n"
|
||||
" Set the initial window vertical position.\n"
|
||||
" Default is -1 (automatic).\n"
|
||||
"\n"
|
||||
"Shortcuts:\n"
|
||||
"\n"
|
||||
" " CTRL_OR_CMD "+f\n"
|
||||
@ -250,6 +258,27 @@ parse_max_size(char *optarg, uint16_t *max_size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_window_position(char *optarg, int16_t *position) {
|
||||
char *endptr;
|
||||
if (*optarg == '\0') {
|
||||
LOGE("Window position parameter is empty");
|
||||
return false;
|
||||
}
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*endptr != '\0') {
|
||||
LOGE("Invalid window position: %s", optarg);
|
||||
return false;
|
||||
}
|
||||
if (value < -1 || value > 0x7fff) {
|
||||
LOGE("Window position must be between -1 and 32767: %ld", value);
|
||||
return false;
|
||||
}
|
||||
|
||||
*position = (int16_t) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_port(char *optarg, uint16_t *port) {
|
||||
char *endptr;
|
||||
@ -308,6 +337,8 @@ guess_record_format(const char *filename) {
|
||||
#define OPT_CROP 1004
|
||||
#define OPT_RECORD_FORMAT 1005
|
||||
#define OPT_PREFER_TEXT 1006
|
||||
#define OPT_WINDOW_X 1007
|
||||
#define OPT_WINDOW_Y 1008
|
||||
|
||||
static bool
|
||||
parse_args(struct args *args, int argc, char *argv[]) {
|
||||
@ -331,8 +362,9 @@ parse_args(struct args *args, int argc, char *argv[]) {
|
||||
{"turn-screen-off", no_argument, NULL, 'S'},
|
||||
{"prefer-text", no_argument, NULL, OPT_PREFER_TEXT},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"window-title", required_argument, NULL,
|
||||
OPT_WINDOW_TITLE},
|
||||
{"window-title", required_argument, NULL, OPT_WINDOW_TITLE},
|
||||
{"window-x", required_argument, NULL, OPT_WINDOW_X},
|
||||
{"window-y", required_argument, NULL, OPT_WINDOW_Y},
|
||||
{NULL, 0, NULL, 0 },
|
||||
};
|
||||
|
||||
@ -410,6 +442,16 @@ parse_args(struct args *args, int argc, char *argv[]) {
|
||||
case OPT_WINDOW_TITLE:
|
||||
opts->window_title = optarg;
|
||||
break;
|
||||
case OPT_WINDOW_X:
|
||||
if (!parse_window_position(optarg, &opts->window_x)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_WINDOW_Y:
|
||||
if (!parse_window_position(optarg, &opts->window_y)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_PUSH_TARGET:
|
||||
opts->push_target = optarg;
|
||||
break;
|
||||
|
@ -387,7 +387,8 @@ scrcpy(const struct scrcpy_options *options) {
|
||||
options->window_title ? options->window_title : device_name;
|
||||
|
||||
if (!screen_init_rendering(&screen, window_title, frame_size,
|
||||
options->always_on_top)) {
|
||||
options->always_on_top, options->window_x,
|
||||
options->window_y)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,8 @@ struct scrcpy_options {
|
||||
uint16_t port;
|
||||
uint16_t max_size;
|
||||
uint32_t bit_rate;
|
||||
int16_t window_x;
|
||||
int16_t window_y;
|
||||
bool show_touches;
|
||||
bool fullscreen;
|
||||
bool always_on_top;
|
||||
@ -38,6 +40,8 @@ struct scrcpy_options {
|
||||
.port = DEFAULT_LOCAL_PORT, \
|
||||
.max_size = DEFAULT_LOCAL_PORT, \
|
||||
.bit_rate = DEFAULT_BIT_RATE, \
|
||||
.window_x = -1, \
|
||||
.window_y = -1, \
|
||||
.show_touches = false, \
|
||||
.fullscreen = false, \
|
||||
.always_on_top = false, \
|
||||
|
@ -141,7 +141,8 @@ create_texture(SDL_Renderer *renderer, struct size frame_size) {
|
||||
|
||||
bool
|
||||
screen_init_rendering(struct screen *screen, const char *window_title,
|
||||
struct size frame_size, bool always_on_top) {
|
||||
struct size frame_size, bool always_on_top,
|
||||
int16_t window_x, int16_t window_y) {
|
||||
screen->frame_size = frame_size;
|
||||
|
||||
struct size window_size = get_initial_optimal_size(frame_size);
|
||||
@ -158,8 +159,9 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
||||
#endif
|
||||
}
|
||||
|
||||
screen->window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
int x = window_x != -1 ? window_x : SDL_WINDOWPOS_UNDEFINED;
|
||||
int y = window_y != -1 ? window_y : SDL_WINDOWPOS_UNDEFINED;
|
||||
screen->window = SDL_CreateWindow(window_title, x, y,
|
||||
window_size.width, window_size.height,
|
||||
window_flags);
|
||||
if (!screen->window) {
|
||||
|
@ -55,7 +55,8 @@ screen_init(struct screen *screen);
|
||||
// initialize screen, create window, renderer and texture (window is hidden)
|
||||
bool
|
||||
screen_init_rendering(struct screen *screen, const char *window_title,
|
||||
struct size frame_size, bool always_on_top);
|
||||
struct size frame_size, bool always_on_top,
|
||||
int16_t window_x, int16_t window_y);
|
||||
|
||||
// show the window
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user