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
120f08ee96
commit
f983ec67fa
@ -29,6 +29,8 @@ struct args {
|
|||||||
uint16_t port;
|
uint16_t port;
|
||||||
uint16_t max_size;
|
uint16_t max_size;
|
||||||
uint32_t bit_rate;
|
uint32_t bit_rate;
|
||||||
|
int16_t window_x;
|
||||||
|
int16_t window_y;
|
||||||
bool always_on_top;
|
bool always_on_top;
|
||||||
bool turn_screen_off;
|
bool turn_screen_off;
|
||||||
bool render_expired_frames;
|
bool render_expired_frames;
|
||||||
@ -118,6 +120,14 @@ static void usage(const char *arg0) {
|
|||||||
" --window-title text\n"
|
" --window-title text\n"
|
||||||
" Set a custom window title.\n"
|
" Set a custom window title.\n"
|
||||||
"\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"
|
"Shortcuts:\n"
|
||||||
"\n"
|
"\n"
|
||||||
" " CTRL_OR_CMD "+f\n"
|
" " CTRL_OR_CMD "+f\n"
|
||||||
@ -258,6 +268,27 @@ parse_max_size(char *optarg, uint16_t *max_size) {
|
|||||||
return true;
|
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
|
static bool
|
||||||
parse_port(char *optarg, uint16_t *port) {
|
parse_port(char *optarg, uint16_t *port) {
|
||||||
char *endptr;
|
char *endptr;
|
||||||
@ -310,8 +341,10 @@ guess_record_format(const char *filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define OPT_RENDER_EXPIRED_FRAMES 1000
|
#define OPT_RENDER_EXPIRED_FRAMES 1000
|
||||||
#define OPT_WINDOW_TITLE 1001
|
#define OPT_PUSH_TARGET 1001
|
||||||
#define OPT_PUSH_TARGET 1002
|
#define OPT_WINDOW_TITLE 1002
|
||||||
|
#define OPT_WINDOW_X 1003
|
||||||
|
#define OPT_WINDOW_Y 1004
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
parse_args(struct args *args, int argc, char *argv[]) {
|
parse_args(struct args *args, int argc, char *argv[]) {
|
||||||
@ -335,8 +368,9 @@ parse_args(struct args *args, int argc, char *argv[]) {
|
|||||||
{"show-touches", no_argument, NULL, 't'},
|
{"show-touches", no_argument, NULL, 't'},
|
||||||
{"turn-screen-off", no_argument, NULL, 'S'},
|
{"turn-screen-off", no_argument, NULL, 'S'},
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"version", no_argument, NULL, 'v'},
|
||||||
{"window-title", required_argument, NULL,
|
{"window-title", required_argument, NULL, OPT_WINDOW_TITLE},
|
||||||
OPT_WINDOW_TITLE},
|
{"window-x", required_argument, NULL, OPT_WINDOW_X},
|
||||||
|
{"window-y", required_argument, NULL, OPT_WINDOW_Y},
|
||||||
{NULL, 0, NULL, 0 },
|
{NULL, 0, NULL, 0 },
|
||||||
};
|
};
|
||||||
int c;
|
int c;
|
||||||
@ -402,6 +436,16 @@ parse_args(struct args *args, int argc, char *argv[]) {
|
|||||||
case OPT_WINDOW_TITLE:
|
case OPT_WINDOW_TITLE:
|
||||||
args->window_title = optarg;
|
args->window_title = optarg;
|
||||||
break;
|
break;
|
||||||
|
case OPT_WINDOW_X:
|
||||||
|
if (!parse_window_position(optarg, &args->window_x)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OPT_WINDOW_Y:
|
||||||
|
if (!parse_window_position(optarg, &args->window_y)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case OPT_PUSH_TARGET:
|
case OPT_PUSH_TARGET:
|
||||||
args->push_target = optarg;
|
args->push_target = optarg;
|
||||||
break;
|
break;
|
||||||
@ -470,6 +514,8 @@ main(int argc, char *argv[]) {
|
|||||||
.port = DEFAULT_LOCAL_PORT,
|
.port = DEFAULT_LOCAL_PORT,
|
||||||
.max_size = DEFAULT_MAX_SIZE,
|
.max_size = DEFAULT_MAX_SIZE,
|
||||||
.bit_rate = DEFAULT_BIT_RATE,
|
.bit_rate = DEFAULT_BIT_RATE,
|
||||||
|
.window_x = -1,
|
||||||
|
.window_y = -1,
|
||||||
.always_on_top = false,
|
.always_on_top = false,
|
||||||
.no_control = false,
|
.no_control = false,
|
||||||
.no_display = false,
|
.no_display = false,
|
||||||
@ -514,6 +560,8 @@ main(int argc, char *argv[]) {
|
|||||||
.record_format = args.record_format,
|
.record_format = args.record_format,
|
||||||
.max_size = args.max_size,
|
.max_size = args.max_size,
|
||||||
.bit_rate = args.bit_rate,
|
.bit_rate = args.bit_rate,
|
||||||
|
.window_x = args.window_x,
|
||||||
|
.window_y = args.window_y,
|
||||||
.show_touches = args.show_touches,
|
.show_touches = args.show_touches,
|
||||||
.fullscreen = args.fullscreen,
|
.fullscreen = args.fullscreen,
|
||||||
.always_on_top = args.always_on_top,
|
.always_on_top = args.always_on_top,
|
||||||
|
@ -390,7 +390,8 @@ scrcpy(const struct scrcpy_options *options) {
|
|||||||
options->window_title ? options->window_title : device_name;
|
options->window_title ? options->window_title : device_name;
|
||||||
|
|
||||||
if (!screen_init_rendering(&screen, window_title, frame_size,
|
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;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@ struct scrcpy_options {
|
|||||||
uint16_t port;
|
uint16_t port;
|
||||||
uint16_t max_size;
|
uint16_t max_size;
|
||||||
uint32_t bit_rate;
|
uint32_t bit_rate;
|
||||||
|
int16_t window_x;
|
||||||
|
int16_t window_y;
|
||||||
bool show_touches;
|
bool show_touches;
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
bool always_on_top;
|
bool always_on_top;
|
||||||
|
@ -136,7 +136,8 @@ create_texture(SDL_Renderer *renderer, struct size frame_size) {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
screen_init_rendering(struct screen *screen, const char *window_title,
|
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;
|
screen->frame_size = frame_size;
|
||||||
|
|
||||||
struct size window_size = get_initial_optimal_size(frame_size);
|
struct size window_size = get_initial_optimal_size(frame_size);
|
||||||
@ -153,8 +154,9 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
screen->window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED,
|
int x = window_x != -1 ? window_x : SDL_WINDOWPOS_UNDEFINED;
|
||||||
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_size.width, window_size.height,
|
||||||
window_flags);
|
window_flags);
|
||||||
if (!screen->window) {
|
if (!screen->window) {
|
||||||
|
@ -46,7 +46,8 @@ screen_init(struct screen *screen);
|
|||||||
// initialize screen, create window, renderer and texture (window is hidden)
|
// initialize screen, create window, renderer and texture (window is hidden)
|
||||||
bool
|
bool
|
||||||
screen_init_rendering(struct screen *screen, const char *window_title,
|
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
|
// show the window
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user