-
-
Save wknapik/b4fa9ad26595a717ba2be38d26969d6a to your computer and use it in GitHub Desktop.
Lenovo Thinkpad P50, dock with external monitor, udev + xrandr auto switching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This switches between the laptop monitor ($intern) when undocked and a two monitor setup when docked ($extern right of $intern). | |
ENV{ID_VENDOR_ID}, ENV{ID_MODEL_ID}, x_user and intern need to be set. | |
Based on the Arch wiki, StackExchange and Google. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SUBSYSTEM=="usb", ACTION=="add|remove", ENV{ID_VENDOR_ID}=="17ef", ENV{ID_MODEL_ID}=="305a", RUN+="/usr/local/bin/auto_xrandr.sh dock" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
readonly ty="$1" | |
x_user=some_user | |
intern="DP-4" | |
extern="$(xrandr|grep '\bconnected\b'|grep -v "^$intern connected"|head -n1|cut -d' ' -f1)" | |
export DISPLAY=:0.0 | |
export XAUTHORITY="$(getent passwd "$x_user"|cut -d: -f6)/.Xauthority" | |
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u "$x_user")/bus" | |
sleep 2 | |
if [[ -z "$extern" ]]; then | |
xrandr --output "$extern" --off --output "$intern" --auto --panning 0x0 | |
else | |
case "$ty" in | |
dock) xrandr --output "$extern" --primary --auto --output "$intern" --left-of "$extern" --auto;; | |
*) xrandr --output "$extern" --primary --auto --output "$intern" --off;; | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment