Plasma: Monitor Power Save command in X-11

Here is a snippet of a command that I use to turn off the screen immediately and not have to wait for the 10 minutes that I have set in the options. Sometimes, you don’t want to wait.

sleep 3  # Gives 3 seconds to let go of the mouse if clicking a link on the desktop.
xset dpms force off

This does work, but the first one or two times it will come right back on after a few seconds. If I let the 10 minutes expire and Plasma Power Devil turns off the monitor, it never fails to work. What command is Power Devil using? Or, is it something that I am just missing?

In Wayland, I use the following and it always works flawlessly, but this command does not work in X-11.

/bin/sleep 3 && /bin/dbus-send --session --print-reply --dest=org.kde.kglobalaccel  /component/org_kde_powerdevil org.kde.kglobalaccel.Component.invokeShortcut string:'Turn Off Screen'

If I knew where the file was, I would just open it and read it.

Thanks in advance. :slightly_smiling_face:

Both your commands work for me on X11.

Check if something inhibits dpms or if something wakes your monitor again

€: Just to test you could increase your sleep to 10 or something like that

I didn’t figure delaying the command would make any difference. I tried it anyway. No change on my end. Both seem to do the same thing. They turn the screen off, but a few seconds later, it comes right back on. Multiple attempts will succeed. I don’t know of anything disrupting the monitor going to sleep, yet it does. The mouse is not being moved. I can highlight the link or command and run it by hitting the Enter key and it will still fail after a few seconds. If I didn’t have an nVidia card in this PC, I would be using Wayland it it wouldn’t be a problem.

Thanks for helping out on this @Duha

I have no solution so far but I post things I looked up here so I can keep track. Maybe this also helps you find a solution.

If I use your command without sleep I can reproduce your issue (sometimes). With sleep I it works properly.
Since you mention org.kde.kglobalaccel.Component.invokeShortcut string:'Turn Off Screen' I checked the shortcuts and there is a Power Management → Turn off Screen hotkey. I tried it with the hotkey option but the screen always turns back on again. Relevant bug report: 423035 – Turn off screen shortcut turns the screen back on automatically
I will try on a plasma 6 session to see if it works there. €: still doesn’t work on plasma 6.

There are a few things you can try, but I doubt they work.

  • Since I saw a few posts about apps like steam turn the monitor back on you could try to close all programs and see if your commands work.
  • Try not clicking your script but just copy them into konsole → that’s the way I tried and it worked.
  • Increase the delay some more. I know you said it didn’t work for you but it is odd that it works for me.

Well, the first one still fails even after stopping Steam, but the second one seems to work. Strange that it didn’t work before installing Steam. :smile:

I just wish I knew the command that Plasma sends when the timer runs out, because that one seems to never fail.

Well how good is your C++?
Have a look at Plasma / PowerDevil · GitLab
src/libdpms · master · Plasma / libkscreen · GitLab

I am not a coder, but the closest thing I found in there so far are.

            .icon = QIcon::fromTheme("preferences-desktop-screensaver"),
            .name = i18n("Turn off screen"),
            .value = qToUnderlying(PowerDevil::PowerButtonAction::TurnOffScreen),

    case PowerDevil::PowerButtonAction::ToggleScreenOnOff:
            .icon = QIcon::fromTheme("osd-shutd-screen"),
            .name = i18n("Toggle screen on/off"),
            .value = qToUnderlying(PowerDevil::PowerButtonAction::TurnOffScreen),

Try to disconnect your mouse.

Also, under keyboars shortcuts search for “energy options” or something and you can configure a custom shortcut for turning off the screen.

The actual implementation of DPMS is in the X11 itself (Kscreen uses the XCB DPMS protocol to ask X11 to turn off the screen, which is the same thing xset dpms does) and in the kwin-wayland server (accessed using the KDE-specific DPMS protocol ).

So, to your question - what does Plasma uses to turn off the screen on X11? The answer is basically the same thing that xset dpms does, but I’m guessing the difference is that Plasma uses powerdevil to turn off a few things before it actually sets the DPMS mode.

I suggest trying to set and use the keyboard shortcut to turn off the screen - this should do 100% what the idle timer does.

Thanks @guss77

I did try the keyboard shortcut that @kenning pointed out earlier today. It does no better than running the command in the script I cobbled together. I have to do it two or three times before it sticks. It’s not a huge issue. Just an annoyance. I was hoping that I would find something that I was missing. :slightly_smiling_face:

If I didn’t play games on this PC, I would pull the nVidia card out and just move it over to Wayland like the other two I have running.

But did you try unplugging the mouse?

Sadly, no. I have not managed to talk my old butt into crawling under the desk to test it. :rofl:

OK, I just did it. No change.

There is obviously something that PowerDevil does other than just turning off the monitor. If I knew what it was, I could possibly add that to my script.