Add a shortcut to pause/unpause display

Pause/unpause display on MOD+z and MOD+Shift+z.

It only impacts rendering, the device is still captured, the video
stream continues to be transmitted to the device and recorded (if
recording is enabled).

Fixes #1632 <https://github.com/Genymobile/scrcpy/issues/1632>
PR #4748 <https://github.com/Genymobile/scrcpy/pull/4748>
display_pause
Romain Vimont 3 months ago
parent be3d357a6d
commit 1c3801a0b1

@ -577,6 +577,14 @@ Flip display horizontally
.B MOD+Shift+Up, MOD+Shift+Down .B MOD+Shift+Up, MOD+Shift+Down
Flip display vertically Flip display vertically
.TP
.B MOD+z
Pause or re-pause display
.TP
.B MOD+Shift+z
Unpause display
.TP .TP
.B MOD+g .B MOD+g
Resize window to 1:1 (pixel\-perfect) Resize window to 1:1 (pixel\-perfect)

@ -900,6 +900,14 @@ static const struct sc_shortcut shortcuts[] = {
.shortcuts = { "MOD+Shift+Up", "MOD+Shift+Down" }, .shortcuts = { "MOD+Shift+Up", "MOD+Shift+Down" },
.text = "Flip display vertically", .text = "Flip display vertically",
}, },
{
.shortcuts = { "MOD+z" },
.text = "Pause or re-pause display",
},
{
.shortcuts = { "MOD+Shift+z" },
.text = "Unpause display",
},
{ {
.shortcuts = { "MOD+g" }, .shortcuts = { "MOD+g" },
.text = "Resize window to 1:1 (pixel-perfect)", .text = "Resize window to 1:1 (pixel-perfect)",

@ -402,6 +402,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,
const SDL_KeyboardEvent *event) { const SDL_KeyboardEvent *event) {
// controller is NULL if --no-control is requested // controller is NULL if --no-control is requested
bool control = im->controller; bool control = im->controller;
bool paused = im->screen->paused;
SDL_Keycode keycode = event->keysym.sym; SDL_Keycode keycode = event->keysym.sym;
uint16_t mod = event->keysym.mod; uint16_t mod = event->keysym.mod;
@ -427,46 +428,51 @@ sc_input_manager_process_key(struct sc_input_manager *im,
enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP; enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP;
switch (keycode) { switch (keycode) {
case SDLK_h: case SDLK_h:
if (im->kp && !shift && !repeat) { if (im->kp && !shift && !repeat && !paused) {
action_home(im, action); action_home(im, action);
} }
return; return;
case SDLK_b: // fall-through case SDLK_b: // fall-through
case SDLK_BACKSPACE: case SDLK_BACKSPACE:
if (im->kp && !shift && !repeat) { if (im->kp && !shift && !repeat && !paused) {
action_back(im, action); action_back(im, action);
} }
return; return;
case SDLK_s: case SDLK_s:
if (im->kp && !shift && !repeat) { if (im->kp && !shift && !repeat && !paused) {
action_app_switch(im, action); action_app_switch(im, action);
} }
return; return;
case SDLK_m: case SDLK_m:
if (im->kp && !shift && !repeat) { if (im->kp && !shift && !repeat && !paused) {
action_menu(im, action); action_menu(im, action);
} }
return; return;
case SDLK_p: case SDLK_p:
if (im->kp && !shift && !repeat) { if (im->kp && !shift && !repeat && !paused) {
action_power(im, action); action_power(im, action);
} }
return; return;
case SDLK_o: case SDLK_o:
if (control && !repeat && down) { if (control && !repeat && down && !paused) {
enum sc_screen_power_mode mode = shift enum sc_screen_power_mode mode = shift
? SC_SCREEN_POWER_MODE_NORMAL ? SC_SCREEN_POWER_MODE_NORMAL
: SC_SCREEN_POWER_MODE_OFF; : SC_SCREEN_POWER_MODE_OFF;
set_screen_power_mode(im, mode); set_screen_power_mode(im, mode);
} }
return; return;
case SDLK_z:
if (down && !repeat) {
sc_screen_set_paused(im->screen, !shift);
}
return;
case SDLK_DOWN: case SDLK_DOWN:
if (shift) { if (shift) {
if (!repeat & down) { if (!repeat & down) {
apply_orientation_transform(im, apply_orientation_transform(im,
SC_ORIENTATION_FLIP_180); SC_ORIENTATION_FLIP_180);
} }
} else if (im->kp) { } else if (im->kp && !paused) {
// forward repeated events // forward repeated events
action_volume_down(im, action); action_volume_down(im, action);
} }
@ -477,7 +483,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,
apply_orientation_transform(im, apply_orientation_transform(im,
SC_ORIENTATION_FLIP_180); SC_ORIENTATION_FLIP_180);
} }
} else if (im->kp) { } else if (im->kp && !paused) {
// forward repeated events // forward repeated events
action_volume_up(im, action); action_volume_up(im, action);
} }
@ -505,17 +511,17 @@ sc_input_manager_process_key(struct sc_input_manager *im,
} }
return; return;
case SDLK_c: case SDLK_c:
if (im->kp && !shift && !repeat && down) { if (im->kp && !shift && !repeat && down && !paused) {
get_device_clipboard(im, SC_COPY_KEY_COPY); get_device_clipboard(im, SC_COPY_KEY_COPY);
} }
return; return;
case SDLK_x: case SDLK_x:
if (im->kp && !shift && !repeat && down) { if (im->kp && !shift && !repeat && down && !paused) {
get_device_clipboard(im, SC_COPY_KEY_CUT); get_device_clipboard(im, SC_COPY_KEY_CUT);
} }
return; return;
case SDLK_v: case SDLK_v:
if (im->kp && !repeat && down) { if (im->kp && !repeat && down && !paused) {
if (shift || im->legacy_paste) { if (shift || im->legacy_paste) {
// inject the text as input events // inject the text as input events
clipboard_paste(im); clipboard_paste(im);
@ -547,7 +553,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,
} }
return; return;
case SDLK_n: case SDLK_n:
if (control && !repeat && down) { if (control && !repeat && down && !paused) {
if (shift) { if (shift) {
collapse_panels(im); collapse_panels(im);
} else if (im->key_repeat == 0) { } else if (im->key_repeat == 0) {
@ -558,12 +564,12 @@ sc_input_manager_process_key(struct sc_input_manager *im,
} }
return; return;
case SDLK_r: case SDLK_r:
if (control && !shift && !repeat && down) { if (control && !shift && !repeat && down && !paused) {
rotate_device(im); rotate_device(im);
} }
return; return;
case SDLK_k: case SDLK_k:
if (control && !shift && !repeat && down if (control && !shift && !repeat && down && !paused
&& im->kp && im->kp->hid) { && im->kp && im->kp->hid) {
// Only if the current keyboard is hid // Only if the current keyboard is hid
open_hard_keyboard_settings(im); open_hard_keyboard_settings(im);
@ -574,7 +580,7 @@ sc_input_manager_process_key(struct sc_input_manager *im,
return; return;
} }
if (!im->kp) { if (!im->kp || paused) {
return; return;
} }
@ -622,7 +628,6 @@ sc_input_manager_process_key(struct sc_input_manager *im,
static void static void
sc_input_manager_process_mouse_motion(struct sc_input_manager *im, sc_input_manager_process_mouse_motion(struct sc_input_manager *im,
const SDL_MouseMotionEvent *event) { const SDL_MouseMotionEvent *event) {
if (event->which == SDL_TOUCH_MOUSEID) { if (event->which == SDL_TOUCH_MOUSEID) {
// simulated from touch events, so it's a duplicate // simulated from touch events, so it's a duplicate
return; return;
@ -695,16 +700,16 @@ sc_input_manager_process_touch(struct sc_input_manager *im,
static void static void
sc_input_manager_process_mouse_button(struct sc_input_manager *im, sc_input_manager_process_mouse_button(struct sc_input_manager *im,
const SDL_MouseButtonEvent *event) { const SDL_MouseButtonEvent *event) {
bool control = im->controller;
if (event->which == SDL_TOUCH_MOUSEID) { if (event->which == SDL_TOUCH_MOUSEID) {
// simulated from touch events, so it's a duplicate // simulated from touch events, so it's a duplicate
return; return;
} }
bool control = im->controller;
bool paused = im->screen->paused;
bool down = event->type == SDL_MOUSEBUTTONDOWN; bool down = event->type == SDL_MOUSEBUTTONDOWN;
if (!im->forward_all_clicks) { if (!im->forward_all_clicks) {
if (control) { if (control && !paused) {
enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP; enum sc_action action = down ? SC_ACTION_DOWN : SC_ACTION_UP;
if (im->kp && event->button == SDL_BUTTON_X1) { if (im->kp && event->button == SDL_BUTTON_X1) {
@ -747,7 +752,7 @@ sc_input_manager_process_mouse_button(struct sc_input_manager *im,
// otherwise, send the click event to the device // otherwise, send the click event to the device
} }
if (!im->mp) { if (!im->mp || paused) {
return; return;
} }
@ -885,9 +890,10 @@ void
sc_input_manager_handle_event(struct sc_input_manager *im, sc_input_manager_handle_event(struct sc_input_manager *im,
const SDL_Event *event) { const SDL_Event *event) {
bool control = im->controller; bool control = im->controller;
bool paused = im->screen->paused;
switch (event->type) { switch (event->type) {
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
if (!im->kp) { if (!im->kp || paused) {
break; break;
} }
sc_input_manager_process_text_input(im, &event->text); sc_input_manager_process_text_input(im, &event->text);
@ -899,13 +905,13 @@ sc_input_manager_handle_event(struct sc_input_manager *im,
sc_input_manager_process_key(im, &event->key); sc_input_manager_process_key(im, &event->key);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
if (!im->mp) { if (!im->mp || paused) {
break; break;
} }
sc_input_manager_process_mouse_motion(im, &event->motion); sc_input_manager_process_mouse_motion(im, &event->motion);
break; break;
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
if (!im->mp) { if (!im->mp || paused) {
break; break;
} }
sc_input_manager_process_mouse_wheel(im, &event->wheel); sc_input_manager_process_mouse_wheel(im, &event->wheel);
@ -919,7 +925,7 @@ sc_input_manager_handle_event(struct sc_input_manager *im,
case SDL_FINGERMOTION: case SDL_FINGERMOTION:
case SDL_FINGERDOWN: case SDL_FINGERDOWN:
case SDL_FINGERUP: case SDL_FINGERUP:
if (!im->mp) { if (!im->mp || paused) {
break; break;
} }
sc_input_manager_process_touch(im, &event->tfinger); sc_input_manager_process_touch(im, &event->tfinger);

@ -362,6 +362,8 @@ sc_screen_init(struct sc_screen *screen,
screen->maximized = false; screen->maximized = false;
screen->minimized = false; screen->minimized = false;
screen->mouse_capture_key_pressed = 0; screen->mouse_capture_key_pressed = 0;
screen->paused = false;
screen->resume_frame = NULL;
screen->req.x = params->window_x; screen->req.x = params->window_x;
screen->req.y = params->window_y; screen->req.y = params->window_y;
@ -614,13 +616,10 @@ prepare_for_frame(struct sc_screen *screen, struct sc_size new_frame_size) {
} }
static bool static bool
sc_screen_update_frame(struct sc_screen *screen) { sc_screen_apply_frame(struct sc_screen *screen) {
av_frame_unref(screen->frame);
sc_frame_buffer_consume(&screen->fb, screen->frame);
AVFrame *frame = screen->frame;
sc_fps_counter_add_rendered_frame(&screen->fps_counter); sc_fps_counter_add_rendered_frame(&screen->fps_counter);
AVFrame *frame = screen->frame;
struct sc_size new_frame_size = {frame->width, frame->height}; struct sc_size new_frame_size = {frame->width, frame->height};
enum sc_display_result res = prepare_for_frame(screen, new_frame_size); enum sc_display_result res = prepare_for_frame(screen, new_frame_size);
if (res == SC_DISPLAY_RESULT_ERROR) { if (res == SC_DISPLAY_RESULT_ERROR) {
@ -655,6 +654,54 @@ sc_screen_update_frame(struct sc_screen *screen) {
return true; return true;
} }
static bool
sc_screen_update_frame(struct sc_screen *screen) {
if (screen->paused) {
if (!screen->resume_frame) {
screen->resume_frame = av_frame_alloc();
if (!screen->resume_frame) {
LOG_OOM();
return false;
}
} else {
av_frame_unref(screen->resume_frame);
}
sc_frame_buffer_consume(&screen->fb, screen->resume_frame);
return true;
}
av_frame_unref(screen->frame);
sc_frame_buffer_consume(&screen->fb, screen->frame);
return sc_screen_apply_frame(screen);
}
void
sc_screen_set_paused(struct sc_screen *screen, bool paused) {
if (!paused && !screen->paused) {
// nothing to do
return;
}
if (screen->paused && screen->resume_frame) {
// If display screen was paused, refresh the frame immediately, even if
// the new state is also paused.
av_frame_free(&screen->frame);
screen->frame = screen->resume_frame;
screen->resume_frame = NULL;
sc_screen_apply_frame(screen);
}
if (!paused) {
LOGI("Display screen unpaused");
} else if (!screen->paused) {
LOGI("Display screen paused");
} else {
LOGI("Display screen re-paused");
}
screen->paused = paused;
}
void void
sc_screen_switch_fullscreen(struct sc_screen *screen) { sc_screen_switch_fullscreen(struct sc_screen *screen) {
uint32_t new_mode = screen->fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP; uint32_t new_mode = screen->fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP;

@ -64,6 +64,9 @@ struct sc_screen {
SDL_Keycode mouse_capture_key_pressed; SDL_Keycode mouse_capture_key_pressed;
AVFrame *frame; AVFrame *frame;
bool paused;
AVFrame *resume_frame;
}; };
struct sc_screen_params { struct sc_screen_params {
@ -135,6 +138,10 @@ void
sc_screen_set_orientation(struct sc_screen *screen, sc_screen_set_orientation(struct sc_screen *screen,
enum sc_orientation orientation); enum sc_orientation orientation);
// set the display pause state
void
sc_screen_set_paused(struct sc_screen *screen, bool paused);
// react to SDL events // react to SDL events
// If this function returns false, scrcpy must exit with an error. // If this function returns false, scrcpy must exit with an error.
bool bool

@ -28,6 +28,8 @@ _<kbd>[Super]</kbd> is typically the <kbd>Windows</kbd> or <kbd>Cmd</kbd> key._
| Rotate display right | <kbd>MOD</kbd>+<kbd></kbd> _(right)_ | Rotate display right | <kbd>MOD</kbd>+<kbd></kbd> _(right)_
| Flip display horizontally | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd></kbd> _(left)_ \| <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd></kbd> _(right)_ | Flip display horizontally | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd></kbd> _(left)_ \| <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd></kbd> _(right)_
| Flip display vertically | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd></kbd> _(up)_ \| <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd></kbd> _(down)_ | Flip display vertically | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd></kbd> _(up)_ \| <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd></kbd> _(down)_
| Pause or re-pause display | <kbd>MOD</kbd>+<kbd>z</kbd>
| Unpause display | <kbd>MOD</kbd>+<kbd>Shift</kbd>+<kbd>z</kbd>
| Resize window to 1:1 (pixel-perfect) | <kbd>MOD</kbd>+<kbd>g</kbd> | Resize window to 1:1 (pixel-perfect) | <kbd>MOD</kbd>+<kbd>g</kbd>
| Resize window to remove black borders | <kbd>MOD</kbd>+<kbd>w</kbd> \| _Double-left-click¹_ | Resize window to remove black borders | <kbd>MOD</kbd>+<kbd>w</kbd> \| _Double-left-click¹_
| Click on `HOME` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _Middle-click_ | Click on `HOME` | <kbd>MOD</kbd>+<kbd>h</kbd> \| _Middle-click_

Loading…
Cancel
Save