My laptop has a 4k screen and I also have an external 1080p monitor. The scaling is incorrect on the monitor and so every time I plug in the monitor, I execute an xrandr command to fix it. I figured I could automate the process and have created a udev rule to execute when it recognizes my monitor is plugged into the HDMI port. The issue is that the xrandr scripts are not being executed. I put an echo to a text file in the script right above the xrandr command to make sure it was reaching that point and it was. I have also tried using sleep commands, but the external monitor just waits for the script to finish sleeping before turning on. Running the script manually works.
My udev rule file is as follows:
SUBSYSTEM==”drm”, ACTION==”change”, RUN+=”/usr/local/bin/ext_monitor_scale”
USER_NAME=`who | grep “(:0)” | cut -f 1 -d ‘ ‘`
if [ $HDMI_STATUS = “connected” ]
echo “test” >> test.txt
sudo -u $USER_NAME xrandr –output DP-3 –scale 2×2 –output eDP-1 –scale 0.9999×0.9999
Does anyone know a workaround? It seems I need to wait and allow the monitor to come on incorrectly and then have the script execute the xrandr command, but since the display waits for sleep before it auto adjusts I don’t know how to go about this. Thanks!