From b858204786bbcf9700e0bed2dc5b4ce7f07b2e6b Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 13 Mar 2018 08:32:48 +0100 Subject: [PATCH] Remove black borders on double-click Resize the window to fit the device screen on click on black borders (same as Ctrl+x). Suggested-by: Guillaume Roche --- README.md | 31 ++++++++++++++++--------------- app/src/inputmanager.c | 10 ++++++++++ app/src/main.c | 1 + 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 337f12e1..195193d3 100644 --- a/README.md +++ b/README.md @@ -188,22 +188,23 @@ To run without installing: ## Shortcuts - | Action | Shortcut | - | -------------------------------------- |:---------------------------- | - | switch fullscreen mode | `Ctrl`+`f` | - | resize window to 1:1 (pixel-perfect) | `Ctrl`+`g` | - | resize window to remove black borders | `Ctrl`+`x` | - | click on `HOME` | `Ctrl`+`h` \| _Middle-click_ | - | click on `BACK` | `Ctrl`+`b` \| _Right-click¹_ | - | click on `APP_SWITCH` | `Ctrl`+`m` | - | click on `VOLUME_UP` | `Ctrl`+`+` | - | click on `VOLUME_DOWN` | `Ctrl`+`-` | - | click on `POWER` | `Ctrl`+`p` | - | turn screen on | _Right-click¹_ | - | paste computer clipboard to device | `Ctrl`+`v` | - | enable/disable FPS counter (on stdout) | `Ctrl`+`i` | + | Action | Shortcut | + | -------------------------------------- |:---------------------------- | + | switch fullscreen mode | `Ctrl`+`f` | + | resize window to 1:1 (pixel-perfect) | `Ctrl`+`g` | + | resize window to remove black borders | `Ctrl`+`x` \| _Double-click¹_ | + | click on `HOME` | `Ctrl`+`h` \| _Middle-click_ | + | click on `BACK` | `Ctrl`+`b` \| _Right-click²_ | + | click on `APP_SWITCH` | `Ctrl`+`m` | + | click on `VOLUME_UP` | `Ctrl`+`+` | + | click on `VOLUME_DOWN` | `Ctrl`+`-` | + | click on `POWER` | `Ctrl`+`p` | + | turn screen on | _Right-click¹_ | + | paste computer clipboard to device | `Ctrl`+`v` | + | enable/disable FPS counter (on stdout) | `Ctrl`+`i` | -_¹Right-click turns the screen on if it was off, presses BACK otherwise._ +_¹Double-click on black borders to remove them._ +_²Right-click turns the screen on if it was off, presses BACK otherwise._ ## Why _scrcpy_? diff --git a/app/src/inputmanager.c b/app/src/inputmanager.c index 6a9243e2..4a1140d4 100644 --- a/app/src/inputmanager.c +++ b/app/src/inputmanager.c @@ -235,6 +235,16 @@ void input_manager_process_mouse_button(struct input_manager *input_manager, action_home(input_manager->controller); return; } + // double-click on black borders resize to fit the device screen + if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) { + SDL_bool outside_device_screen = + event->x < 0 || event->x >= input_manager->screen->frame_size.width || + event->y < 0 || event->y >= input_manager->screen->frame_size.height; + if (outside_device_screen) { + screen_resize_to_fit(input_manager->screen); + } + return; + } }; struct control_event control_event; if (mouse_button_from_sdl_to_android(event, input_manager->screen->frame_size, &control_event)) { diff --git a/app/src/main.c b/app/src/main.c index 287c9d7d..b56b78a6 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -57,6 +57,7 @@ static void usage(const char *arg0) { " resize window to 1:1 (pixel-perfect)\n" "\n" " Ctrl+x\n" + " Double-click on black borders\n" " resize window to remove black borders\n" "\n" " Ctrl+h\n"