I struggled with this problem too for years. I have PopOs 22.04, but have found a solution by creating a script.
nvidia-settings can be used on the command line to set all settings you see in the nvidia gui, but first, you need to know which attribute to set.
The Task
In my case, I wanted to:
a) configure the locations and orientations of 4 displays
b) set one as the main display.
The steps to have these set at startup are:
- capture the current configuration from the xorg.conf file
- write a script that writes the orientation/location/main monitor settings via nvidia-settings command line option
- run the script at startup
Let's begin:
1) Capture the current configuration
Open the nvidia GUI through your OS, or via the command-line by typing: nvidia-settings.
Next, click "X Servier Display Configuration" set the orientation and location of each display, and the main display.
2) Grab the X Configuration settings
A popup appears, click "Show Preview"
Copy the preview text into an editor.
3) Find the options you want to save
The two options I was interested in are below:
a) nvidiaXineramaInfoOrder
b) metamodes
4) Find out what the attribute names are
We need to find the attribute names for the above settings so we can feed them to nvidia-settings via the command line
type
nvidia-settings --query all > attributes.txt
This will show all the possible attributes we can set,
After reading the attributes.txt, it looks like the attribute I need for order, and locations/orientations are
XineramaInfoOrder
CurrentMetaMode
5) Write the Script:
So I created a script using the above attributes and the values from the xorg preview:
mkdir ~/bin
cd ~/bin
sudo nano nvidiaStartup.sh
Now paste in the command:
nvidia-settings --assign <attributeName>="<your setting from xorg.conf"
example:
#!/bin/bash
nvidia-settings --assign CurrentMetaMode="DP-0: nvidia-auto-select +0+0, HDMI-0: nvidia-auto-select +0+1050, DP-1: nvidia-auto-select +1920+1080, DP-3: nvidia-auto-select +4480+1080 {rotation=right}"
nvidia-settings --assign XineramaInfoOrder="DP-1"
6) Set startup applications
Next, set the permissions of the script
sudo chmod u+x ~/bin/nvidiaStartup.sh
To access start startup settings:
gnome-session-properties
gnome-session-properties
press add
Now it will start up each time you load your OS.
To test it simply type
sh nvidiaStartup.sh
Hope this helps!