Linux T440s lid script

April 11, 2014

I wouldn’t like to start talking about the sorry state about the Linux Power Management in laptops, because the whole situation is at least disappointing.  (Having digged the situation only a little bit, power management is done by systemd-logind, acpid, and pm-utils, and the way all these interact if you add laptop-mode is not clear at all).  I use my new T440s either as is, or as “desktop” replacement using external monitor, keyboard and mouse. In the second case when I “docked” and connected the peripherals, I didn’t want by closing the lid to activate screensaver, or suspending the system, on the other hand, whenever I was using the laptop undocked, when I closed the lid I wanted to be put in sleep mode. After having fiddled a little bit with the configuration I thought that the best way was to create the following script which I put in /etc/acpi/local/


# This script affects the way lid behaves. The logic is described
# If the laptop is connected to an external display 
#   If we have a display in the active displays that is not the built in
#       unset everything (do nothing)
# else
#	don't touch anything

#getting the outputs
for x in $d/X*; do
    if [ x$XAUTHORITY != x ]; then
       export DISPLAY=:$displaynum
       connectedOutputs=$(su $XUSER -s /bin/sh -c "xrandr" | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
       activeOutput=$(su $XUSER -s /bin/sh -c "xrandr" | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/") 
       connected=$(echo $connectedOutputs | wc -w)

#if we have one display do nothing
if [ $connected -gt 1 ]
	for display in $activeOutput
		if [ x$display != x$XRANDR_OUTPUT ] 

This scipt is called by /etc/acpi/ which in turn is called when an lid event is received which is defined in /etc/acpi/events/lidbtn


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: