0

I want to turn off the screen after 10 minutes of inactivity, and 1 minute later, IF the monitor is still off, then lock the screen.

I know how to turn the screen off with dbus, how to lock screen, and how to get the screensaver state (i.e., if the screen is locked). But I do not know how to get the current monitor state ON/OFF.

So I want for KDE to trigger this script after 10 minutes of inactivity:

#!/bin/bash
sleep 1
dbus-send --session --print-reply --dest=org.kde.kglobalaccel /component/org_kde_powerdevil org.kde.kglobalaccel.Component.invokeShortcut string:'Turn Off Screen'
sleep 60
[[ <IS MONITOR OFF?> ]] && dbus-send --session --print-reply --dest=org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.Lock

So how to query for monitor state (preferably with dbus), namely, the <IS MONITOR OFF?> condition in the above script?

I used to do xset -q | grep -i 'monitor is off', but now I get an error: Server does not have the DPMS Extension.

3
  • Running a Wayland session? Well, enjoy it: gitlab.freedesktop.org/wayland/wayland/-/issues/233 Commented Jul 23, 2024 at 8:40
  • Oh boy, what a mess! I think I will go back to x11 until Wayland matures - around 2045. Commented Jul 23, 2024 at 11:36
  • 2045 sounds about right for Wayland. Commented Jul 23, 2024 at 12:32

2 Answers 2

0

The utility ddcutil is mentioned on kde.org as being used by kde. It talks to a monitor via its I2C channel (which is used to get the EDID Extended display identification data, for example).

Use sudo ddcutil detect to go through the /dev/i2c-* devices to find which bus your monitor is on, eg /dev/i2c-7.

You can then use ddcutil vcpinfo --verbose to list the known VCP codes, and in particular code D6:

 VCP code D6: Power mode
   DPM and DPMS status
   MCCS versions: 2.0, 2.1, 3.0, 2.2
   MCCS specification groups: Control, Miscellaneous
   ddcutil feature subsets: 
   Attributes: Read Write, Non-Continuous (simple)
   Simple NC values:
      0x01: DPM: On,  DPMS: Off
      0x02: DPM: Off, DPMS: Standby
      0x03: DPM: Off, DPMS: Suspend
      0x04: DPM: Off, DPMS: Off
      0x05: Write only value to turn off display

You can then try to read this value from the monitor, and interpret it to see what state it is currently in.

sudo ddcutil --bus 7 getvcp 0xd6`

If it times out with Maximum retries exceeded, then that code is not implemented.

1
  • Of course!! How I did not think about this... :)) Anyway, it seems it does not work: the following command gives "On" even when "Off" for 20 seconds, and then stops with an error: Error opening Display_Ref[bus /dev/i2c-5]: DDCRC_DISCONNECTED: while ( true ); do sleep 1 ; ddcutil --bus 5 getvcp 0xd6 | grep -oP '(?<=DPM: )O[^ ,]*' ; done Commented Oct 26, 2024 at 17:39
0

2025-01-10 update: kscreen-doctor will have (I believe in Plasma 6.3) an option to show DPMS state; see usage documentation here: https://invent.kde.org/plasma/libkscreen/-/commit/a641ee4ad28bd8574475d417f1b565dd51fb0c3b

Bug is here: https://bugs.kde.org/show_bug.cgi?id=495499

1
  • Thanks! I will try it when installed. Commented Jan 10 at 19:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.