Implement device screen off while mirroring
Add two shortcuts: - Ctrl+o to turn the device screen off while mirroring - Ctrl+Shift+o to turn it back on On power on (either via the POWER key or BACK while screen is off), both the device screen and the mirror are turned on. <https://github.com/Genymobile/scrcpy/issues/175>
This commit is contained in:
@@ -55,6 +55,9 @@ control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
||||
&buf[1]);
|
||||
return 1 + len;
|
||||
}
|
||||
case CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE:
|
||||
buf[1] = msg->set_screen_power_mode.mode;
|
||||
return 2;
|
||||
case CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON:
|
||||
case CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||
case CONTROL_MSG_TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||
|
||||
@@ -24,6 +24,13 @@ enum control_msg_type {
|
||||
CONTROL_MSG_TYPE_COLLAPSE_NOTIFICATION_PANEL,
|
||||
CONTROL_MSG_TYPE_GET_CLIPBOARD,
|
||||
CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
||||
CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE,
|
||||
};
|
||||
|
||||
enum screen_power_mode {
|
||||
// see <https://android.googlesource.com/platform/frameworks/base.git/+/pie-release-2/core/java/android/view/SurfaceControl.java#305>
|
||||
SCREEN_POWER_MODE_OFF = 0,
|
||||
SCREEN_POWER_MODE_NORMAL = 2,
|
||||
};
|
||||
|
||||
struct control_msg {
|
||||
@@ -50,6 +57,9 @@ struct control_msg {
|
||||
struct {
|
||||
char *text; // owned, to be freed by SDL_free()
|
||||
} set_clipboard;
|
||||
struct {
|
||||
enum screen_power_mode mode;
|
||||
} set_screen_power_mode;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -159,6 +159,18 @@ set_device_clipboard(struct controller *controller) {
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_screen_power_mode(struct controller *controller,
|
||||
enum screen_power_mode mode) {
|
||||
struct control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
|
||||
msg.set_screen_power_mode.mode = mode;
|
||||
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
LOGW("Cannot request 'set screen power mode'");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
switch_fps_counter_state(struct video_buffer *vb) {
|
||||
mutex_lock(vb->mutex);
|
||||
@@ -263,6 +275,14 @@ input_manager_process_key(struct input_manager *input_manager,
|
||||
action_power(input_manager->controller, action);
|
||||
}
|
||||
return;
|
||||
case SDLK_o:
|
||||
if (control && ctrl && !meta && event->type == SDL_KEYDOWN) {
|
||||
enum screen_power_mode mode = shift
|
||||
? SCREEN_POWER_MODE_NORMAL
|
||||
: SCREEN_POWER_MODE_OFF;
|
||||
set_screen_power_mode(input_manager->controller, mode);
|
||||
}
|
||||
return;
|
||||
case SDLK_DOWN:
|
||||
#ifdef __APPLE__
|
||||
if (control && !ctrl && meta && !shift) {
|
||||
|
||||
@@ -129,7 +129,13 @@ static void usage(const char *arg0) {
|
||||
" click on POWER (turn screen on/off)\n"
|
||||
"\n"
|
||||
" Right-click (when screen is off)\n"
|
||||
" turn screen on\n"
|
||||
" power on\n"
|
||||
"\n"
|
||||
" Ctrl+o\n"
|
||||
" turn device screen off (keep mirroring)\n"
|
||||
"\n"
|
||||
" Ctrl+Shift+o\n"
|
||||
" turn device screen on\n"
|
||||
"\n"
|
||||
" Ctrl+n\n"
|
||||
" expand notification panel\n"
|
||||
|
||||
Reference in New Issue
Block a user