From 675704c71c0d105af2242d9bbeee83127097fa0d Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sat, 10 Mar 2018 00:11:52 +0100 Subject: [PATCH] Map right-click to BACK if screen is on Right-click was used to turn the screen on. It did nothing when the screen was already on. Instead, in that case, press BACK (like Vysor). Suggested by: --- README.md | 4 +++- app/src/controlevent.h | 2 +- app/src/inputmanager.c | 7 ++++--- .../main/java/com/genymobile/scrcpy/ControlEvent.java | 2 +- .../main/java/com/genymobile/scrcpy/EventController.java | 9 +++++++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8452f302..9c034ae2 100644 --- a/README.md +++ b/README.md @@ -199,10 +199,12 @@ To run without installing: | click on `VOLUME_UP` | `Ctrl`+`+` | | click on `VOLUME_DOWN` | `Ctrl`+`-` | | click on `POWER` | `Ctrl`+`p` | - | turn screen on | _Right-click_ | + | turn screen on or press BACK¹ | _Right-click_ | | paste computer clipboard to device | `Ctrl`+`v` | | enable/disable FPS counter (on stdout) | `Ctrl`+`i` | +_¹ Press BACK if the screen is already on._ + ## Why _scrcpy_? diff --git a/app/src/controlevent.h b/app/src/controlevent.h index 65f965e4..471a9a9b 100644 --- a/app/src/controlevent.h +++ b/app/src/controlevent.h @@ -20,7 +20,7 @@ enum control_event_type { CONTROL_EVENT_TYPE_COMMAND, }; -#define CONTROL_EVENT_COMMAND_SCREEN_ON 0 +#define CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON 0 struct control_event { enum control_event_type type; diff --git a/app/src/inputmanager.c b/app/src/inputmanager.c index 81fa9619..7b10a91d 100644 --- a/app/src/inputmanager.c +++ b/app/src/inputmanager.c @@ -78,10 +78,11 @@ static inline void action_volume_down(struct controller *controller) { send_keycode(controller, AKEYCODE_VOLUME_DOWN, "VOLUME_DOWN"); } -static void turn_screen_on(struct controller *controller) { +// turn the screen on if it was off, press BACK otherwise +static void press_back_or_turn_screen_on(struct controller *controller) { struct control_event control_event; control_event.type = CONTROL_EVENT_TYPE_COMMAND; - control_event.command_event.action = CONTROL_EVENT_COMMAND_SCREEN_ON; + control_event.command_event.action = CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON; if (!controller_push_event(controller, &control_event)) { LOGW("Cannot turn screen on"); @@ -226,7 +227,7 @@ void input_manager_process_mouse_motion(struct input_manager *input_manager, void input_manager_process_mouse_button(struct input_manager *input_manager, const SDL_MouseButtonEvent *event) { if (event->button == SDL_BUTTON_RIGHT && event->type == SDL_MOUSEBUTTONDOWN) { - turn_screen_on(input_manager->controller); + press_back_or_turn_screen_on(input_manager->controller); return; }; struct control_event control_event; diff --git a/server/src/main/java/com/genymobile/scrcpy/ControlEvent.java b/server/src/main/java/com/genymobile/scrcpy/ControlEvent.java index 43b8f930..3c9cbda1 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ControlEvent.java +++ b/server/src/main/java/com/genymobile/scrcpy/ControlEvent.java @@ -11,7 +11,7 @@ public final class ControlEvent { public static final int TYPE_SCROLL = 3; public static final int TYPE_COMMAND = 4; - public static final int COMMAND_SCREEN_ON = 0; + public static final int COMMAND_BACK_OR_SCREEN_ON = 0; private int type; private String text; diff --git a/server/src/main/java/com/genymobile/scrcpy/EventController.java b/server/src/main/java/com/genymobile/scrcpy/EventController.java index a7733f96..4a0ce331 100644 --- a/server/src/main/java/com/genymobile/scrcpy/EventController.java +++ b/server/src/main/java/com/genymobile/scrcpy/EventController.java @@ -167,10 +167,15 @@ public class EventController { return device.isScreenOn() || injectKeycode(KeyEvent.KEYCODE_POWER); } + private boolean pressBackOrTurnScreenOn() { + int keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER; + return injectKeycode(keycode); + } + private boolean executeCommand(int action) { switch (action) { - case ControlEvent.COMMAND_SCREEN_ON: - return turnScreenOn(); + case ControlEvent.COMMAND_BACK_OR_SCREEN_ON: + return pressBackOrTurnScreenOn(); default: Ln.w("Unsupported command: " + action); }