7

I like turning off the monitor when I don't need it, to reduce eyestrain and energy consumption (e. g. when only listening to music). On X11, I have been using the sleep 0.5; xset dpms force off shell command and assigned it a custom keyboard shortcut.

Recently, I've switched my entire workflow to Wayland, and the xset dpms commands apparently don't work on this platform - output says server does not have an extension for dpms option.

Is there an alternative method which I can use to turn off the monitor on Wayland?

mara004
  • 226
  • 1
  • 3
  • 10
  • I have found an interesting approach: In the Plasma System Settings power configuration (kcmshell5 powerdevilprofilesconfig), one can set When power button pressed to Turn off screen. I guess this sends some special signal, which might also be callable via qdbus. I have now downladed the powerdevil kcm source code and try to investigate how it works – mara004 Feb 13 '21 at 12:59
  • 1
    https://askubuntu.com/questions/979334/how-to-turn-off-the-screen-in-ubuntu-17-10 has all you need. scripts included. – Rinzwind Feb 13 '21 at 13:09
  • Thanks, but I'm on Kubuntu, so the gnome/mutter-related bus calls won't help – mara004 Feb 13 '21 at 13:13
  • My current (temporary) solution is: sleep 0.5 && qdbus org.kde.kglobalaccel /component/org_kde_powerdevil invokeShortcut "PowerOff" . That works, but only if you have powerdevil configured to turn off the screen when the power button is pressed, so it's not particularly elegant... – mara004 Feb 13 '21 at 14:48

3 Answers3

13

The accepted answer doesn't answer the question you asked, frankly.
You accepted a shortcut, but your question is - I think - mostly interpreted as looking for a command line solution.

That shorcut works, and your temporary solution in your comment under your question is almost perfect. Here is the command needed:
/bin/sleep 1 && /bin/dbus-send --session --print-reply --dest=org.kde.kglobalaccel /component/org_kde_powerdevil org.kde.kglobalaccel.Component.invokeShortcut string:'Turn Off Screen'

Basically, the difference compared to your solution:

  • don't use qdbus command as it is deprecated (good distos ship it with some qt4 tool package still, but only with them, and they do not install it by default. Nor should most people install it...)
  • you almost got the dbus method call right, but used a wrong shortcut and a hack with power button. It needed 2 minutes more in D-Bus viewer to find "Turn Off Screen" argument for invokeShortcut

And why would anyone need a command if there is a shortcut? Because some people need a command for turning off screen together with screen locking

Anyway, thank for your answer, as it helped me a lot find the solution to this, and the latter question!!!

  • On my Plasma 5.21.5 your command takes no effect, unfortunately. – mara004 May 08 '21 at 15:41
  • Ah, this works for me: sleep 0.5 && qdbus org.kde.kglobalaccel /component/org_kde_powerdevil invokeShortcut "Turn Off Screen" – mara004 May 08 '21 at 16:28
  • And, by the way, the qdbus command-line tool is not deprectaed as far as I know. – mara004 May 08 '21 at 16:32
  • 3
    Okay, I edited my answer! Funny thing, but with dbus-send you need to add --print-reply switch for it to work, but I am too tired to look up why... – Krisztián Szegi May 10 '21 at 21:26
  • 1
    This thread is now a long time ago, but I updated my answer to include possible commands. These days there is also kscreen-doctor --dpms off, which is simpler than manual dbus. – mara004 Feb 16 '24 at 22:16
6

There are multiple options:

  • kscreen-doctor --dpms off
  • sleep 0.5 && qdbus org.kde.kglobalaccel /component/org_kde_powerdevil invokeShortcut "Turn Off Screen"
  • sleep 0.5 && dbus-send --session --print-reply --dest=org.kde.kglobalaccel /component/org_kde_powerdevil org.kde.kglobalaccel.Component.invokeShortcut string:'Turn Off Screen'

Also note, there is a native KDE Keyboard Shortcut option that works with Wayland. It is located at System Settings -> Shortcuts -> Power Management -> Turn Off Screen.

mara004
  • 226
  • 1
  • 3
  • 10
0

Have a look at wlr-randr.

Something like "wlr-randr --output <device_name> --off" should work.

Should be in apt (on debian at least).

Cheers

  • Is this the code you mean? If I understand the description right, then it only works for wlroots-based compositors, and I don't think kwin is. – mara004 Mar 22 '21 at 19:14
  • 4
    Seems like wlr-randr is not the solution. I built it from the above mentioned repository and when running it, I get the following error message: compositor doesn't support wlr-output-management-unstable-v1. This probably confirms my assumption that it does not work for kwin. – mara004 Mar 22 '21 at 19:19