Skip to content

Instantly share code, notes, and snippets.

@bakoushin
Last active May 30, 2023 02:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakoushin/5420084a7581f818073c3955bb79d3c0 to your computer and use it in GitHub Desktop.
Save bakoushin/5420084a7581f818073c3955bb79d3c0 to your computer and use it in GitHub Desktop.
Lubuntu 18.04 external HDMI display hotplug
ACTION=="change", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/USER/.Xauthority", RUN+="/bin/bash /home/USER/bin/monitorhotplug.sh"

Lubuntu 18.04 external display hotplug

When external HDMI display is connected, the internal display is automatically turned of. Suspending on lid close is turned off as well, so you can close laptop and continue to work.

When external display is disconnected, the internal display is turned back on, and suspending on lid close is restored as well.

Check if hotplug works

First of all make sure that plugging external display provides udev event.

Run udevadm monitor. You should see some events logged when you plug in and plug out external display.

If so, your machine is ready for hotplug config.

Create config

  1. Create file /etc/udev/rules.d/90-monitor-hotplug.rules with content provided here.

Notice that <USER> should be substituted with actual user's name.

  1. Create file ~/bin/monitorhotplug.sh with content provided here.
  2. Make monitorplug.sh exectutable: chmod +x monitorplug.sh
#!/bin/bash
# if a HDMI monitor is plugged in:
if [ $(cat /sys/class/drm/card0/card0-HDMI-A-1/status) = "connected" ]; then
# set power settings
# 1 for suspend, 0 for do nothing
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/lid-action-on-ac -s 0
# init xrandr, otherwise it won't work
xrandr > /dev/null
# turn on external screen and turn off laptop screen
xrandr --output LVDS-1 --off
xrandr --output HDMI-1 --auto
# in case of anything else reset to standard options
else
# reset power settings
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/lid-action-on-ac -s 1
# init xrandr, otherwise it won't work
xrandr > /dev/null
# restore laptop screen and turn off external screen
xrandr --output LVDS-1 --auto
xrandr --output HDMI-1 --off
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment