2

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?

3

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.

1
  • You're right. When hitting enter key fast, the display stays off. So sleep 1 is to make sure xset does not register keyrelease upon hitting enter key. Thank you. – zindarod May 13 '17 at 18:32
0

I think its probably to do with what the system considers to be "user activity".

If the system detects keyboard activity it comes back from sleep. That fact that you press enter to send the force standby command counts as some "current" activity and so it immediately un-sleeps.

sleep 1 ensures that the keyboard has not recorded activity for 1 second before the sleep command is sent, so standby goes ahead.

1
  • There are potentially 2 human activity events occurring as you press the enter key. key down , comand run , key up. If you exagerate the delay in key up you always see the screen come back. – teknopaul May 12 '17 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.