Scripting Monitors (Gnome & Wayland on Fedora)

On my PC (Fedora 39, Gnome Desktop Environment via Wayland) I often find myself switching monitor configuration. I have a dual-4k-screen setup, and jump between a few modes:

While not tricky, it’s a fiddly process to frequently configure monitor settings. Therefore I wanted to automate this process. Looking online, most tools and guides used old techniques which were incompatible with my current desktop environment.

Then I came across gnome-monitor-config. After compiling and testing this out, it seemed to do the job! Then I found I didn’t need to compile it myself since it’s already available in the Fedora repos under the “gnome-monitor-config” package, so I just needed a sudo dnf install gnome-monitor-config to get it installed.

Once available, I then wrote a simple bash script with my various configurations:


if [ -z "$1" ]; then
  echo "Setting monitors to default state"
  echo "================================="
  gnome-monitor-config set -LM DP-2 -m 3840x2160@59.997 -x 2192 -y 0 -t normal -s 1.7518248558044434 \
      	   -LpM DP-1 -m 3840x2160@59.997 -x 0 -y 0 -t normal -s 1.7518248558044434
  case "$1" in
      echo "Setting monitors up for gaming"
  	  echo "=============================="
  		gnome-monitor-config set -LpM DP-1 -m 3840x2160@59.997 -x 0 -y 0 -t normal -s 1
      echo "Setting monitors for recording"
      echo "=============================="
      gnome-monitor-config set -LpM DP-2 -m 3840x2160@59.997 -x 1920 -y 0 -t normal -s 1.5 \
      	   -LM DP-1 -m 3840x2160@59.997 -x 0 -y 0 -t normal -s 2
      echo "Unknown argument: $1; Valid arguments: gaming, recording (pass nothing for default)"

With this saved to a monitors executable file in my PATH, I can just run monitors gaming to configure things for gaming, monitors recording for recording, or just monitors to return things to my default setup.

Details of the syntax and options can be found in the readme of the gnome-monitor-config repo. The only thing I found fiddly was the x and y positioning. This had to be correct with monitors adjacent, which may not be obvious to work out when scaling is involved. To get correct figures, I found I could configure my monitors as normal via gnome settings, then read my ~/.config/monitors.xml file to understand the values gnome uses and accepts.

This has seemed to work pretty well so far. I sometimes see some rendering noise/artifacts after switching, but not always and it goes away in seconds.