Here's an extremely simple solution, just bind this to a shortcut:
#!/bin/bash
if [[ -z "${MONITOR}" || "${MONITOR}" == "internal" ]]; then
export MONITOR="external"
~/dotfiles/xrandr/external.sh
else
export MONITOR="internal"
~/dotfiles/xrandr/internal.sh
fi
and just autostart internal.sh
I'd most likely keep it like that and go on with my day, but here's an ai response for automating it:
To trigger a script when an external monitor is connected or disconnected, you can use udev, the device manager for the Linux kernel.
Here's a step-by-step plan:
Create a script that will be triggered when the monitor is connected or disconnected. For example, /usr/local/bin/monitor-hotplug.sh. Make sure to make it executable with chmod +x /usr/local/bin/monitor-hotplug.sh.
#!/bin/bash
export DISPLAY=:0
export XAUTHORITY=/home/username/.Xauthority # replace "username" with your actual username
xrandr | grep "HDMI1 connected" # replace "HDMI1" with your actual monitor identifier
if [ $? -eq 0 ]; then
# commands to run when the monitor is connected
else
# commands to run when the monitor is disconnected
fi
Create a udev rule that will trigger the script. For example, /etc/udev/rules.d/95-monitor-hotplug.rules.
Now, whenever an external monitor is connected or disconnected, the monitor-hotplug.sh script will be triggered.
Please note that you'll need to replace "HDMI1" with your actual monitor identifier, which you can find by running xrandr without any arguments. Also, replace "username" with your actual username.
And here's an example of using modes in i3 if you need to switch between multiple configurations:
set $mode_system System (k) lock, (l) logout, (u) suspend, (h) hibernate, (r) reboot, (s) shutdown
mode "$mode_system" {
bindsym k exec --no-startup-id ~/dotfiles/.config/i3/scripts/i3exit.sh lock, mode "default"
bindsym l exec --no-startup-id ~/dotfiles/.config/i3/scripts/i3exit.sh logout, mode "default"
bindsym u exec --no-startup-id ~/dotfiles/.config/i3/scripts/i3exit.sh suspend, mode "default"
bindsym h exec --no-startup-id ~/dotfiles/.config/i3/scripts/i3exit.sh hibernate, mode "default"
bindsym r exec --no-startup-id ~/dotfiles/.config/i3/scripts/i3exit.sh reboot, mode "default"
bindsym s exec --no-startup-id ~/dotfiles/.config/i3/scripts/i3exit.sh shutdown, mode "default"
# back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym control+mod1+X mode "$mode_system"
Doesn’t xfce use a dm?
Display manager?
A gui for manually configuring the layout or something more?
Basic stuff you'd expect, and it has a quick switch keybinding to go between a few basic configurations.