How to change display resolution on RPi 4 / startx

Not an issue, just a tip.

I’m running a 1920x1080 app on a Raspberry Pi 4 via startx. It works fine on a native 1920x1080 monitor, but when I tried a 4k monitor, X starts with the monitor’s default resolution and my app only fills 1/4 of the screen. Here’s how I fixed things, in case anyone else is doing something similar:

After starting the app with startx, you can use xrandr to change the display resolution:
sudo xrandr -display :0.0 --output HDMI-1 --mode 1920x1080

This obviously isn’t ideal. Another option is to create a file called xorg.conf in /etc/X11/ with something like the following contents:

Section “Monitor”
Identifier “HDMI-1”
VendorName “SAM”
Modeline “forced” 148.50 1920 2008 2052 2200 1080 1084 1089 1125 +hsync +vsync
Option “Primary” “true”
Option “PreferredMode” “forced”
Option “Enable” “true”
Option “IgnoreEDID”

Note that the Modeline and VendorName lines were copied from a log file at /var/log/Xorg.??.log that is created by startx. See linux - Xorg -configure not working, but running X works - Super User

Great tips! Thank you!