Merge pull request #412 from npes87184/dev

app: add always_on_top
This commit is contained in:
Romain Vimont 2019-01-27 14:09:19 +01:00 committed by GitHub
commit aa07dfd2ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 15 deletions

View file

@ -196,6 +196,16 @@ scrcpy -f # short version
Fullscreen can then be toggled dynamically with `Ctrl`+`f`. Fullscreen can then be toggled dynamically with `Ctrl`+`f`.
### Always on top
The window of app can always be above others by:
```bash
scrcpy --always-on-top
scrcpy -T # short version
```
### Show touches ### Show touches
For presentations, it may be useful to show physical touches (on the physical For presentations, it may be useful to show physical touches (on the physical

View file

@ -19,6 +19,7 @@ struct args {
Uint16 port; Uint16 port;
Uint16 max_size; Uint16 max_size;
Uint32 bit_rate; Uint32 bit_rate;
SDL_bool always_on_top;
}; };
static void usage(const char *arg0) { static void usage(const char *arg0) {
@ -65,6 +66,9 @@ static void usage(const char *arg0) {
" Enable \"show touches\" on start, disable on quit.\n" " Enable \"show touches\" on start, disable on quit.\n"
" It only shows physical touches (not clicks from scrcpy).\n" " It only shows physical touches (not clicks from scrcpy).\n"
"\n" "\n"
" -T, --always-on-top\n"
" Make scrcpy window always on top (above other windows).\n"
"\n"
" -v, --version\n" " -v, --version\n"
" Print the version of scrcpy.\n" " Print the version of scrcpy.\n"
"\n" "\n"
@ -206,6 +210,7 @@ static SDL_bool parse_port(char *optarg, Uint16 *port) {
static SDL_bool parse_args(struct args *args, int argc, char *argv[]) { static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
static const struct option long_options[] = { static const struct option long_options[] = {
{"always-on-top", no_argument, NULL, 'T'},
{"bit-rate", required_argument, NULL, 'b'}, {"bit-rate", required_argument, NULL, 'b'},
{"crop", required_argument, NULL, 'c'}, {"crop", required_argument, NULL, 'c'},
{"fullscreen", no_argument, NULL, 'f'}, {"fullscreen", no_argument, NULL, 'f'},
@ -219,7 +224,7 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
{NULL, 0, NULL, 0 }, {NULL, 0, NULL, 0 },
}; };
int c; int c;
while ((c = getopt_long(argc, argv, "b:c:fhm:p:r:s:tv", long_options, NULL)) != -1) { while ((c = getopt_long(argc, argv, "b:c:fhm:p:r:s:tTv", long_options, NULL)) != -1) {
switch (c) { switch (c) {
case 'b': case 'b':
if (!parse_bit_rate(optarg, &args->bit_rate)) { if (!parse_bit_rate(optarg, &args->bit_rate)) {
@ -254,6 +259,9 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
case 't': case 't':
args->show_touches = SDL_TRUE; args->show_touches = SDL_TRUE;
break; break;
case 'T':
args->always_on_top = SDL_TRUE;
break;
case 'v': case 'v':
args->version = SDL_TRUE; args->version = SDL_TRUE;
break; break;
@ -288,6 +296,7 @@ int 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,
.always_on_top = SDL_FALSE,
}; };
if (!parse_args(&args, argc, argv)) { if (!parse_args(&args, argc, argv)) {
return 1; return 1;
@ -324,6 +333,7 @@ int main(int argc, char *argv[]) {
.bit_rate = args.bit_rate, .bit_rate = args.bit_rate,
.show_touches = args.show_touches, .show_touches = args.show_touches,
.fullscreen = args.fullscreen, .fullscreen = args.fullscreen,
.always_on_top = args.always_on_top,
}; };
int res = scrcpy(&options) ? 0 : 1; int res = scrcpy(&options) ? 0 : 1;

View file

@ -223,7 +223,7 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
goto finally_destroy_controller; goto finally_destroy_controller;
} }
if (!screen_init_rendering(&screen, device_name, frame_size)) { if (!screen_init_rendering(&screen, device_name, frame_size, options->always_on_top)) {
ret = SDL_FALSE; ret = SDL_FALSE;
goto finally_stop_and_join_controller; goto finally_stop_and_join_controller;
} }

View file

@ -12,6 +12,7 @@ struct scrcpy_options {
Uint32 bit_rate; Uint32 bit_rate;
SDL_bool show_touches; SDL_bool show_touches;
SDL_bool fullscreen; SDL_bool fullscreen;
SDL_bool always_on_top;
}; };
SDL_bool scrcpy(const struct scrcpy_options *options); SDL_bool scrcpy(const struct scrcpy_options *options);

View file

@ -144,7 +144,10 @@ static inline SDL_Texture *create_texture(SDL_Renderer *renderer, struct size fr
frame_size.width, frame_size.height); frame_size.width, frame_size.height);
} }
SDL_bool screen_init_rendering(struct screen *screen, const char *device_name, struct size frame_size) { SDL_bool screen_init_rendering(struct screen *screen,
const char *device_name,
struct size frame_size,
SDL_bool always_on_top) {
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);
@ -152,6 +155,10 @@ SDL_bool screen_init_rendering(struct screen *screen, const char *device_name, s
#ifdef HIDPI_SUPPORT #ifdef HIDPI_SUPPORT
window_flags |= SDL_WINDOW_ALLOW_HIGHDPI; window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif #endif
if (always_on_top) {
window_flags |= SDL_WINDOW_ALWAYS_ON_TOP;
}
screen->window = SDL_CreateWindow(device_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen->window = SDL_CreateWindow(device_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
window_size.width, window_size.height, window_flags); window_size.width, window_size.height, window_flags);
if (!screen->window) { if (!screen->window) {

View file

@ -43,7 +43,8 @@ void 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)
SDL_bool screen_init_rendering(struct screen *screen, SDL_bool screen_init_rendering(struct screen *screen,
const char *device_name, const char *device_name,
struct size frame_size); struct size frame_size,
SDL_bool always_on_top);
// show the window // show the window
void screen_show_window(struct screen *screen); void screen_show_window(struct screen *screen);