1

I added an external monitor to my laptop last week and have almost everything working like I want except for the Brightness & Lock behavior.

I've long had this set to "Turn screen off when inactive for: 5 minutes" and it works like a charm for the laptop screen - both before and after the addition of the external monitor. But it doesn't work on the external monitor. When I'm away from my desk for longer than I intended, I come back to a black laptop screen and the locked screen and login input on the external monitor.

The issue seems similar to this question, but in that one it appears that it's the primary monitor not going black. Which is why I'm posting this as a separate question.

Yes, I know I can turn the monitor's power off, and I do at night, but I'd like it to go black in synch with the native screen if possible.

I'm on 14.04. The monitor is connected via HDMI. The laptop is a VAIO with a little age on it now.

FOLLOW-UP EDIT

As a follow-up, when I tested the bash script in the accepted answer, I set a low timeout, ran the script from a terminal, watched both monitors dim to black, and then accepted the answer. Subsequently, I actually added the script (with a re-set timeout) to my startup scripts and bounced my machine.

After my first longer-than-expected absence, imagine my surprise when I came back to my desk to find my external monitor shining brightly!

Subsequent research has shown that this is likely caused by the HDMI monitor itself, and no script is going to fix it. Indeed, I've (accidentally) been at my desk when this script kicked in. Both monitors go black as they should, and then about a minute later, the external monitor turns itself back on. :-(

Oh well. I tried.

  • Not sure what the cause is, but there are several solutions; we could "synchronize" both screens; if the main screens is turned of, the second will too (within a few seconds) or we could replace the "native" option with our own idle- script. In both cases, a minor (practically not consuming any resources) background script would be involved. would that bother you? – Jacob Vlijm Apr 12 '16 at 17:27
  • I could live with that @JacobVlijm if there's not a way to make it happen 'automatically' via a settings tweak – G. Ann - SonarSource Team Apr 12 '16 at 17:30
  • Hi G.Ann, did you notice the answer? Please let me know if it works. – Jacob Vlijm Apr 14 '16 at 4:43
  • I did. I haven't had a chance to try it yet, but that should happen before Monday. – G. Ann - SonarSource Team Apr 14 '16 at 11:22
2

I suspect the issue is the result of a bug, since I cannot find another cause. At least as a workaround the background script below could be used.

The script does the job on my system, but you'll have to try and see. If it doesn't work on your system, we can switch to xrandr to specifically switch of per monitor, but this is the simplest option.

Resources?

About resources you don't have to worry, the script checks once per ten seconds if the idle time is exceeded. Even if I make it 10 times per second, the load is practically none.

#!/usr/bin/env python3
import subprocess
import time

t = 300

scr = True
while True:
    time.sleep(10)
    idle = int(subprocess.check_output("xprintidle").decode("utf-8").strip())/1000
    if idle > t and scr == True:
        subprocess.Popen(["xset", "dpms", "force", "off"])
        scr = False
    elif idle < t and scr == False:
        subprocess.Popen(["xset", "dpms", "force", "on"])
        scr = True

How to use

  1. The script needs xprintidle:

    sudo apt-get install xprintidle
    
  2. Copy the script into an empty file, save it as switchoff.py

  3. In the head of the script, set the idle time (in seconds) in the line:

    t = 300
    
  4. Switch off your "normal" switch-off-screen-after-x idletime -settings

  5. Run the script with the command:

    python3 /path/to/switchoff.py
    
  6. If all works fine, add it to Startup Applications: Dash > Startup Applications > Add.

    Add the command:

    /bin/bash -c "sleep 15 &&  python3 /path/to/switchoff.py"
    

EDIT

As requested in a comment, below the bash version of the same script. You'd still need to install xprintidle though.

#!/bin/bash

# --- set the idle time in seconds below
let "t = 300"
# ---

let "div = 1000"
t=$(($t * $div))
scr=true

while true
do
  sleep 10
  let "idle = "$(xprintidle)""
  if  [ "$idle" -gt "$t" ] && [ "$scr" = true ] 
  then
    scr=false
    xset dpms force off
  elif [ "$idle" -lt "$t" ] && [ "$scr" = false ] 
  then
    xset dpms force on
    scr=true
  fi
done

Note

  • Since we don't know what causes the behaviour on your system, we still need to find out if it is necessary to specifically switch off your screens per screen by xrandr. You'd have to try.
  • I've just realized I don't have Python installed, and I'd rather not add it. This is my work machine and I've had trouble with scripting language installs in the past. If you're feeling generous enough to give me a bash version I'll be very grateful. If not, I'll accept anyway; it's not your fault I'm chicken-livered. – G. Ann - SonarSource Team Apr 15 '16 at 20:37
  • @G.Ann-SonarSourceTeam I can't imagine you don't have python installed, since 14.04 is not working without. Does python3 --version have an output? – Jacob Vlijm Apr 15 '16 at 20:43
  • Sorry. That's coming. I step away from my machine Friday p.m. & do my best not to come back until Monday :-) – G. Ann - SonarSource Team Apr 18 '16 at 11:26
  • This worked beautifully, but the results made me wonder if not turning off the external monitor was on purpose: on wake, it took a couple of seconds to re-establish the data connection. But I'm happy to wait those couple of seconds. Thanks very much!! – G. Ann - SonarSource Team Apr 18 '16 at 18:53
  • @G.Ann-SonarSourceTeam Ah, I am very happy it works :) – Jacob Vlijm Apr 18 '16 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.