Display and control your Android device
Add --lock-video-orientation=initial
Romain Vimontfd0dc6c0cdc2
diff --git a/README.md b/README.mdindex d9aeb142..037c5828 100644--- a/README.md+++ b/README.md@@ -198,6 +198,7 @@ If `--max-size` is also specified, resizing is applied after cropping.To lock the orientation of the mirroring:```bash+scrcpy --lock-video-orientation initial # initial (current) orientationscrcpy --lock-video-orientation 0 # natural orientationscrcpy --lock-video-orientation 1 # 90° counterclockwisescrcpy --lock-video-orientation 2 # 180°diff --git a/app/scrcpy.1 b/app/scrcpy.1index ea9bce9b..89b7ee75 100644--- a/app/scrcpy.1+++ b/app/scrcpy.1@@ -84,9 +84,9 @@ This is a workaround for some devices not behaving as expected when setting the.TP.BI "\-\-lock\-video\-orientation " value-Lock video orientation to \fIvalue\fR. Possible values are -1 (unlocked), 0, 1, 2 and 3. Natural device orientation is 0, and each increment adds a 90 degrees otation counterclockwise.+Lock video orientation to \fIvalue\fR. Possible values are "unlocked", "initial" (locked to the initial orientation), 0, 1, 2 and 3. Natural device orientation is 0, and each increment adds a 90 degrees otation counterclockwise.-Default is -1 (unlocked).+Default is "unlocked"..TP.BI "\-\-max\-fps " valuediff --git a/app/src/cli.c b/app/src/cli.cindex ec3c1294..05e178e0 100644--- a/app/src/cli.c+++ b/app/src/cli.c@@ -81,10 +81,11 @@ scrcpy_print_usage(const char *arg0) {"\n"" --lock-video-orientation value\n"" Lock video orientation to value.\n"- " Possible values are -1 (unlocked), 0, 1, 2 and 3.\n"+ " Possible values are \"unlocked\", \"initial\" (locked to the\n"+ " initial orientation), 0, 1, 2 and 3.\n"" Natural device orientation is 0, and each increment adds a\n"" 90 degrees rotation counterclockwise.\n"- " Default is -1 (unlocked).\n"+ " Default is \"unlocked\".\n""\n"" --max-fps value\n"" Limit the frame rate of screen capture (officially supported\n"@@ -383,15 +384,27 @@ parse_max_fps(const char *s, uint16_t *max_fps) {}static bool-parse_lock_video_orientation(const char *s, int8_t *lock_video_orientation) {+parse_lock_video_orientation(const char *s,+ enum sc_lock_video_orientation *lock_mode) {+ if (!strcmp(s, "initial")) {+ // Without argument, lock the initial orientation+ *lock_mode = SC_LOCK_VIDEO_ORIENTATION_INITIAL;+ return true;+ }++ if (!strcmp(s, "unlocked")) {+ *lock_mode = SC_LOCK_VIDEO_ORIENTATION_UNLOCKED;+ return true;+ }+long value;- bool ok = parse_integer_arg(s, &value, false, -1, 3,+ bool ok = parse_integer_arg(s, &value, false, 0, 3,"lock video orientation");if (!ok) {return false;}- *lock_video_orientation = (int8_t) value;+ *lock_mode = (enum sc_lock_video_orientation) value;return true;}@@ -765,7 +778,8 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {}break;case OPT_LOCK_VIDEO_ORIENTATION:- if (!parse_lock_video_orientation(optarg, &opts->lock_video_orientation)) {+ if (!parse_lock_video_orientation(optarg,+ &opts->lock_video_orientation)) {return false;}break;diff --git a/app/src/scrcpy.h b/app/src/scrcpy.hindex f91cb6b8..7c2689ab 100644--- a/app/src/scrcpy.h+++ b/app/src/scrcpy.h@@ -20,6 +20,16 @@ enum sc_record_format {SC_RECORD_FORMAT_MKV,};+enum sc_lock_video_orientation {+ SC_LOCK_VIDEO_ORIENTATION_UNLOCKED = -1,+ // lock the current orientation when scrcpy starts+ SC_LOCK_VIDEO_ORIENTATION_INITIAL = -2,+ SC_LOCK_VIDEO_ORIENTATION_0 = 0,+ SC_LOCK_VIDEO_ORIENTATION_1,+ SC_LOCK_VIDEO_ORIENTATION_2,+ SC_LOCK_VIDEO_ORIENTATION_3,+};+#define SC_MAX_SHORTCUT_MODS 8enum sc_shortcut_mod {@@ -59,7 +69,7 @@ struct scrcpy_options {uint16_t max_size;uint32_t bit_rate;uint16_t max_fps;- int8_t lock_video_orientation;+ enum sc_lock_video_orientation lock_video_orientation;uint8_t rotation;int16_t window_x; // SC_WINDOW_POSITION_UNDEFINED for "auto"int16_t window_y; // SC_WINDOW_POSITION_UNDEFINED for "auto"@@ -106,7 +116,7 @@ struct scrcpy_options {.max_size = 0, \.bit_rate = DEFAULT_BIT_RATE, \.max_fps = 0, \- .lock_video_orientation = -1, \+ .lock_video_orientation = SC_LOCK_VIDEO_ORIENTATION_UNLOCKED, \.rotation = 0, \.window_x = SC_WINDOW_POSITION_UNDEFINED, \.window_y = SC_WINDOW_POSITION_UNDEFINED, \diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.javaindex a63976fd..2d67ab6f 100644--- a/server/src/main/java/com/genymobile/scrcpy/Device.java+++ b/server/src/main/java/com/genymobile/scrcpy/Device.java@@ -25,6 +25,9 @@ public final class Device {public static final int POWER_MODE_OFF = SurfaceControl.POWER_MODE_OFF;public static final int POWER_MODE_NORMAL = SurfaceControl.POWER_MODE_NORMAL;+ public static final int LOCK_VIDEO_ORIENTATION_UNLOCKED = -1;+ public static final int LOCK_VIDEO_ORIENTATION_INITIAL = -2;+private static final ServiceManager SERVICE_MANAGER = new ServiceManager();public interface RotationListener {diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenInfo.java b/server/src/main/java/com/genymobile/scrcpy/ScreenInfo.javaindex 10acfb50..c27322ef 100644--- a/server/src/main/java/com/genymobile/scrcpy/ScreenInfo.java+++ b/server/src/main/java/com/genymobile/scrcpy/ScreenInfo.java@@ -82,6 +82,12 @@ public final class ScreenInfo {public static ScreenInfo computeScreenInfo(DisplayInfo displayInfo, Rect crop, int maxSize, int lockedVideoOrientation) {int rotation = displayInfo.getRotation();++ if (lockedVideoOrientation == Device.LOCK_VIDEO_ORIENTATION_INITIAL) {+ // The user requested to lock the video orientation to the current orientation+ lockedVideoOrientation = rotation;+ }+Size deviceSize = displayInfo.getSize();Rect contentRect = new Rect(0, 0, deviceSize.getWidth(), deviceSize.getHeight());if (crop != null) {