Skip to content

1573/Turn the screen back off if it's known to turn on by an action in scrcpy #1577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

brunoais
Copy link
Contributor

@brunoais brunoais commented Jul 8, 2020

On my phone (cheap phone running Android 6), this hack works.
I was unable to find a decent way to achieve this otherwise.

What do you think? Any better ideas?

closes #1573

@brunoais brunoais changed the title Turn the screen back off if it's known to turn on by an action in scrcpy 1573/Turn the screen back off if it's known to turn on by an action in scrcpy Jul 9, 2020
@brunoais brunoais force-pushed the 1573/ScreenBackOffIf_remote_consequently_turnedOn branch from d559955 to dfdfb54 Compare July 10, 2020 07:02
@brunoais
Copy link
Contributor Author

@rom1v Any comments or sth?

@rom1v
Copy link
Collaborator

rom1v commented Jul 14, 2020

@brunoais Sorry I didn't have the time to test yet.

However, as I said in #1573 (comment), I still think this is too "hacky" and may cause problems. For example if 2 scrcpy are started for the same device (this is already a problem for cleanup, but here it's only a one-time problem), or it does not behave the same way if we press power physically or via Ctrl+p, and probably other problems…

@brunoais
Copy link
Contributor Author

brunoais commented Jul 15, 2020

@brunoais Sorry I didn't have the time to test yet.

Ah OK. I didn't know whether you didn't have time or it was de-prioritized or forgotten.

You are right. The behavior is different between acting directly on the device and on scrcpy. Howeverr if there are more than one instance of scrcpy connected to the same device, I don't see what kind of problem this may really create.
However, I do understand the inconsistency this can create.

What about we get this feature opt-in by running it behind a command line argument, with (hopefully) proper explanation about it? Would that be a good compromise?

@brunoais brunoais force-pushed the 1573/ScreenBackOffIf_remote_consequently_turnedOn branch from dfdfb54 to a99dee1 Compare July 19, 2020 20:04
@brunoais
Copy link
Contributor Author

I made this feature opt-in.
Even though it's execution is still not so good, maybe with some decent docs about it, it it works acceptably well.

@rom1v
Copy link
Collaborator

rom1v commented Jul 19, 2020

I quickly tested before my holidays, it worked quite well. I might consider merging with this behavior. But I will do more tests before. But probably not before few weeks.

@brunoais
Copy link
Contributor Author

Sure. Thank you for keeping me updated.
I'll wait and let me know how to update the README to be more clear to users. I'll try to get some ideas myself.

rom1v pushed a commit that referenced this pull request Aug 3, 2020
@rom1v
Copy link
Collaborator

rom1v commented Aug 3, 2020

I acknowledge that it is convenient especially on right-click to turn the screen on (keeping the physical device screen off), even if --stay-awake (while plugged in) already provided a (partial) solution.

I took some of your commits and squashed them (I didn't make it optional, so I didn't include Create keep_screen_off command line option): 2a7f3d7

  • I replaced magic numbers by KeyEvent constants (like KeyEvent.KEYCODE_POWER).
  • I moved the test screenStayOff to the callers
  • I also moved the calls to scheduleScreenOff() to the injection methods (as a side-effect, this avoids to call it on right-click when it actually injects BACK).

I also suggest to replace Timer by Executor: https://stackoverflow.com/questions/409932/java-timer-vs-executorservice
as follow: e31b13b

The branch is pr1577. Are you ok with these changes?

_Also, I will probably rename "screen off" to "power mode off" (for example schedulePowerModeOff()), to avoid confusion with the existing "turn screen on" (in particular, pressBackOrTurnScreenOn(), when it turns the screen on, schedules "screen off", which is confusing). _

(The behavior is a bit weird after pressing the physical POWER button: the screen is turned on, but then pressing POWER via scrcpy turns it back off.)

I don't know whether I will merge it yet.
More opinions are welcome :)

@brunoais
Copy link
Contributor Author

brunoais commented Aug 3, 2020

@rom1v I approve all the changes you did.

rom1v pushed a commit that referenced this pull request Aug 6, 2020
PR #1577 <#1577>
Fixes #1573 <#1573>

Signed-off-by: Romain Vimont <[email protected]>
@rom1v
Copy link
Collaborator

rom1v commented Aug 6, 2020

Merged cf9d449

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants