Create keep_screen_off command line option.

(still doesn't have docs for it)
This commit is contained in:
brunoais 2020-07-19 21:02:07 +01:00
parent 22cdab6bfb
commit a99dee19b0
8 changed files with 26 additions and 5 deletions

View file

@ -566,6 +566,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
{"show-touches", no_argument, NULL, 't'},
{"stay-awake", no_argument, NULL, 'w'},
{"turn-screen-off", no_argument, NULL, 'S'},
{"keep-screen-off", no_argument, NULL, 'S'},
{"verbosity", required_argument, NULL, 'V'},
{"version", no_argument, NULL, 'v'},
{"window-title", required_argument, NULL, OPT_WINDOW_TITLE},
@ -649,6 +650,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
opts->serial = optarg;
break;
case 'S':
opts->keep_screen_off = opts->turn_screen_off;
opts->turn_screen_off = true;
break;
case 't':

View file

@ -311,6 +311,7 @@ scrcpy(const struct scrcpy_options *options) {
.lock_video_orientation = options->lock_video_orientation,
.control = options->control,
.display_id = options->display_id,
.keep_screen_off = options->keep_screen_off,
.show_touches = options->show_touches,
.stay_awake = options->stay_awake,
.codec_options = options->codec_options,

View file

@ -54,6 +54,7 @@ struct scrcpy_options {
bool control;
bool display;
bool turn_screen_off;
bool keep_screen_off;
bool render_expired_frames;
bool prefer_text;
bool window_borderless;
@ -93,6 +94,7 @@ struct scrcpy_options {
.control = true, \
.display = true, \
.turn_screen_off = false, \
.keep_screen_off = false, \
.render_expired_frames = false, \
.prefer_text = false, \
.window_borderless = false, \

View file

@ -294,6 +294,7 @@ execute_server(struct server *server, const struct server_params *params) {
params->show_touches ? "true" : "false",
params->stay_awake ? "true" : "false",
params->codec_options ? params->codec_options : "-",
params->keep_screen_off ? "true" : "false",
};
#ifdef SERVER_DEBUGGER
LOGI("Server debugger waiting for a client on device port "

View file

@ -55,6 +55,7 @@ struct server_params {
int8_t lock_video_orientation;
bool control;
uint16_t display_id;
bool keep_screen_off;
bool show_touches;
bool stay_awake;
bool force_adb_forward;

View file

@ -28,13 +28,15 @@ public class Controller {
private final MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[PointersState.MAX_POINTERS];
private final MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[PointersState.MAX_POINTERS];
private final Timer keepScreenOffTimer = new Timer("KeepScreenOff", true);
private final Timer keepScreenOffTimer;
public Controller(Device device, DesktopConnection connection) {
public Controller(Device device, DesktopConnection connection, boolean keepScreenOff) {
this.device = device;
this.connection = connection;
initPointers();
sender = new DeviceMessageSender(connection);
keepScreenOffTimer = keepScreenOff ? new Timer("KeepScreenOff", true) : null;
}
private void initPointers() {
@ -241,7 +243,7 @@ public class Controller {
* Tested on a low end Android 6 device
*/
public void scheduleScreenOff() {
if (screenStayOff) {
if (keepScreenOffTimer != null && screenStayOff) {
keepScreenOffTimer.schedule(
new TimerTask() {
@Override

View file

@ -16,6 +16,7 @@ public class Options {
private boolean showTouches;
private boolean stayAwake;
private String codecOptions;
private boolean keepScreenOff;
public Ln.Level getLogLevel() {
return logLevel;
@ -120,4 +121,12 @@ public class Options {
public void setCodecOptions(String codecOptions) {
this.codecOptions = codecOptions;
}
public boolean isKeepScreenOff() {
return keepScreenOff;
}
public void setKeepScreenOff(boolean keepScreenOff) {
this.keepScreenOff = keepScreenOff;
}
}

View file

@ -57,7 +57,7 @@ public final class Server {
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps(), codecOptions);
if (options.getControl()) {
final Controller controller = new Controller(device, connection);
final Controller controller = new Controller(device, connection, options.isKeepScreenOff());
// asynchronous
startController(controller);
@ -120,7 +120,7 @@ public final class Server {
"The server version (" + BuildConfig.VERSION_NAME + ") does not match the client " + "(" + clientVersion + ")");
}
final int expectedParameters = 14;
final int expectedParameters = 15;
if (args.length != expectedParameters) {
throw new IllegalArgumentException("Expecting " + expectedParameters + " parameters");
}
@ -167,6 +167,9 @@ public final class Server {
String codecOptions = args[13];
options.setCodecOptions(codecOptions);
boolean keepScreenOff = Boolean.parseBoolean(args[14]);
options.setKeepScreenOff(keepScreenOff);
return options;
}