Display and control your Android device
Add --rotation command-line option
Romain Vimont28c71c528f08
diff --git a/README.md b/README.mdindex 321acfd6..97be9f71 100644--- a/README.md+++ b/README.md@@ -340,6 +340,33 @@ scrcpy -f # short versionFullscreen can then be toggled dynamically with `Ctrl`+`f`.+#### Rotation++The window may be rotated:++```bash+scrcpy --rotation 1+```++Possibles values are:+ - `0`: no rotation+ - `1`: 90 degrees counterclockwise+ - `2`: 180 degrees+ - `3`: 90 degrees clockwise++The rotation can also be changed dynamically with `Ctrl`+`←` _(left)_ and+`Ctrl`+`→` _(right)_.++Note that _scrcpy_ manages 3 different rotations:+ - `Ctrl`+`r` requests the device to switch between portrait and landscape (the+ current running app may refuse, if it does support the requested+ orientation).+ - `--lock-video-orientation` changes the mirroring orientation (the orientation+ of the video sent from the device to the computer. This affects the+ recording.+ - `--rotation` (or `Ctrl`+`←`/`Ctrl`+`→`) rotates only the window content. This+ affects only the display, not the recording.+### Other mirroring optionsdiff --git a/app/scrcpy.1 b/app/scrcpy.1index 2bcde227..e44bfc7e 100644--- a/app/scrcpy.1+++ b/app/scrcpy.1@@ -110,6 +110,10 @@ Force recording format (either mp4 or mkv)..B \-\-render\-expired\-framesBy default, to minimize latency, scrcpy always renders the last available decoded frame, and drops any previous ones. This flag forces to render all frames, at a cost of a possible increased latency.+.TP+.BI "\-\-rotation " value+Set the initial display rotation. Possibles values are 0, 1, 2 and 3. Each increment adds a 90 degrees rotation counterclockwise.+.TP.BI "\-s, \-\-serial " numberThe device serial number. Mandatory only if several devices are connected to adb.diff --git a/app/src/cli.c b/app/src/cli.cindex c4d5585a..44f06ef2 100644--- a/app/src/cli.c+++ b/app/src/cli.c@@ -104,6 +104,11 @@ scrcpy_print_usage(const char *arg0) {" This flag forces to render all frames, at a cost of a\n"" possible increased latency.\n""\n"+ " --rotation value\n"+ " Set the initial display rotation.\n"+ " Possibles values are 0, 1, 2 and 3. Each increment adds a 90\n"+ " degrees rotation counterclockwise.\n"+ "\n"" -s, --serial serial\n"" The device serial number. Mandatory only if several devices\n"" are connected to adb.\n"@@ -316,6 +321,18 @@ parse_lock_video_orientation(const char *s, int8_t *lock_video_orientation) {return true;}+static bool+parse_rotation(const char *s, uint8_t *rotation) {+ long value;+ bool ok = parse_integer_arg(s, &value, false, 0, 3, "rotation");+ if (!ok) {+ return false;+ }++ *rotation = (uint8_t) value;+ return true;+}+static boolparse_window_position(const char *s, int16_t *position) {// special value for "auto"@@ -435,6 +452,7 @@ guess_record_format(const char *filename) {#define OPT_MAX_FPS 1012#define OPT_LOCK_VIDEO_ORIENTATION 1013#define OPT_DISPLAY_ID 1014+#define OPT_ROTATION 1015boolscrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {@@ -455,6 +473,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {{"push-target", required_argument, NULL, OPT_PUSH_TARGET},{"record", required_argument, NULL, 'r'},{"record-format", required_argument, NULL, OPT_RECORD_FORMAT},+ {"rotation", required_argument, NULL, OPT_ROTATION},{"render-expired-frames", no_argument, NULL,OPT_RENDER_EXPIRED_FRAMES},{"serial", required_argument, NULL, 's'},@@ -592,6 +611,11 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {case OPT_PREFER_TEXT:opts->prefer_text = true;break;+ case OPT_ROTATION:+ if (!parse_rotation(optarg, &opts->rotation)) {+ return false;+ }+ break;default:// getopt prints the error message on stderrreturn false;diff --git a/app/src/scrcpy.c b/app/src/scrcpy.cindex 84c87ad8..94e8cde5 100644--- a/app/src/scrcpy.c+++ b/app/src/scrcpy.c@@ -396,7 +396,8 @@ scrcpy(const struct scrcpy_options *options) {options->always_on_top, options->window_x,options->window_y, options->window_width,options->window_height,- options->window_borderless)) {+ options->window_borderless,+ options->rotation)) {goto end;}diff --git a/app/src/scrcpy.h b/app/src/scrcpy.hindex b6c52fd7..93ee6724 100644--- a/app/src/scrcpy.h+++ b/app/src/scrcpy.h@@ -21,6 +21,7 @@ struct scrcpy_options {uint32_t bit_rate;uint16_t max_fps;int8_t lock_video_orientation;+ uint8_t rotation;int16_t window_x; // WINDOW_POSITION_UNDEFINED for "auto"int16_t window_y; // WINDOW_POSITION_UNDEFINED for "auto"uint16_t window_width;@@ -52,6 +53,7 @@ struct scrcpy_options {.bit_rate = DEFAULT_BIT_RATE, \.max_fps = 0, \.lock_video_orientation = DEFAULT_LOCK_VIDEO_ORIENTATION, \+ .rotation = 0, \.window_x = WINDOW_POSITION_UNDEFINED, \.window_y = WINDOW_POSITION_UNDEFINED, \.window_width = 0, \diff --git a/app/src/screen.c b/app/src/screen.cindex f506e1d6..ae33cd27 100644--- a/app/src/screen.c+++ b/app/src/screen.c@@ -178,8 +178,13 @@ boolscreen_init_rendering(struct screen *screen, const char *window_title,struct size frame_size, bool always_on_top,int16_t window_x, int16_t window_y, uint16_t window_width,- uint16_t window_height, bool window_borderless) {+ uint16_t window_height, bool window_borderless,+ uint8_t rotation) {screen->frame_size = frame_size;+ screen->rotation = rotation;+ if (rotation) {+ LOGI("Initial display rotation set to %u", rotation);+ }struct size content_size =get_rotated_size(frame_size, screen->rotation);diff --git a/app/src/screen.h b/app/src/screen.hindex 4e893811..8afbbf46 100644--- a/app/src/screen.h+++ b/app/src/screen.h@@ -63,7 +63,8 @@ boolscreen_init_rendering(struct screen *screen, const char *window_title,struct size frame_size, bool always_on_top,int16_t window_x, int16_t window_y, uint16_t window_width,- uint16_t window_height, bool window_borderless);+ uint16_t window_height, bool window_borderless,+ uint8_t rotation);// show the windowvoid