Prevent Ubuntu 16.04 Lock Screen from Dimming

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

Investigation:

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

Results:

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.

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:

From the results, some lines are interesting:

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

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:

Leave a Reply