I had the same problem. This is the solution that worked for me. I uploaded a whole working solution here
https://github.com/pangratt12345/automatic-monitor-readjustment
It seems that there are some bugs regarding /etc/X11/xorg.conf file.
Also it seems that no matter what the content of /etc/X11/xorg.conf file is, all Nvidia settings are overridden by native Linux settings stored in ~/.config/monitors.xml
This problem is also mentioned in this document in section - "The display settings I configured in nvidia-settings do not persist"
http://http.download.nvidia.com/XFree86/Linux-x86_64/565.57.01/README/commonproblems.html#settingsoverridden
So one approach might be to change the content of ~/.config/monitors.xml file
Another approach is to change screen resolution settings manually.
You can use 2 equivalent commands for this purpose:
nvidia-settings --assign CurrentMetaMode="HDMI-0: 1280x1024 +0+0"
xrandr --output HDMI-0 --mode 1280x1024
It is important to write correct cable interface into these commands
xrandr command shows which monitor/cable is currently used. For me it was HDMI-0. You may need to substitute HDMI-0 with DPY-3, DP-0, DVI-D-0, etc. depending on first element in xrandr output line corresponding to Your monitor
or can check the content of this folder
/sys/class/drm/
Then You can make an automatic script to be run after every startup of Linux
gnome-session-properties
or by creating file like nvidia-setup.desktop in this directory /home/{username}/.config/autostart/
[Desktop Entry]
Type=Application
Exec=nvidia-settings --assign CurrentMetaMode="HDMI-0: 1280x1024 +0+0"
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Monitor_settings_Readjustment
Or even better, you can create an udev callback to readjust nvidia screen settings properly every time specific monitor is plugged to PC
Can create udev rule like this 99-monitor-hotplug.rules in this folder /etc/udev/rules.d
KERNEL=="card[0-9]*", SUBSYSTEM=="drm", ACTION=="change", ENV{DISPLAY}=":1.0", ENV{XAUTHORITY}+="/run/user/1000/gdm/Xauthority", ENV{HOTPLUG}+="1", RUN+="/usr/sbin/hotplug.sh"
and callback function hotplug.sh in this folder /usr/sbin/
if [[ $(cat /sys/class/drm/card1-HDMI-A-1/status) == 'connected' ]]; then
echo "monitor connected with HDMI";
nvidia-settings --assign CurrentMetaMode="HDMI-0: 1280x1024 +0+0";
fi
When using udev monitor cable unplug/replug events then these 2 environment variables are important to be set in automatic script DISPLAY, XAUTHORITY
export DISPLAY=":$(find /tmp/.X11-unix/* | sed s#/tmp/.X11-unix/X##).0";
export XAUTHORITY="$(ps -C Xorg -f --no-header | sed -n "s/.*-auth //; s/ -[^ ].*//; p")";
More information about udev callbacks here
https://stackoverflow.com/questions/5469828/how-to-create-a-callback-for-monitor-plugged-on-an-intel-graphics