System doesn't detect hot-plugged display port(through thunderbolt connector)

9

4

My external display(connected to my laptop through thunderbolt) works fine if connected before boot-up. However, once it's unplugged or disconnected by any means, xrandr won't detect the reconnected monitor anymore.

I am running Arch Linux, using bumblebee for graphic card handling. External card is connected through thunderbolt connector. Could someone tell me what is wrong with the machine and how can I make hotplugging work? Thanks.


[Debugging detail]

Following multiple threads on bumblebee and udevadm, I did several testing and made a hotplug script. Yet the problem is still not solved. Result is posted as below.

For bumblebee, I didn't tweak much, since the second monitor is detect fine when not hotplugged.

For hot-plugging related issue. I did the following:

When monitor is working normally, xrandr --query returns

Screen 0: minimum 8 x 8, current 2944 x 1080, maximum 32767 x 32767
eDP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 382mm x 215mm
   1920x1080     60.02*+

...

DP1 connected 1024x768+1920+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1024x768      60.00* 

...

When unplugging monitor from DP2 with udevadm monitor --environment --udev opened, information gathered is:

UDEV  [979.022342] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
ACTION=change
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:02.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
ID_FOR_SEAT=drm-pci-0000_00_02_0
ID_PATH=pci-0000:00:02.0
ID_PATH_TAG=pci-0000_00_02_0
MAJOR=226
MINOR=0
SEQNUM=2650
SUBSYSTEM=drm
TAGS=:master-of-seat:uaccess:seat:
USEC_INITIALIZED=3775241

And when plugging the monitor in:

UDEV  [1111.426386] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
ACTION=change
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:02.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
ID_FOR_SEAT=drm-pci-0000_00_02_0
ID_PATH=pci-0000:00:02.0
ID_PATH_TAG=pci-0000_00_02_0
MAJOR=226
MINOR=0
SEQNUM=2651
SUBSYSTEM=drm
TAGS=:seat:uaccess:master-of-seat:
USEC_INITIALIZED=3775241

UDEV  [1111.522857] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
ACTION=change
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:02.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
ID_FOR_SEAT=drm-pci-0000_00_02_0
ID_PATH=pci-0000:00:02.0
ID_PATH_TAG=pci-0000_00_02_0
MAJOR=226
MINOR=0
SEQNUM=2652
SUBSYSTEM=drm
TAGS=:seat:uaccess:master-of-seat:
USEC_INITIALIZED=3775241

It seems that udev is able to detect the hardware when the monitor is plugged in, so I setted-up a udev rule to help xrandr use the new monitor. My script for /etc/udev/rules.d/95-monitor-hotplug.rules is as following:

ACTION=="change", SUBSYSTEM=="drm", RUN+="/usr/local/bin/hotplug_monitor.sh"

And /usr/local/bin/hotplug_monitor.sh is

#!/bin/sh
export XAUTHORITY=/home/chong/.Xauthority

function connectDP1(){
    DISPLAY=:0 xrandr --output DP1 --auto --right-of eDP1
}

function disconnectDP1(){
    DISPLAY=:0 xrandr --output DP1 --off
}

function connectDP2(){
    DISPLAY=:0 xrandr --output DP2 --auto --right-of eDP1
}

function disconnectDP2(){
    DISPLAY=:0 xrandr --output DP2 --off
}

xrandr | grep "DP1 connected" &> /dev/null && connectDP1 || disconnectDP1
xrandr | grep "DP2 connected" &> /dev/null && connectDP2 || disconnectDP2

The script runs and quits normally, but afterwards xrandr --query still shows DP1 and DP2 disconnected.

Chong

Posted 2015-09-08T15:07:58.687

Reputation: 496

I'm experiencing the exact same behavior. Also on Arch. I tried without bumblebee as well with the nvidia proprietary drivers with no luck. Did you try with nouveau? – Johnride – 2015-11-17T04:42:04.400

@Johnride My graphic card is Maxwell Architecture. Nouveau hasn't made it work yet. Currently I am using HDMI port and direct NVIDIA driver. It looks like they are working fine. – Chong – 2015-11-17T10:51:49.777

this will be fixed in one of the next kernels https://bugzilla.kernel.org/show_bug.cgi?id=115121

– None – 2016-04-24T22:45:54.523

Has anyone found a solution? I've got a newer kernel than the one mentioned above and I still have the same problem than Chong. I get the networks port, webcam and usb detected and working, but not the display. – dvdgc13 – 2017-08-14T14:10:19.580

#!/bin/bash (not sh) otherwise the function statement is in error – nd34567s32e – 2017-10-07T19:55:13.953

the && || statement is not the same as if then else as per https://github.com/koalaman/shellcheck/wiki/SC2015

– nd34567s32e – 2017-10-08T16:41:25.300

Answers

1

I found your code and persisted in trying to make it work. Under NO conditions could i make it work with an "if then" paradigm. the "xrandr|grep" ALWAYS failed to be true when run as udev trigger, but worked if i ran it manually. I was FORCED to break it into two scripts.

Although my device is different (StarTech CDPVGDVHDMDP), i will post my version here.

First, i found it helpful to reload udev rules when troubleshooting:

sudo udevadm control --reload-rules

My device was a little different, and i found that subsystem "hidraw" was something i could trigger off of. Also, I was forced to run /bin/bash /path/to/script"; otherwise it did not run. This is my udev rule (/etc/udev/rules.d/95-monitor-hotplug.rules):

ACTION=="remove", SUBSYSTEM=="hidraw", RUN+="/bin/bash /home/user/scripts/hotunplug-displayport.sh"
ACTION=="add", SUBSYSTEM=="hidraw", RUN+="/bin/bash /home/user/scripts/hotplug-displayport.sh"

This is my hotplug script

#!/bin/bash
export XAUTHORITY=/home/user/.Xauthority
DISPLAY=:0 /usr/bin/xrandr --addmode DP-1 1680x1050
DISPLAY=:0 /usr/bin/xrandr --output DP-1 --right-of  eDP-1 --mode 1680x1050
echo "$(date) : Hotplug Connect DP-1" >> /var/log/hotplug.txt
DISPLAY=:0 /usr/bin/xrandr --addmode DP-2 1680x1050
DISPLAY=:0 /usr/bin/xrandr --output DP-2 --right-of  eDP-1 --mode 1680x1050
echo "$(date) : Hotplug Connect DP-2" >> /var/log/hotplug.txt

This is my hot-unplug script

#!/bin/bash
export XAUTHORITY=/home/user/.Xauthority
DISPLAY=:0 /usr/bin/xrandr --output DP-1 --off
echo "$(date) : Hotplug Disconnect DP-1" >> /var/log/hotplug.txt
DISPLAY=:0 /usr/bin/xrandr --output DP-2 --off
echo "$(date) : Hotplug Disconnect DP-2" >> /var/log/hotplug.txt

nd34567s32e

Posted 2015-09-08T15:07:58.687

Reputation: 101

Since posting this, I've disabled the hotUNplug script, as it is not necessary and actually cased problems when plugging other usb devices. – nd34567s32e – 2017-11-24T21:14:45.660