I don't know such software but here's a quick script that does the logical counterpart of iptables -S
, that is generate commands that result in current config:
#!/bin/bash
# Emit current X configuration as xrandr commands (similar to iptables -S)
# (does not currently support custom modelines or axis or panning)
# Copyright 2003 Mikko Rantalainen <mikko.rantalainen@iki.fi>
# License: MIT
function create_flags()
{
port="$1"
shift
status="$1"
shift
if [ "$status" = "disconnected" ]; then
printf "%s" "--output '$port' --off"
return
fi
if [ "$status" != "connected" ]; then
echo "Error: port=$port: unknown status=$status" 1>&2
exit 1
fi
PRIMARY=""
if [ "$1" = "primary" ]; then
PRIMARY="yes"
shift
fi
mode="$1"
shift
printf "%s\n" "$mode" | sed 's/+/ /; s/+/x/' | while read mode position
do
printf "%s" "--output '$port' --mode '$mode' --pos '$position'"
done
if [ "$PRIMARY" = "yes" ]; then
printf "%s" " --primary"
fi
rotation="$1"
if [ "$rotation" = "left" ]; then
printf " --rotation left"
shift
elif [ "$rotation" = "right" ]; then
printf " --rotation right"
shift
elif [ "$rotation" = "inverted" ]; then
printf " --rotation inverted"
shift
fi
return
}
printf "xrandr"
LC_ALL=C xrandr -q | grep connected | while read line
do
test "$1" = "--debug" && printf "\nProcessing line [%s]\n" "$line" 1>&2
printf " %s" "$(create_flags $line)"
done
printf "\n"
Save that as a text file, give it executable bit and run it to emit the current X screen configuration as xrandr
command. Pass a command line argument --debug
to show how each line is interpreted.
I wish xrandr -S
emitted this by default. Parsing textual output is always error-prone if the output is not designed to be parsed in the future, too. This doesn't try to preserve the selected refresh rate because output syntax of the query is that problematic. Instead, the xrandr
will default to highest supported refresh rate for each GPU and monitor combination.
Note that connector / output names may change so the emitted commands cannot be used if xrandr
renames the outputs after reboot. See https://www.baeldung.com/linux/primary-monitor-x-wayland for details.
autorandr
handle thexrandr
orarandr
details behind the scenes for you. Example here: https://askubuntu.com/a/1130337/8 It's much simpler, just be sure to disable/remove the prior solutions so they don't clash with each other. – mechanical_meat Nov 21 '21 at 21:23