
What interests us here is that we can make a udev rule which can trigger a xrandr script on device change events. These can be observed through sudo udevadm monitor -environment. Udev is a Linux device manager, which generates various events. This is the purpose of line 14, but you should tune it to fit the xrandr query output.
The xrandr command is executed if two conditions occur: the monitor is connected following the event, and the resolution appears in xrandr -q. Otherwise, /usr/bin/xrandr -auto should be used. On disconnected or unknown events, I let XFCE handle the automatic resizing. You should change the “DP-1” to the name of your display as it appears in xrandr -q. On line 4, the status of the display is inserted in a variable which we later check to determine the state of the screen. usr/bin/xrandr -output DP-1 -mode 2560x1440 -pos 1920x0 -output eDP-1 -pos 0x700 -scale 1x1 2>&1 | tee -a log.txtĮcho "no resolution, bad setup" > log.txt #THIS IS THE XRANDR COMMAND, output piped to the log If xrandr -q | grep -q "2560" then #the resolution should appear Sleep 1 #give the system time to setup the connectionĭmode= " $(cat /sys/class/drm/card0-DP-1/status)" This is my script: /home//scripts/layout.sh 1ĭate > log.txt #log the date for debug purposes It is heavily inspired by this StackOverflow answer: I struggled for a while to understand why my command couldn’t be run automatically until that answer indicated that it needed a DISPLAY handle and XAUTHORITY. The following script will do the actual automatic connection. Experiment with the values until you get a minimal, reliable and pixel-perfect command. Play with the displays until it works and then select Layout -> Save As to save the command as a. #XFCE4 SCREEN RESOLUTION SWITCHER INSTALL#
Install it with sudo apt-get install ARandR. use Arandr to find out the right commandįirst, we have to find the right xrandr command to automatically setup your connect, e.g xrandr -output DP-1 -mode 2560x1440 -pos 1920x0 -output eDP-1 -pos 0x700 -scale 1x1 in my case.ĪRandR is a visual interface for xrandr (the X11 “ resize and rotate“ protocol), which can also save commands as shell scripts. This will disable the popup every time you connect a screen, since we’ll now do it automatically.Ģ.
Open xfce4-display-settings (or just open the Whisker menu and look for “Display”), then toggle “Configure new displays when connected”. I got tired of this very quickly, but XFCE’s Display settings lacks consistency and there’s no other way but to develop a custom solution for now.
inally select advanced and adjust the position of the secondary monitor to roughly where it needs to be: a little above the laptop’s display. select “extend to the right” (which restricts my secondary monitor to be on the right of my laptop),. wait for xfce4-display-settings to pop up,. Every day, when I come home from work, I connect my Xubuntu laptop to my 27” secondary monitor and need to do the same ritual: