How switch monitor configuration with a bash script (Gnome and wayland)

Hi,
My workstation consists of two monitors, the main one of the laptop and an external monitor that can be rotated vertically. I would like to create a script to be able to quickly change the configuration of the monitors. The two configurations I need are: secondary monitor above the main one (both horizontally)

and secondary monitor in vertical (right) to the right of the main monitor.

I tried with xrandr and with the file ~/.config/monitors.xml, but I did not find anything that works. I need to be able to change the configuration “live”, without terminating the session or rebooting.
Is there a way to modify (or load it from a saved one) the configuration from a script?

I’m using two 1920x1080 monitors, Gnome 47.2 on Wayland, kernel 6.12.9-zen1-1-zen

Thanks

Hi @simdll ,
What I’ve tested in Gnome 47.2 Mutter (Wayland):
yay -S gnome-monitor-config-git
then check

gnome-monitor-config list

and modify accordingly my toggle script
cat tm.sh

#!/bin/sh
# This shell script is PUBLIC DOMAIN. You may do whatever you want with it.

TOGGLE=$HOME/.toggle

if [ ! -e $TOGGLE ]; then
    touch $TOGGLE
    gnome-monitor-config set -LM HDMI-1 -t normal -m 1920x1080@60.000 -LpM eDP-1 -m 1920x1080@60.008 -x 0 -y 1080 -t normal
else
    rm $TOGGLE
    gnome-monitor-config set -LM HDMI-1 -m 1920x1080@60.000 -x 1920 -t left -LpM eDP-1 -m 1920x1080@60.008 -x 0 -y 0 -t normal
fi

The device names may vary and the refresh rate should be copied exactly from the
[id: ‘1920x1080@60.008’] sections of gnome-monitor-config list
Shortcut I used Super+M assigned to the script above. Refine it.

1 Like

Thank you @eso your solution work perfectly for me. Now with the custom command toggle extension I can switch the two option in one second.
For reference this is the script that I’m using:

#!/bin/bash

usage() {
    echo "Usage: $0 -1 | -2"
    echo "  -1: Set up secondary monitor above primary (horizontal)"
    echo "  -2: Set up secondary monitor to the right of primary (vertical)"
    exit 1
}

if [ "$#" -ne 1 ]; then
    usage
fi

case "$1" in
    -1)
        gnome-monitor-config set -LM DP-1 -t normal -m 1920x1080@60.000 -LpM eDP-1 -m 1920x1080@60.164 -x 0 -y 1080 -t normal
        echo "1"
        ;;
    -2)
        gnome-monitor-config set -LM DP-1 -m 1920x1080@60.000 -x 1920 -t left -LpM eDP-1 -m 1920x1080@60.164 -x 0 -y 0 -t normal
        echo "2"
        ;;
    *)
        usage
        ;;
esac

Thank you

simdll

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.