0

How to prevent screen blanking when on AC?

Corollary:

Do screen blanking (as configured) only when on Battery power.

Means:

I do not need a different screen blanking setting between AC and Battery. All I need is an automatically disabled screen blanking when on AC and automatically enabled screen blanking when on Battery.


What I already did

I already searched AskUbuntu but found no valid answer:

Set different blank screen timeouts when on battery or ac

  • The question is about different blank screen timeouts. I do not ask of different timeouts. I ask for blank screen being not active on AC at all. No timeout here wanted!
  • The first and accepted answer is plain wrong. As noted in the comments, this configures suspend times, not the screen blanker.
  • The second answer is wrong as well. It certainly is possible to change the configuration of the screen blanker in Gnome/etc. depending on the AC-setting. That there is no such function built in ready to use yet does not qualify for "it`s not possible".
  • Again to stress: This answer could, perhaps, answer my question, too. But my question is entirely different, so if ever a solution shows up there, this would only accidentally cover my question, by chance.

Use blank screensaver when on battery power

  • This asks for a different screen blanking method on battery power. I do not ask for something like that. My question is how to not do screen blanking at all when on AC. When on battery power, the screen blanking should happen as configured, of course!
  • This question has no answer at all.

Details I need

So what I need are scripts/hacks (whatever) which do following:

  • When on battery, screen blanking is switched on
    • So normal configured screen blanking happens
  • When on AC, screen blanking is just switched off
    • So normal configured screen blanking does not happen at all

The pieces I am unable to solve (because I really have no idea where to look for the answers) are:

  • Commands (from the commandline) to switch screen blanking on and off.
    • Reliably.
    • For all screens and X11 severs or Waylands etc. running on the machine.
    • For all users.
    • For all (standard) desktop types (KDE, Gnome, XFCE, LXDE).
  • A hook (script, whatever) which detects when the machine changes AC/Battery status.
    • This hook must not use polling. So no CPU use as long as the system stays in the same power mode.
    • Reliably
    • Even when the power input changes multiple per second for some period of time (Brownouts)
    • So the last reported state must not differ from the real (and then stable) state

I know how to hack the kernel. I know how to use sbuild and create Debian Packages. I know C better than my native language (which is not English, I think you guessed that). But I really have no idea, not even the slightest clue, how things nowadays work in the presence of SystemD and current Desktop frameworks. I even do not have the slightest idea where to start looking for this. As I am not into Desktops and frontends, I am just the middleware, backend and hardware Guy (with the exception of postmodern things like SystemD. This might change in the 2030s, but today for me things change dramatically too fast in that area, such that I am unable to keep up. Read: I am a bit too old for that now).

But ..

.. with these 2 bits above (a hook and the magic how to dis/enable blanking on the various Desktops) I am certainly able to create my own solution. Something, I would expect to already be present in Ubuntu today, ready for use for all, because, AFAICS, we already have the year 2022.

Historic note: One of my first portable Computers from 1989 running under DOS had this property I ask for. The BIOS was able to blank the screen (it actually cut the power to the entire display) when on battery power, to extend battery life (factor 2 and above)! But it would be cheating to say, those old days already offered that feature: For the BIOS to detect activity, you needed to read input via the BIOS. Most DOS did that. But graphical applications like Games usually did not .. Hence the BIOS only offered screen blanking for battery state to not disturb AC state ..


What I want to archive

My goal is do leave machines alone for themselves. Many of them. When I come over to look at their displays, I expect that their screens are up and running and have the right content and not blanked or black displays. As "blank" means "wrong state", "defect", "death" or even worse.

However if power drops or something other fails (for example I declutter all those knots in the power cables to the machines and forget to plug one in) the machine (the one without power) shall blank the screen (after 15 to 30 minutes) and then, if I do not take this as a hint something is going wrong currently (read: Even Admins do sleep from time to time), it shall suspend until I am back on duty again and recognize the off state of the screen.

OTOH when I fix the problem (plug in the forgotten power cord) the screen blanking should immediately vanish (so I can see that I found the right one in the haystack). Oh yes, you do not see that bit in my "needs" above. Because that is a very unique thing at my side. So I do not ask that the solution should cover that, too. Yet. Because I hope, that, with the hints how to dis/enable blanking, I manage to find out myself where to look to get this done.

I only note this, because this section is about what I want to archive, not what I dare to ask.


Thanks for any clues on how to allow screen blanking only when on battery.

BTW I only need a solution for Ubuntu 22.04

Tino
  • 720
  • 1
  • 7
  • 16

1 Answers1

0

Ok, one of those actually did contain the answer you need. So this is how:

Get available options for AC Inactive:

gsettings range org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type

This should be something like:

enum
'blank'
'suspend'
'shutdown'
'hibernate'
'interactive'
'nothing'
'logout'

So, for AC you want to set that up as 'nothing'.

That means, on inactive timeout, nothing will happen.

Issue the command to check if it is writable:

gsettings writable org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type

Then, set it to nothing. Note that your system should support this configuration for it to work (see the output of range for allowed values)

gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type nothing

Next set the type for battery power to be blank and set a timeout.

gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type blank

gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-timeout 1200

For KDE, it is much, much simpler:

Goto System Settings -> Power Management -> Energy Saving

It has three tabs: AC Power, On Battery, On Low Battery

For each you can choose: Screen Energy Saving (it is a chek box, you can enable disable it)

KDE Power Management (Energy Savings

Personally, I favour KDE, it works perfectly, and is easy to check if settings are set or not.

sotirov
  • 3,169