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

28,859

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.

Share:
28,859

Related videos on Youtube

gertvdijk
Author by

gertvdijk

FOSS enthousiast, Developer, Debian GNU/Linux (and Ubuntu) user, DevOps with Ansible/Pupppet powers, Coding in C/C++/Python. Keywords: Linux, KVM/Libvirt, Kubernetes, Ansible, Docker, Python, a bit of C/C++/Kotlin, Debian, Ubuntu, Apache, Kopano, Postfix, MySQL, PostgreSQL, Kafka, security, KDE, SSL/TLS. Every now and then I'll write an article on those topics my blog. Other sites I'm active on: Launchpad, Tweakers.net, Twitter, LinkedIn

Updated on September 18, 2022

Comments

  • gertvdijk
    gertvdijk over 1 year

    First of all, I'm aware a similar question for GNOME is asked here: "Switch off laptop backlight when locking screen".

    Objective

    I would like to turn off my screen on locking the session for power saving reasons.

    Actual problem

    Locking the screen on Kubuntu (KDE) inevitably triggers the screensaver as far as I can see. There's no screensaver option other than 'Blank screen' together with its background colour set to black that comes just close to my goal. It blanks the screen, but doesn't turn off the screen. Screen's backlight will still be on and not saving any power.

    Current workaround

    A workaround via a script + shortcut key is possible, however, it's just a workaround since it doesn't trigger on all ways to lock the session. Therefore, I think it should be possible to have it done more elegantly, for example by providing this option in KDE's configuration dialog of the screensaver.

    The workaround I am now using is the following. A script that locks the screen and turns off the screen:

    #!/bin/bash
    
    qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock
    xset dpms force standby
    

    and let it run with a shortcut key via a custom menu entry. It works.

    Here's why I consider it to be a workaround rather than a solution. It doesn't work for other ways to trigger the locking of the session.

    My actual question(s)

    Do I need to touching/patching KDE's source?

    • If not what are my options?
    • If so,
      • could someone point me to where I can get started?
      • what do you think is the recommended place in the GUI for configuration?

    I'm using Kubuntu 12.04 and willing to upgrade to KDE 4.9 or waiting for the 12.10 release.

  • gertvdijk
    gertvdijk over 11 years
    Are you sure replacing kscreenlocker is a good idea? It does more than locking the screen, reading from kscreenlocker --help. Other than that, it's a good suggestion to move to Xscreensaver!
  • John Siu
    John Siu over 11 years
    My bad, I should have added that moving to Xscreensave will actually replace your kde screen saver also. Other than that there is no side effect. The kscreenlocker --help is showing how it can be used/call, it works with kde screen saver. Moving to xscreensaver is a work around for now.
  • John Siu
    John Siu over 11 years
    Regarding new vesion of KDE you can check out this post and this post. People with KDC 4.9 or 4.10 seems to encounter some very annoying issue with dpms and actually want to turn off the feature. So I would say don't upgrade kde for now.
  • gertvdijk
    gertvdijk over 10 years
    This is simply SWEET and clever. The trick is to think of "Screen Saver" in the context of locking the screen.
  • Kaz Wolfe
    Kaz Wolfe over 9 years
    Can you explain how this works and what it does?
  • gertvdijk
    gertvdijk almost 9 years
    For Kubuntu 15.04 users - this approach appears hit a bug in which KDE daemon crashes completely, taking the whole session with it... :-(
  • SomeoneSomewhereSupportsMonica
    SomeoneSomewhereSupportsMonica almost 9 years
    @gertvdijk Hmm. Might have to check that - I'm still on 14.04, and it's working for me. Though I've slowly expanded this to about half a dozen different things that happens when I lock/unlock.
  • Alan Thompson
    Alan Thompson over 8 years
    xset dpms force standby seems to be very reliable and doesn't need the sleep 1 ; xset dpms force off trick.
  • SomeoneSomewhereSupportsMonica
    SomeoneSomewhereSupportsMonica over 8 years
    @AlanThompson, the sleep 1 is just so that if you're using a mouse to click a button, you have time to let go of the mouse and it to stop moving before the display turns off. Otherwise, it can wake up the display instantly, which might mean you need to enter your password before you can lock the display again. Not sure where I recommended using sleep 1, though.
  • gertvdijk
    gertvdijk over 8 years
    And then what? It does not turn off my screen (DPMS) when locking. So it does not answer my question.
  • gertvdijk
    gertvdijk over 7 years
    Hmm, I'm missing something perhaps... How to get to a window that has the "complex" tab?
  • gertvdijk
    gertvdijk over 7 years
    Did you mean to comment this to the other XScreensaver answer perhaps? askubuntu.com/a/232844/88802
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 7 years
    The OP is 4 years old and KDE version is < 4.9. Your answer should address the differences.
  • dr0i
    dr0i over 7 years
    My kde is in German and "Komplex" seems to be "Advance" in English version. Also, it's debian, not ubuntu. Should I delete my answer?
  • Tom Pohl
    Tom Pohl over 3 years
    Without the sleep it doesn't work for me, so thanks for this hint!
  • Admin
    Admin about 2 years
    In kubuntu 22.04 after a period of black screen. The display would automatically turn on again for me.