Setup Multiple Monitors in Linux with Arandr

1 minute read

1. Arandr for arranging multiple monitors

Install Arandr

sudo apt install arandr

Open it using command arandr


Usually all plugged monitors are appeared here. In case any of them is not, I have to go to Outputs menu and Active it.

The best thing about Arandr is that it gives me the ability to drag around display to choose the best layout I want (which going left - right/ above - under…). Then press apply.

After I get the layout I want, I can save the layout as a bash script to easly activate it later. The script will be save in $HOME/.screenlayout.

2. How to set random separate wallpaper for each monitor using Nitrogen.

The --head=X option tells nitrogen to set wallpaper to which monitor.

(nitrogen --head=0 --set-zoom-fill --random $HOME/Wallpapers)

3. A script to toggle between one monitor and multiple one.

This was not my original idea, I remembered seeing someone’s script elsewhere online and developed my own version. The credit goes to that person.

#Check if HDMI 1 is connect
#If connect, active twoMonitors mode
#If disconnect, active oneMonitor mode

function HDMIConnected {
    ! xrandr | grep "HDMI1" | grep disconnected

function twoMonitors {
  xrandr --auto &&
  (xrandr --output HDMI1 --mode 1920x1080 --pos 1366x0 --rotate normal --output DP1 --off --output eDP1 --primary --mode 1366x768 --pos 0x0 --rotate normal --output VIRTUAL1 --off) &&
  (sleep 1s)&&
  # Set random wallpapers for separate monitor
  (nitrogen --head=0 --set-zoom-fill --random $HOME/Wallpapers) &&
  (nitrogen --head=1 --set-zoom-fill --random $HOME/Wallpapers) &&
  # Set polybar for only one monitor

function oneMonitor {
  xrandr --output HDMI1 --off --output DP1 --off --output eDP1 --primary --mode 1366x768 --pos 0x0 --rotate normal --output VIRTUAL1 --off

if ! HDMIConnected

if HDMIConnected

I use polybar and only want to add it to just my laptop’s monitor (I use another one for just pure display for my web dev task). I get the monitor name from Arandr.

monitor = ${env:eDP1:}

4. Bind it to a desktop file to go with rofi

I add a desktop file at $HOME/.local/share/applications/

[Desktop Entry]
Name=Two Screen Xrandr

Leave a comment