Accept negative window position
It seems to work on some window managers. Fixes #1242 <https://github.com/Genymobile/scrcpy/issues/1242>
This commit is contained in:
parent
3504c0016b
commit
dc7c677728
5 changed files with 25 additions and 11 deletions
|
@ -131,13 +131,13 @@ Set a custom window title.
|
||||||
.BI "\-\-window\-x " value
|
.BI "\-\-window\-x " value
|
||||||
Set the initial window horizontal position.
|
Set the initial window horizontal position.
|
||||||
|
|
||||||
Default is -1 (automatic).\n
|
Default is "auto".\n
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-window\-y " value
|
.BI "\-\-window\-y " value
|
||||||
Set the initial window vertical position.
|
Set the initial window vertical position.
|
||||||
|
|
||||||
Default is -1 (automatic).\n
|
Default is "auto".\n
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-window\-width " value
|
.BI "\-\-window\-width " value
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -116,11 +117,11 @@ scrcpy_print_usage(const char *arg0) {
|
||||||
"\n"
|
"\n"
|
||||||
" --window-x value\n"
|
" --window-x value\n"
|
||||||
" Set the initial window horizontal position.\n"
|
" Set the initial window horizontal position.\n"
|
||||||
" Default is -1 (automatic).\n"
|
" Default is \"auto\".\n"
|
||||||
"\n"
|
"\n"
|
||||||
" --window-y value\n"
|
" --window-y value\n"
|
||||||
" Set the initial window vertical position.\n"
|
" Set the initial window vertical position.\n"
|
||||||
" Default is -1 (automatic).\n"
|
" Default is \"auto\".\n"
|
||||||
"\n"
|
"\n"
|
||||||
" --window-width value\n"
|
" --window-width value\n"
|
||||||
" Set the initial window width.\n"
|
" Set the initial window width.\n"
|
||||||
|
@ -302,8 +303,16 @@ parse_lock_video_orientation(const char *s, int8_t *lock_video_orientation) {
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
parse_window_position(const char *s, int16_t *position) {
|
parse_window_position(const char *s, int16_t *position) {
|
||||||
|
// special value for "auto"
|
||||||
|
static_assert(WINDOW_POSITION_UNDEFINED == -0x8000);
|
||||||
|
|
||||||
|
if (!strcmp(s, "auto")) {
|
||||||
|
*position = WINDOW_POSITION_UNDEFINED;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
long value;
|
long value;
|
||||||
bool ok = parse_integer_arg(s, &value, false, -1, 0x7FFF,
|
bool ok = parse_integer_arg(s, &value, false, -0x7FFF, 0x7FFF,
|
||||||
"window position");
|
"window position");
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -21,8 +21,8 @@ struct scrcpy_options {
|
||||||
uint32_t bit_rate;
|
uint32_t bit_rate;
|
||||||
uint16_t max_fps;
|
uint16_t max_fps;
|
||||||
int8_t lock_video_orientation;
|
int8_t lock_video_orientation;
|
||||||
int16_t window_x;
|
int16_t window_x; // WINDOW_POSITION_UNDEFINED for "auto"
|
||||||
int16_t window_y;
|
int16_t window_y; // WINDOW_POSITION_UNDEFINED for "auto"
|
||||||
uint16_t window_width;
|
uint16_t window_width;
|
||||||
uint16_t window_height;
|
uint16_t window_height;
|
||||||
bool show_touches;
|
bool show_touches;
|
||||||
|
@ -51,8 +51,8 @@ struct scrcpy_options {
|
||||||
.bit_rate = DEFAULT_BIT_RATE, \
|
.bit_rate = DEFAULT_BIT_RATE, \
|
||||||
.max_fps = 0, \
|
.max_fps = 0, \
|
||||||
.lock_video_orientation = DEFAULT_LOCK_VIDEO_ORIENTATION, \
|
.lock_video_orientation = DEFAULT_LOCK_VIDEO_ORIENTATION, \
|
||||||
.window_x = -1, \
|
.window_x = WINDOW_POSITION_UNDEFINED, \
|
||||||
.window_y = -1, \
|
.window_y = WINDOW_POSITION_UNDEFINED, \
|
||||||
.window_width = 0, \
|
.window_width = 0, \
|
||||||
.window_height = 0, \
|
.window_height = 0, \
|
||||||
.show_touches = false, \
|
.show_touches = false, \
|
||||||
|
|
|
@ -186,8 +186,10 @@ screen_init_rendering(struct screen *screen, const char *window_title,
|
||||||
window_flags |= SDL_WINDOW_BORDERLESS;
|
window_flags |= SDL_WINDOW_BORDERLESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = window_x != -1 ? window_x : (int) SDL_WINDOWPOS_UNDEFINED;
|
int x = window_x != WINDOW_POSITION_UNDEFINED
|
||||||
int y = window_y != -1 ? window_y : (int) SDL_WINDOWPOS_UNDEFINED;
|
? window_x : (int) SDL_WINDOWPOS_UNDEFINED;
|
||||||
|
int y = window_y != WINDOW_POSITION_UNDEFINED
|
||||||
|
? window_y : (int) SDL_WINDOWPOS_UNDEFINED;
|
||||||
screen->window = SDL_CreateWindow(window_title, x, y,
|
screen->window = SDL_CreateWindow(window_title, x, y,
|
||||||
window_size.width, window_size.height,
|
window_size.width, window_size.height,
|
||||||
window_flags);
|
window_flags);
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
#define WINDOW_POSITION_UNDEFINED (-0x8000)
|
||||||
|
|
||||||
struct video_buffer;
|
struct video_buffer;
|
||||||
|
|
||||||
struct screen {
|
struct screen {
|
||||||
|
@ -53,6 +55,7 @@ void
|
||||||
screen_init(struct screen *screen);
|
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)
|
||||||
|
// window_x and window_y accept WINDOW_POSITION_UNDEFINED
|
||||||
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,
|
||||||
|
|
Loading…
Reference in a new issue