15

I spent some time getting my settings correct for multiple monitors, and that is working fine when I am logged in, but is not right at the login screen or for other users.

How do I set the display settings globally for all users and the login screen?

mirams
  • 673
  • How did you set it? from GUI or command line, and what exectly are your settings? – Jacob Vlijm Jun 22 '15 at 10:24
  • With the "Screen Display" GUI I think, settings are showing up in there anyway. Two monitors, one rotated. – mirams Jun 22 '15 at 11:01
  • http://askubuntu.com/questions/360886/personalize-monitor-position-before-login sets the login to be the same as one user, which is helpful. http://askubuntu.com/questions/372729/configure-ubuntu-to-rotate-the-display-globally seems to address old xorg settings which are no longer used in 14.04 (I think?). Can't find any question or answer for how to do this on 14.04... – mirams Jun 23 '15 at 09:28
  • I tried that answer, screen rotated for login correctly, and then not rotated for users afterwards (even after deleting their local monitors.xml) – mirams Jun 23 '15 at 09:44
  • I am a bit surprised of the bounty, if you set up your monitors, run sudo cp ~/.config/monitors.xml /var/lib/lightdm/.config/ as suggested earlier, + the solution below, you have your setup for all users (including new users) exactly as you describe. – Jacob Vlijm Jun 26 '15 at 14:55
  • It's obviously not how it is supposed to work though - it must be picking up monitor settings from somewhere to start with - I want to change them there, not 10 seconds after login each time. – mirams Jun 26 '15 at 14:57

6 Answers6

14

Depending on the way you've set up your system, it might be as easy as copying the monitors.xml file from the correctly set-up user to all users:

To test this for one user:

cp --preserve=timestamps /home/CorrectUser/.config/monitors.xml /home/TestUser/.config/

then log off TestUser if already logged in, log back on and see whether everything is correct.

The command for all users:

cp /home/CorrectUser/.config/monitors.xml /tmp/
for szUser in /home/* ; do sudo cp --preserve=timestamps /tmp/monitors.xml $szUser/.config/ ; done

The command for the login screen:

sudo cp --preserve=timestamps /home/CorrectUser/.config/monitors.xml /var/lib/lightdm/.config/

The command for all future users¹:

sudo mkdir -p /etc/skel/.config
sudo cp --preserve=timestamps /home/CorrectUser/.config/monitors.xml /etc/skel/.config/

Note¹: All users you'll be creating in the future

Error404
  • 7,440
Fabby
  • 34,259
  • 1
    I already suggested it in the comments (and in my answer earlier, but rolled back), but OP mentioned it was not sufficient. This does only work for the log in screen :) It also does not work for new users unless you copy them again to those users. – Jacob Vlijm Jun 30 '15 at 08:13
  • 1
    @JacobVlijm: Read again... Mine is for log-in screen and all users... :P (leaving it in there as a comment below this by the OP that it doesn't work would warn other posters from typing all that a third time) >:-) – Fabby Jun 30 '15 at 08:14
  • 1
    I didn' t suggest copying the file to all users, because of this: I'd like a solution that applies settings to all user accounts (and future ones), and also makes the login screen look right. adding to /etc/xdg seems to be the only trick that does that to new users as well. – Jacob Vlijm Jun 30 '15 at 08:22
  • @JacobVlijm: ah, missed that one! (Added solution for that as well) ;-) – Fabby Jun 30 '15 at 08:39
  • 2
    This is best answer yet - sets all the monitors up correctly, and works immediately for the guest user too. As a bonus - is there a way to also copy the "Launcher Placement" setting from the Display Settings GUI too? On my user it is just on one monitor, but on both for new/guest user. – mirams Jun 30 '15 at 09:55
  • I'm glad as I'm currently travelling so had no way to test this out... ;-) The launcher is a unity setting and is hidden somewhere else and as I don't have an additional monitor to test on, you'll have to drop by the AU General Chat Room so we can test things out together... An upvote for the answer so far would be nice! :-) – Fabby Jun 30 '15 at 11:10
  • Is it necessary to use the --preserve=timestamps flag? For me it works without the flag. Are there cases where --preserve=timestamps is required? – Andrew Bate Jan 18 '22 at 16:33
3

To set your screen configuration for every user on log in (this will not change the configuration on the log in screen), you can create a .desktop file in /etc/xdg/autostart

How to do that

  1. find out the name of the screen you'd like to be rotated by running xrandr. It will output a number of lines, among thos a few lines looking like:

    VGA-0 connected
    

    This gives you information on the names of the connected screens.

  2. Pick the one you want to have rotated, in my example below VGA-0
  3. Create a launcher with (e.g.) gedit:

    sudo -i gedit /etc/xdg/autostart/set_screens.desktop
    

    Paste the text below into the file:

    [Desktop Entry]
    Name=set_screens
    Exec=/bin/bash -c "sleep 10&&xrandr --output VGA-0 --rotate left"
    Type=Application
    

    replace in the line:

    Exec=/bin/bash -c "sleep 10&&xrandr --output VGA-0 --rotate left"
    

    The string: VGA-0 by your (rotated) screen's name.

Important notes

  • In the line

    Exec=/bin/bash -c "sleep 10&&xrandr --output VGA-0 --rotate left"
    

    I included a sleep 10. That is because sometimes, xrandr commands break if they run too early, before the desktop is "finished" loading. Possibly you need to increase the break, or you could try leaving it out. In the command, as it is, the screen rotates after 10 seconds after log in of any user.

  • The command:

    xrandr --output VGA-0 --rotate left
    

    rotates the screen left, no need to say that if you'd like another type of rotation, you can choose either left, right, normal, inverted (see also here).

Explanation

You can run commands on startup (actually log in) by placing a .desktop file (launcher) in ~/.config/autostart. This will only run the launcher for a single user. If you do the same, but place the launcher in /etc/xdg/autostart, the command runs whenever any user logs in, unless a specific user disables the launcher for him or her in Dash > Startup Applications

Additionally, you can simply copy your local ~/.config/monitors.xml file to /var/lib/lightdm/monitors.xml to also make the settings work on log in screen.

Imo the combination of this, and the solution above (a launcher in /etc/xdg) is the easiest solution to achieve exactly what you want for both the login screen and (any) user. Also, the solution of a launcher in /etc/xdg is (very) easily reversed or changed in case you'd need to make another setup, without editing many files on (each) user's level, since both the user's settings and the login screen are managed for all users at once in two simple files.

Jacob Vlijm
  • 83,767
  • That might work - changing the settings 10s after login, but I'd prefer to know where they are set to start with and change them for everyone (and the login screen, which is currently sideways). – mirams Jun 23 '15 at 07:46
  • Why would someone downvote this? – Fabby Jun 30 '15 at 18:48
2

for Ubuntu 21.10 the display manager is gdm3 and the command to change the login screen resolution is

sudo cp -v ~/.config/monitors.xml /var/lib/gdm3/.config/

the other existing user can be set with

for u in /home/*
do
   if [ "$u" != "$HOME" ]
   then
       sudo cp -v ~/.config/monitors.xml "$u/.config"
    fi
done

and future users

   sudo mkdir -v /etc/skel/.config/
   sudo cp -v  ~/.config/monitors.xml /etc/skel/.config/

Note: the -v is optional

NB: don't bother with /root the root user as you should NEVER login as root in the GUI it is very dangerous

grizzlysmit
  • 53
  • 1
  • 7
  • Unfortunately the accepted is grossly outdated, this should be the new accepted answer. – Jonah Jun 03 '22 at 03:11
2

Just wanted to add a comment for anyone finding this struggling with a similar issue. I was stuck with resolution of my old monitor (1280x1024) every time I log in, but the login screen and guest user login use the correct default 1680x1050.

I've read a lot of posts over the last four months looking for an answer, reading up on xorg.conf, monitors.xml, lightdm and xrandr and other suggestions - but some config changes are complicated and carry the risk of breaking the display entirely, so I ended up using the gui to change the monitor setting manually every login.

Today I did a grep for the old resolution in my .config folder.

grep -HrnIF '1280' .config | less

First result was ~/.config/autostart/xrandr.desktop file containing this,

Exec=xrandr -s 1280x1024 -r 75

so I just moved the file out of there. And bingo, I log in and get the default 1680x1050 resolution.

It took me a few hours of searching and I couldn't find a close enough answer, so posting here in case it's useful to someone.

MattB
  • 21
  • 1
  • Welcome to Ask Ubuntu. Thanks for sharing your four months (elapsed time) of research. – WinEunuuchs2Unix Dec 28 '16 at 01:13
  • Reading this again I think I possibly created that xrandr.desktop file two years ago to get around Ubuntu always defaulting to the 'Goldstar' basic monitor settings, and that was probably a compatibility issue with my video card. – MattB Jan 21 '17 at 18:38
0

You may wish to append something to /etc/lightdm/lightdm.conf. Here we create a script that uses an xrandr command to setup your display(s). You can use some graphical RandR tool to create a command for you, such as arandr. In my case, the script would look like:

#!/bin/sh
xrandr --output DVI-I-1 --mode 1600x1200 --pos 0x0 --rotate left --output DVI-I-0 --off --output DP-3 --off --output DP-2 --off --output DP-1 --mode 1600x900 --pos 1200x700 --rotate normal --output DP-0 --off

You can put this script in /usr/share or wherever you want. Your script may look far less complex, as this is for a complex dual-monitor setup. Then append something like:

session-setup-script=/usr/share/mycustomxrandr.sh

and:

display-setup-script=/usr/share/mycustomxrandr.sh

Make sure the file is executable, so:

chmod a+x mycustomxrandr.sh

The session-setup-script will set the display for after you login through LightDM, and display-setup-script will change the display for the login screen.

nixpower
  • 1,210
  • 6
  • 18
0

On my system (Ubuntu 16.04) for login screen simply cp'ing as root (using sudo) didn't work. You may also need to make sure that the owner/group of monitors.xml is lightdm:lightdm.

sudo chown lightdm:lightdm /var/lib/lightdm/.config/monitors.xml
Zanna
  • 70,465