Monday, May 20, 2024
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 3009  / 2 Years ago, tue, august 30, 2022, 4:49:30

I have the following line to turn my laptop display off:



sleep 1 && xset dpms force standby


sleep 1: Puts the thread to sleep for 1 second.



xset dpms force standby: From man, forces the dpms flag to standby.



When I omit the sleep 1 command, the xset command puts the pc in standby mode for 1 second, then automatically resumes normal operation. But when combined with sleep 1 command, it puts the pc in standby mode indefinitely, until a user input has been detected.



Can you explain the relationship between these two commands and why it works this way?


More From » command-line

 Answers
4

When you run your command, two events happens, "KeyPress" and "KeyRelease".



So when you run this command with pressing Enter button.



xset dpms force standby


First a "KeyPress" happens, it will cause the command to immediately be run and puts the monitor to sleep, when you release the Enter key, then "KeyRelease" happens and it's a user activity so monitor comes back to working.



If you do the job really fast (Hitting the Enter and realsing it before command being run) your monitor stays at "sleep" state.






To test this things, install x11-xserver-utils package.



sudo apt install x11-xserver-utils


then run xev.



Now hit the Enter to see whats happens; you should see something more or less like:



KeyPress event, serial 48, synthetic NO, window 0x2600001,
...

KeyRelease event, serial 48, synthetic NO, window 0x2600001,
...





So we use sleep to make sure both this events happens before command being run.


[#11286] Tuesday, August 30, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ampolinhad

Total Points: 88
Total Questions: 100
Total Answers: 116

Location: South Georgia
Member since Tue, Feb 1, 2022
2 Years ago
;