0

Use case / Problem

I wanna hear music in the night with my laptop/device and as such I want the screen to be black, as I don't want to get dazzled in the night.

Tried workarounds/“solutions”

As such, …:

  • I cannot put it into standby for obvious reasons (music playing stops)
  • I cannot close the lit without going into standby (I know I can adjust this in gnome-tweaks, but really… I don't wanna disable and re-enable this each time I want to do this, because I usually want to keep the default and very sensible behavior of getting into standby when the lid is closed)
  • I could try any physical solutions to the problem, like closing the lid partially, wearing sunclasses or eye masks or placing the device facing me away or even putting some light-blocking object between me and the device.
    However, this would cause other downsides like needing to reverse the workaround when you want to pause the music or skip a track or so (access to keyboard could be limited in these scenarios). Also, it's really inconvenient. (but closing the lid is e.g. sth. I instinctively do as a workaround, and it's not perfect due to the light reflection.)
  • One solution that partially works, even though it may not be obvious at first, is: Lock your screen! This does not only prevent from cat pictures (or similar) appearing on your screen, but also actually fade the window to black in recent GNOME versions. The problems with this solution/approach are:
    • Any keypress will wake the screen up, even if it is just the keyboard button for pausing music or skipping a track.
    • Worse, any notification will wake your screen up. (Again I could circumvent this by enabling “Do not disturb” mode, but really, do I want to do that just for that? Again very inconvenient.)
    • Also, there may the inevitable “This system will go to standby soon” notification (at least in GNOME 41), which will wake-up your screen,
    • Now, worst though, after your screen woke up once and you are now at the login/lock screen, if you wait the screen will not turn black again automatically. The only workaround I found for this is logging in and, yet again, re-locking it. Do I need to say another time this usability s………eems to be not the best?

An “old” solution I had was one:

  • Another laptop I used had a special Fn button, which would just turn the whole screen black. It looked as if it was not a hardware thing, but somehow GNOME really interpreted that key correctly.

Now, I desperately miss that key or that feature in general.

Solution wanted

I want to have a keyboard shortcut/hotkey or something equally easily accessible that just turns the screen black. Pitch black, so I am not dazzled. It, thought, must not turn the device into standby. (Music players usually have a lock on that, so GNOME won't do that by default anyway, but one could always trigger standby manually of course.)

How can I do that?

System

GNOME 42.1
Fedora 36 (Silverblue)


Cross-posed to Fedora Ask. Feel free to submit your answer there, too, if you have one.

1
  • With Xorg you cannot do this via the commandline: 'sleep 1; xset s activate', but you would need to map it to a hot key, not sure about that off hand.
    – jrdnjhntsn
    Commented May 16, 2022 at 1:59

2 Answers 2

1

I'm using brightnessctl to handle screen brightness, maybe you could trigger custom settings with keyboard shortcuts?

Installation:

sudo apt install brightnessctl

Usage:

brightnessctl set 10%
1
  • I have disabled completely all suspend functionality altogether, which is why screen won't go black anymore on lid closed. This is simple and elegant (also only) solution for me. Commented Jan 1 at 9:43
1

As mentioned before, you can use command line tool brightnessctl to manage the backlights of your built-in screen. Please visit the github page for installation and usage on your specific distribution (it is available with sudo dnf install brightnessctl in Fedora).

Before trying to turn off your screen, make sure to have a method to turn it back on. You can achieve this with the built-in brightness FN keys of your laptop or you can also try to blind type in your terminal to modify the last command (for example UP then BACKSPACE then type 10%).

Then you might try the command brightnessctl s 0 in a terminal to see if your screen backlights turn off. Depending on your distribution or hardware, it could not work (with my LED screen controlled with intel_backlight, it works well on Fedora 39 with Gnome 45, but not on Ubuntu 22.04 in which I can not set the brightness lower than a certain value).

If it works, you can write a bash script to toogle the behaviour and assign a keyboard shortcut to it in the Gnome parameters. You can try the following script which uses a temporary file to store the last brightness before turning off the screen, and recover the value when turning it back on.

#!/bin/bash
brightness=$(brightnessctl g)
if [ $brightness -ne 0 ]; then 
    # if brightness value not 0, store the value in file then turn off screen
    echo "$brightness" > "$(pwd)/.last-brightness"
    brightnessctl s 0
else
    # if brightness value is 0, try to catch the last brightness value from file
    # or set to 20% if no file
    brightnessctl s $(cat $(pwd)/.last-brightness) || brightnessctl s 20%   
fi

To assign the script to a shortcut command, make it executable with chmod -x, go to Gnome keyboard parameters, custom shortcuts, create a new shortcut with the name of your choice, the command path-to-your-script (you might need to provide a full path here) and the shortcut you like.

You must log in to answer this question.

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