How to turn off screen (DPMS) together with locking session in KDE?

Solution 1:

Found a way for KDE 4 (up to Ubuntu 14.10). For modern KDE 5 see other answer.

  1. Go to System SettingsApplication and System NotificationsManage Notifications.

  2. Select Screen Saver as the Event Source

  3. Locate and select the Screen Locked

  4. add this command to the event:

     xset dpms force off
    

enter image description here

It will turn off all displays every time it gets locked.

Solution 2:

Confirmed: running the command: /bin/sleep 1 ; /usr/bin/xset dpms force off within the screen locked notification works for Plasmashell 5.10.

Go to: System Settings > Notifications > Event source "Screen Saver":

Notifications -- System Settings

Solution 3:

With KDE Plasma 5.18, it is a little bit different from this comment.

Search for Notification via Super and follow the screenshots below:

Notifications

Notifications - Application Settings

Configure Notifications - System Settings Module

I used /bin/sleep 5; /usr/bin/xset dpms force off instead of 1, but that's up to you.

Solution 4:

As of KDE 5, most of the solutions here no longer work.

Here's what I found that works though (as of 2016-09-28), create a text document and in it copy and paste the following code:

#!/bin/sh
sleep 0.5
loginctl lock-session
xset dpms force off

and then save it as "KDE5lockscreenanddpms.sh" The name doesn't matter, just make sure you have the .sh at the end of it. Then navigate to where you saved with your file manager, right click on it and open up properties>permissions> and make it executable.

Now you can click on it and it will run the script which will lock your screen and then after .5 seconds will turn your monitor(s) off.

Here are some posts with the info about these commands.

KDE.org- loginctl lock-session

Linux-apps.com - sleep 0.5 xset dpms force off

Solution 5:

One possible solution is switch to xscreensaver. The man page actually come with instruction.

Following is outline

  1. Disable KDE screen saver

    1. K menu -> Computer -> System Settings -> Display and Monitor -> Screen Saver
    2. Uncheck Start automatically after
  2. Install xscreensaver

    sudo apt-get install xscreensaver

  3. Create ~/.kde/Autostart/xscreensaver.desktop

    Add following lines into it

    [Desktop Entry]
    Exec=xscreensaver
    Name=XScreenSaver
    Type=Application
    X-KDE-StartupNotify=false
    
  4. Replace KDE lock screen

    cd /usr/lib/kde4/libexec
    sudo mv kscreenlocker kscreenlocker.original
    sudo vim kscreenlocker
    

    Add following lines into kscreenlocker

    #!/bin/sh
    xscreensaver-command -lock
    
  5. Use xscreensaver-demo to configure dpms (no sudo)

    Configure DPMS in Advance tab. The minimum standby is 1min.

    However, you can try make it less by editing ~/.xscreensaver after first time configuration. Look for dpmsStandby: in the file.

    Not sure if it work if dpmsStandby: is changed to 0:00:00. I am testing with a VM and the black screen look the same.