8

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?

5
  • 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
    Commented Feb 13, 2021 at 12:59
  • 1
    askubuntu.com/questions/979334/… has all you need. scripts included.
    – Rinzwind
    Commented Feb 13, 2021 at 13:09
  • Thanks, but I'm on Kubuntu, so the gnome/mutter-related bus calls won't help
    – mara004
    Commented Feb 13, 2021 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
    Commented Feb 13, 2021 at 14:48
  • None of these answers helped, so I created a universal utility! Gnome-Wayland, KDE-Wayland, and Xorg! Commented Aug 12, 2024 at 13:44

4 Answers 4

14

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!!!

5
  • On my Plasma 5.21.5 your command takes no effect, unfortunately.
    – mara004
    Commented May 8, 2021 at 15:41
  • Ah, this works for me: sleep 0.5 && qdbus org.kde.kglobalaccel /component/org_kde_powerdevil invokeShortcut "Turn Off Screen"
    – mara004
    Commented May 8, 2021 at 16:28
  • And, by the way, the qdbus command-line tool is not deprectaed as far as I know.
    – mara004
    Commented May 8, 2021 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... Commented May 10, 2021 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
    Commented Feb 16, 2024 at 22:16
8

There are multiple options:

  • kscreen-doctor --dpms off (note: Wayland only – does not work on X11)
  • 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.

4
  • 1
    kscreen-doctor works for me. Neither of your other two work for me. I implemented it in my turn-off-monitors program. Commented Aug 12, 2024 at 13:44
  • @TheodoreR.Smith Strange, is there any error message with the other two commands? Regarding qdbus, it may be called qdbus-qt5 (or -qt6) on some distributions, and you might have to install it first. FWIW, this works on my Fedora 37 device. What distro / version of KDE Plasma are you on?
    – mara004
    Commented Aug 12, 2024 at 14:49
  • dbus-send didn’t work because I don’t have kscreensaver installed. Can’t remember why qdbus didn’t work. Commented Aug 24, 2024 at 3:27
  • What kscreensaver do you mean? Can you give a link or something? Neither Debian nor Fedora provide such a package.
    – mara004
    Commented Aug 24, 2024 at 14:11
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

2
  • 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
    Commented Mar 22, 2021 at 19:14
  • 5
    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
    Commented Mar 22, 2021 at 19:19
0

For days, weeks, I scoured the Internet for a solution on how to turn off monitors in Wayland via the command line.

Nothing was found. It was a very hard problem. Many people asking for it, no readily-found solutions.

So I created one!

turn-off-monitors is a nearly-universal Linux command line utility to turn off your computer’s monitors from the CLI.

Tested in:

  • Arch Linux 2024-08-12 (xorg (gnome + kde + xfce + cinnamon + gnome classic + mate), gnome-wayland, gnome-classic-wayland, kde-wayland)
  • RHEL 8.8 (gnome-wayland)
  • Ubuntu 22.04 (xorg (gnome + kde), gnome-wayland, kde-wayland)
  • EndeavourOS (xorg (kde), kde-wayland)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .