9

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
  • 274

4 Answers4

15

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

9

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.

mara004
  • 274
3

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)
1

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