Skip to content

Instantly share code, notes, and snippets.

@aiguofer
Last active June 16, 2020 15:41
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aiguofer/87b5ca3b53cfd8394c79 to your computer and use it in GitHub Desktop.
Save aiguofer/87b5ca3b53cfd8394c79 to your computer and use it in GitHub Desktop.
Automatic setup external monitors when docking ThinkPad T530 to ThinkPad Mini Dock
# Save this file (after modifying ID_VENDOR and ID_MODEL if necessary) as /etc/udev/rules.d/81-thinkpad-dock.rules
# These values seem to work for "ThinkPad Mini Dock Plus Series 3"
SUBSYSTEM=="usb", ACTION=="add", ENV{ID_VENDOR}=="17ef", ENV{ID_MODEL}=="100a", SYMLINK+="tp_mini_dock", TAG+="systemd"

HOWTO

In this HOWTO I will install for Fedora 23, you may need to adjust for other versions or distros. I've provided links to most sources I used so feel free to check those out for more info.

Steps

  1. Make sure you have the Nvidia card enabled in BIOS

     Go to BIOS -> Config -> Display, and select “NVidia Optimus”, and make sure to enable “Optimus OS Detection”.
    
  2. Install Bumblebee and intel-virtual-output (provided by the package intel-gpu-tools)

     sudo dnf -y --nogpgcheck install http://install.linux.ncsu.edu/pub/yum/itecs/public/bumblebee/fedora23/noarch/bumblebee-release-1.2-1.noarch.rpm
     sudo dnf -y --nogpgcheck install http://install.linux.ncsu.edu/pub/yum/itecs/public/bumblebee-nonfree/fedora23/noarch/bumblebee-nonfree-release-1.2-1.noarch.rpm
     sudo dnf install bumblebee-nvidia bbswitch-dkms primus kernel-devel
     sudo dnf install intel-gpu-tools
    
  3. Copy my xorg.conf.nvidia file to /etc/bumblebee/xorg.conf.nvidia

    sudo cp xorg.conf.nvidia /etc/bumblebee/xorg.conf.nvidia
    
  4. Reboot to make sure the drivers and modules are correctly built and loaded

  5. Test intel-virtual-output

    # Make sure your laptop is connected to dock (or directly to external monitors through DVI/DP)
    intel-virtual-output -f
    
  6. If that works, go ahead and set up automation

    sudo cp 81-thinkpad-dock.rules /etc/udev/rules.d/81-thinkpad-dock.rules
    cp docked.target ~/.local/share/systemd/user/docked.target
    cp intel-virtual-output.service ~/.local/share/systemd/user/intel-virtual-output.service
    systemctl --user enable docked.target
    systemctl --user enable intel-virtual-output.service
    
  7. (Optional) if you use RedShift and want it to work on your external monitors, set this up as well

    cp redshift-virtual.service ~/.local/share/systemd/user/redshift-virtual.service
    systemctl --user enable redshift-virtual.service
    
  8. Undock and dock again, magic should happen and it should automatically start your monitors. When you undock it should stop the service :)

Caveats

Always undock before suspending/hibernating. I've been playing around with various ways to have it stop the service before it sleeps but so far I haven't been successful. I'll update this when I have time to play with it.

I have pretty bad lag with xorg-x11-drv-intel-2.99.917-19.20151206.fc23 so I had to downgrade to version xorg-x11-drv-intel-2.99.917-16.20150729.fc23.x86_64 (I filed a bug here

Sources

# ~/.local/share/systemd/user/docked.target
[Unit]
Description=dock to ThinkPad Mini Dock
Requisite=dev-tp_mini_dock.device
BindsTo=dev-tp_mini_dock.device
After=dev-tp_mini_dock.device
JobTimeoutSec=3
[Install]
WantedBy=dev-tp_mini_dock.device
# ~/.local/share/systemd/user/intel-virtual-output.service
[Unit]
Description=intel-virtual-output for external displays
Requisite=docked.target
After=docked.target
PartOf=docked.target
Conflicts=sleep.target
Before=sleep.target
[Service]
Type=forking
ExecStart=/usr/bin/intel-virtual-output -d :0
[Install]
WantedBy=docked.target
# ~/.local/share/systemd/user/redshift-virtual.service
[Unit]
Description=RedShift for virtual displays
Requires=docked.target intel-virtual-output.service
After=docked.target intel-virtual-output.service
[Service]
Environment=DISPLAY=:8
ExecStartPre=/usr/bin/sleep 5
ExecStart=/usr/bin/redshift
[Install]
WantedBy=docked.target
# /etc/bumblebee/xorg.conf.nvidia
Section "ServerLayout"
Identifier "Layout0"
EndSection
Section "Device"
Identifier "DiscreteNvidia"
Driver "nvidia"
VendorName "NVIDIA Corporation"
EndSection
Section "ServerFlags"
Option "IgnoreABI" "1"
EndSection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment