Set primary monitor on 16.04

Solution 1:

I had this same problem, as well as several other problems related to having multiple monitors.

It turns out this is an open unsolved bug for Ubuntu; meaning the solution link posted in the above comment does not actually contain a solution that fully works. See open bug report here: https://bugs.launchpad.net/ubuntu/+source/xorg-server/+bug/1425000

Fortunately I spent a bunch of time figuring out how to configure this as well as the orientation of the login screens but that's explained in a different thread (I have four monitors and login orientation was wrong but it's all sorted now, if you also have this issue see solution here: Where does Unity/Unity-Greeter Load X Configuration From?)

The quick simple solution to the problem of not being able to set your default display, and/or the default display getting reset after reboot is to put a short shell command that changes the primary monitor as one of your "Startup Applications" which will automatically run every time you log in (this should work for any recent Ubuntu running the Unity display manager which is the default display manager and probably other DMs but I didn't test that):

1) First, you will want to install arandr to easily find your monitor display names, run this in a shell:

sudo apt-get install arandr --upgrade

2) Next, run the arandr command and look at it's user interface that loads (it will probably load on the wrong screen since you haven't configured anything yet).

3) Now, take note of which display (the names should be something like HDMI-# for hdmi or DP-# for display port, DVI-I-# for digital video, etc). The label should be big and obvious once you run arandr. You can either write down the display name, or just keep arnadr window open, so you can see it, and launch a new shell if you need to for the next part. My default display is called DP-4 used in the next example, but undoubtedly yours will be different so take note for the next step.

4) Next, load up the "Startup Applications" tool. You can find it by going to the dash and typing "Startup Applications" and Ubuntu will find it for you, or you can run this command in a shell:

gnome-session-properties

5) Now, from within the Startup Applications tool, click the "Add" button and add a new program to run upon logging in. A window will pop up asking you what to run, here is what to type:

  • Name: Set Default Monitor

  • (Note: put any name you want)

  • Command: xrandr --output DP-4 --primary

  • (Note: change DP-4 *to whatever monitor code you found you want to be the default display when you ran *arandr)

  • Comment: Leave blank or put a reminder for yourself later what this does.

Reboot to fully test it worked and that should do the trick. If you aren't sure if the command will work and want to test it first, you can run xrandr --output DP-4 --primary (again, replace DP-4 with your default monitor) from a shell then launch a window and see if it shows up on the correct default monitor. But in order to have this save and work each time, to work around the bug, you need to add that command to Startup Applications.

UPDATE: It seems here is a second step / part 2 to this solution in order for it to fully work. After several days of testing on Ubuntu 16.04, I discovered it was also necessary to modify ~/.config/monitors.xml to specify the primary monitor. If you don't set the primary monitor in ~/.config/monitors.xml then it appears some windows and/or programs obey the xrandr command and some do not. All you need to do in order to perform this step is open up ~/.config/monitors.xml in a text editor like gedit and set the <primary> tag to yes for the display monitor you want as primary and no for all other displays. Here are the steps:

1) In a shell, first backup your existing monitors.xml file so you can restore it if something unexpected goes wrong during the editing process:

cp ~/.config/monitors.xml ~/.config/monitors_OLD.xml

2) Open monitors.xml in gedit to change the config settings tags:

gedit ~/.config/monitors.xml

3) Now, inside of the gedit editor window, find the output tag labeled for the monitor you want to be primary, then under that <output> block, change the <primary> tag to yes. Be sure to look at all other monitors and change the primary tag for all the other monitors to no.

For me, doing these two things has solved the problem in all cases I've encountered so far.

Solution 2:

OS: Ubuntu Studio 16.04 LTS

The issue was that my config was saving my display settings through the default display program, though not applying the "Primary" setting correctly on bootup.

I have my Laptop on the right and main screen on the left, I have the left monitor configured as primary.

On bootup, it was displaying the top tool bar on the right, whilst the os (mouse) thought it was on the left, hence to use the top tool bar, I had to blindly navigate (estimate) to where the menuitems were by looking on the right screen and using my mouse on the left. I could overcome this by changing the rotation on atleast one screen, applying the settings, then putting them back again. The top tool bar would then correctly be set to my primary (Left) screen.

The process below now does this for me automatically (many thanks to etron's post) :

  1. Install arandr to easily find and configure your display names.

    sudo apt-get install arandr --upgrade
    
  2. Run the arandr command from a shell to configure and identify your displays.
    -- For Layout you can drag the monitors around.
    -- For Active, Primary, Resolution and Orientation settings goto menu option Outputs > %Display.

  3. Once the above is set as you'd like, goto menu option Layout > Save as: and enter ~/.screenlayout/ScreenLayout.sh in the name field.

  4. Edit the ~/.screenlayout/ScreenLayout.sh file in a text editor and duplicate (copy & paste) the entire xrandr line.

  5. Now modify a value in the first xrandr line.
    I changed the --rotate normal option value to --rotate left. When this script runs it will briefly change the rotation left, then back to normal, re-activating the config. Same as what I had to do manually as described above.
    My ScreenLaout.sh file now looks like this:

    #!/bin/sh 
    xrandr --output LVDS-1 --mode 1680x1050 --pos 1680x0 --rotate left --output HDMI-1 --off --output VGA-1 --primary --mode 1680x1050 --pos 0x0 --rotate normal  
    xrandr --output LVDS-1 --mode 1680x1050 --pos 1680x0 --rotate normal --output HDMI-1 --off --output VGA-1 --primary --mode 1680x1050 --pos 0x0 --rotate normal  
    
  6. Next, load up the "Startup Applications" tool. You can find it by going to the dash and typing "Startup Applications" and Ubuntu will find it for you, or you can run this command in a shell:

    gnome-session-properties
    
  7. Now, from within the session and Startup tool, navigate to the "Applcation Autostart" tabe, click the "Add" button and add a new program to run upon logging in. A window will pop up asking you what to run, here is what to type:
    Name: Set Default Monitor (Note: put any name you want)
    Description: Leave blank or put a reminder for yourself later what this does.
    Command: ~/.screenlayout/ScreenLayout.sh

  8. Reboot to fully test it worked.

Note: If you aren't sure if the command will work and want to test it first, you can run the script manually i.e. in my case I would run this ~/.screenlayout/ScreenLayout.sh in a shell. Also, if you would prefer to use keybindings to set multiple configuration, I believe you can do this within arandr, though it requires Metacity, which I haven't investigated so you're on your own here.

Solution 3:

In addition to etron's answer - that didn't work for me, my secondary screen (HDMI1) which is on the left, still would act as if it was to the right of the primary (HDMI2) after a reboot, even though it was all correct in my monitors.xml. What worked for me was as etron describes, but I put the following command in my startup applications instead:

xrandr --output HDMI2 --pos 1920x0 --output HDMI1 --pos 0x0

This forces my primary (HDMI2) on the right (horizontal offset x=1920) and the secondary (HDMI1) on the left (x=0)