Dynamic multimonitor setup question

From: Milan Obuch <freebsd-x11_at_dino.sk>
Date: Mon, 28 Feb 2022 08:39:51 UTC
Hi,

for some time I am using various PCs with multiple video outputs,
either Intel or AMD built-in graphics (i915kms or radeonkms). It is
quite common for such setup presenting more video outputs, which allows
more displays to be connected.

For some time, I am using some manually started scripts to modify the
setup, kind of

--- 8< -----------------------------------------------------------------

#! /bin/sh

xrandr --output DVI-D-1 --auto
xrandr --output VGA-1 --auto
xrandr --output VGA-1 --left-of DVI-D-1

--- 8< -----------------------------------------------------------------

to activate monitors to be used independently as larger working area.
If such setup is static box, not moved, everything is OK, no need to
make any change later.

Recently, I've got a GPD's MicroPC for mobile usage, which changes the
play. There is internal display with resolution 720x1280 (this needs
rotation right in order to be used normally, not breaking one's neck
and having usual corelation mouse to screen), with HDMI output
available to attach a monitor, possible larger (up to 4K works well,
tested).

I can manually switch the second display on, set resolution as required
(using --auto is the simplest way), start some program and use it on
additional monitor etc. What I'd like to achieve is some dynamic setup,
ideally ability to launch some script when monitor is detected on HDMI
output (connect/disconnect event).

Has anybody some hints for me? As all notebooks and similar devices
probably have additional video output, this functionality is, I think,
really desired.

Regards,
Milan