Prevent Ubuntu 16.04 Lock Screen from Dimming

It annoys me that Ubuntu always dims and goes to blank screen whenever I lock my screen. To prevent this, I have written a script and now share it with all my readers.

Solution:

Copy the following line to install the script (on Github Gist).

wget -O - https://gist.githubusercontent.com/yuan3y/a4effdc88bf5f13654cace493bc3a3aa/raw/92f8db4d32efa17b4495021b8dbbf13a7c8adccb/install_prevent_lock_screen_dim.sh | bash

Investigation:

Following advice from jippie’s answer for What is the screen locking mechanism under KDE? on Ask Ubuntu, we run the following command:

diff <( ps -ef ) <( dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock; sleep 1; ps -ef )

Results:

248d247
< yuan 8831 8129 0 16:14 pts/4 00:00:00 bash
250d248
< yuan 8833 8831 0 16:14 pts/4 00:00:00 ps -ef 251a250,251 > yuan 8838 1508 6 16:14 ? 00:00:00 /usr/lib/x86_64-linux-gnu/unity/unity-panel-service --lockscreen-mode
> yuan 8843 8832 0 16:15 pts/4 00:00:00 ps -ef

This tells us that the locksreen-mode is triggered with unity-panel-service. But there is nothing interesting as the service only loads the indicators for the lock screen.

As changing screensaver or removing it altogether does not alter the behaviour of screen dimming for the first ten seconds after locking the desktop, I suspect that the screensaver itself may not be running during immediately after the screen is locked. We continue to poke around with the dbus-send method calls. Understood from question on Ask Ubuntu, gnome-screensaver-command  is a command that can be helpful for controlling the GNOME screensaver, we look at its man page for clues: -q, --query  Query the state of the screensaver . Therefore we examine the different states of the screensaver with the following commands.

$ dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock; sleep 1; gnome-screensaver-command -q
The screensaver is inactive
$ dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock; sleep 15; gnome-screensaver-command -q
The screensaver is active

From here, we verify that indeed the screensaver doesn’t start immediately.

Inspired with green’s Answer to Bash script to start ‘motion’ on screen lock on Ask Ubuntu and Luv Agarwal’s Answer to Run script on screen lock/unlock on Unix & Linux Stack Exchange, we try to continue our investigation with the following command:

dbus-monitor --session

From the results, some lines are interesting:

signal time=1493379618.139190 sender=:1.0 -> destination=(null destination) serial=1563 path=/com/ubuntu/Upstart; interface=com.ubuntu.Upstart0_6; member=EventEmitted
string "starting"
array [
string "JOB=unity-panel-service-lockscreen"
string "INSTANCE="
]

signal time=1493379618.139651 sender=:1.0 -> destination=(null destination) serial=1567 path=/com/ubuntu/Upstart; interface=com.ubuntu.Upstart0_6; member=EventEmitted
string "desktop-lock"
array [
]
signal time=1493379618.140188 sender=:1.0 -> destination=(null destination) serial=1568 path=/com/ubuntu/Upstart; interface=com.ubuntu.Upstart0_6; member=EventEmitted
string "started"
array [
string "JOB=unity-panel-service-lockscreen"
string "INSTANCE="
]

With these, we try to issue keyboard/mouse events with xdotool.

dbus-monitor --session "type='signal',interface='com.ubuntu.Upstart0_6'" |
while read x; do
  case "$x" in
    *"started"*) sleep 1; xdotool key "Escape";;
  esac
done

This indeed achieve our goal of stopping the dimming. Interestingly, clicking alone (xdotool click 1;;) without moving the mouse would not cancel away the dimming process once screen lock started.

With some polishing, the full working code with installation script is published on Github Gist:

4 Replies to “Prevent Ubuntu 16.04 Lock Screen from Dimming”

  1. Thank you for this great solution:
    I have been searching just a while to deactivate this annoying dimming.
    I hope, that it is okay, that I just linked your Blog Entry on my blog?

    Following your instructions may lead to an error, as – if xdotool is not installed – it leads to the following output:

    Checking xdotool exists: FAILED
    Please answer yes or no.
    […] repeated 20 times […]
    Please answer yes or no.

    Downloading the script and then executing it avoids this output – as well as installing xdotool first.

    Greetings,

    Manuel

    1. Hi Manuel,
      Pleasure and please feel free to link it on your blog.

      Yes, xdotool would be necessary for this solution to work.

Leave a Reply