Our great sponsors
-
autorandr
Auto-detect the connected display hardware and load the appropriate X11 setup using xrandr
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
First setup all the display configurations, ignoring xmobar. Using something like https://github.com/phillipberndt/autorandr and https://christian.amsuess.com/tools/arandr/ make it easy. Now all you have to do is somehow invoke autorandr --change every time there's a connection or disconnection event.
Now coming to the xmobars themselves, https://github.com/xmonad/xmonad-contrib/blob/master/XMonad/Hooks/StatusBar.hs has everything you need and will only spawn and kill the requisite number of bars depending on the number of monitors connected. You can even have different bar configs per monitor (for ex: one with tray, rest without).