You are not logged in.

#1 2013-04-28 20:08:51

XenGi
Member
From: berlin, germany, europe, earth
Registered: 2013-02-23
Posts: 35
Website

[SOLVED] Detect HDMI/DP disconnect and recover laptop screen

Hi,

I have a T430 and sometimes I'm using an HDMI Screen with a mDP to HDMI adapter as a secondary or the only monitor.
I would like to have a script that automatically detects when I unplug the external monitor and switches back to "internal monitor only"-mode.

How can I do this? Where can I get the event from? I don't want to have a script that checks every n secs if the external monitor is still there. An event based script would be better.

Last edited by XenGi (2013-07-19 04:00:13)


# got root?█

Offline

#2 2013-04-28 20:27:22

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [SOLVED] Detect HDMI/DP disconnect and recover laptop screen

# /etc/udev/rules.d/99-hotplug.rules
SUBSYSTEM=="drm", ACTION=="change", RUN+="/my/awesome/script.sh"
# /my/awesome/script.sh
export DISPLAY=:0
export XAUTHORITY=/home/<user>/.Xauthority

<do xrandr stuff>

I've used this with intel and nouveau, works quite well. This won't work with the binary nvidia drivers because they don't trigger a udev event. No idea about ATI.

Offline

#3 2013-04-28 21:10:04

XenGi
Member
From: berlin, germany, europe, earth
Registered: 2013-02-23
Posts: 35
Website

Re: [SOLVED] Detect HDMI/DP disconnect and recover laptop screen

I have a T430 with Intel only grafics and this doesn't work.

I've enable the HDMI out and disabled the LVDS out. Then I disconnected the HDMI cable. Nothing happens. When I reattach the HDMI cable the HDMI screen doesn't come back but my LVDS screen comes on.

So it seems to work but only if I reattach the HDMI screen. That's not the behavier I wanted. wink

Here are my scripts:

/usr/local/bin/displaymagic.sh

#!/bin/bash

export DISPLAY=:0
export XAUTHORITY=/home/xengi/.Xauthority

STATUS="`xrandr --current | grep HDMI1 | cut -d \  -f 2`"

if [[ "$STATUS" == "disconnected" ]] ; then
    # switch HDMI off and LVDS on
    xrandr --output HDMI1 --off
    xrandr --output LVDS1 --mode 1600x900 --rate 60
fi

This works great when I run it manually.

/etc/udev/rules.d/99-hotplug.rules

## enable LVDS on HDMI disconnect
KERNEL=="card0", SUBSYSTEM=="drm", ACTION=="change", RUN+="su xengi -c /usr/local/bin/displaymagic.sh"

This seems to be the tricky part.


EDIT:

I got it working! Here it is in case somebody else wants it too. Thx for your help.

https://gist.github.com/XenGi/5499771

Last edited by XenGi (2013-05-02 02:33:09)


# got root?█

Offline

Board footer

Powered by FluxBB