Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set correct primary monitor for login screen when lightdm greeter starts up on Elementary OS
#!/bin/bash
#
# Created: 2017-07-02 16:20
# Updated: 2018-02-09 12:23
# Creator: Ryan Miller
# Website: http://devopsmachine.com/
# File: /usr/local/bin/set-primary-monitor-pantheon-greeter
#
# Set correct primary monitor for login screen when lightdm greeter starts up on Elementary OS.
#
# Make sure to add the following line into /usr/share/lightdm/lightdm.conf.d/40-pantheon-greeter.conf (without the #)
# greeter-setup-script=/usr/local/bin/set-primary-monitor-pantheon-greeter
#
# Change this variable to your primary display (Run 'xrandr -q' to see available displays)
PRIMARY_DISPLAY='HDMI-0'
# Get list of connected monitors
x_out=$(xrandr -q | grep -e '\( \)connected' | awk -F' ' '{ print $1 }')
# Safety - Check if PRIMARY_DISPLAY is connected; if not, bail out of script
[[ $(grep ${PRIMARY_DISPLAY} <<< ${x_out}) ]] || exit 0
# Iterate over x_out and disable all monitors except for PRIMARY_DISPLAY
for monitor in ${x_out[@]} ; do
if [[ ${monitor} = ${PRIMARY_DISPLAY} ]] ; then
xrandr --output ${monitor} --primary
else
xrandr --output ${monitor} --off
fi
done
@Sarkie

This comment has been minimized.

Copy link

commented Dec 18, 2017

/usr/local/bin/set-primary-monitor-pantheon-greeter

greeter-setup-script=/usr/local/bin/correct-screen-pantheon-greeter

Assume typo?

@pr0digi

This comment has been minimized.

Copy link

commented Jan 4, 2018

Exit code in case primary display isn't connected should be "0", otherwise greeter ends up in loop.

@pwamej

This comment has been minimized.

Copy link

commented Jan 26, 2018

doesn't work for me, even after applying fixes from comments. This bug is really annoying
EDIT: Found a solution! Line greeter-setup-script=/usr/local/bin/correct-screen-pantheon-greeter (assuming you saved script from gist in this path) should be placed in /etc/lightdm/lightdm.conf (if file doesn't exist, create it)
Final files should look like this:

#!/bin/bash
#
# { 2017-07-02 16:20 }
# { Ryan Miller | ryan@abstractfoc.us }
# { /usr/local/bin/correct-screen-pantheon-greeter }
# 
# Set correct primary monitor for login screen when lightdm greeter starts up on Elementary OS.

# Change this variable to your primary display (Run 'xrandr -q' to see available displays)
PRIMARY_DISPLAY='HDMI-0'

# Get list of connected monitors
x_out=$(xrandr -q | grep -e '\( \)connected' | awk -F' ' '{ print $1 }')

# Safety - Check if PRIMARY_DISPLAY is connected; if not, bail out of script
[[ $(grep ${PRIMARY_DISPLAY} <<< ${x_out}) ]] || exit 0
     
# Iterate over x_out and disable all monitors except for PRIMARY_DISPLAY
for monitor in ${x_out[@]} ; do
    if [[ ${monitor} = ${PRIMARY_DISPLAY} ]] ; then
        xrandr --output ${monitor} --primary
    else
        xrandr --output ${monitor} --off
    fi
done
#{ /etc/lightdm/lightdm.conf }
[Seat:*]
greeter-setup-script=/usr/local/bin/correct-screen-pantheon-greeter
@RyanMillerC

This comment has been minimized.

Copy link
Owner Author

commented Feb 10, 2018

Fixed typo and exit 1 in code. Not really sure about /etc/lightdm/lightdm.conf as opposed to /usr/share/lightdm/lightdm.conf.d/40-pantheon-greeter.conf. Are you using Elementary OS or just lightdm on another distribution? Glad it's working for you though!

@kt1024

This comment has been minimized.

Copy link

commented Mar 15, 2018

after add changes my eOS failed to boot, stucked with the boot logo 'e'.
remove lightdm.conf in recovery mode made system boot normally again.

  • have changed PRIMARY_DISPLAY to HDMI-2 according to xrandr results.
@owlugo

This comment has been minimized.

Copy link

commented Apr 9, 2018

Work for me, I do:
Make a archive with name 'correct-screen-pantheon-greeter' in /usr/local/bin/, with 755 permissions
With the content:

#!/bin/bash
#
# { 2017-07-02 16:20 }
# { Ryan Miller | ryan@abstractfoc.us }
# { /usr/local/bin/correct-screen-pantheon-greeter }
# 
# Set correct primary monitor for login screen when lightdm greeter starts up on Elementary OS.

# Change this variable to your primary display (Run 'xrandr -q' to see available displays)
PRIMARY_DISPLAY='HDMI-0'

# Get list of connected monitors
x_out=$(xrandr -q | grep -e '\( \)connected' | awk -F' ' '{ print $1 }')

# Safety - Check if PRIMARY_DISPLAY is connected; if not, bail out of script
[[ $(grep ${PRIMARY_DISPLAY} <<< ${x_out}) ]] || exit 0
     
# Iterate over x_out and disable all monitors except for PRIMARY_DISPLAY
for monitor in ${x_out[@]} ; do
    if [[ ${monitor} = ${PRIMARY_DISPLAY} ]] ; then
        xrandr --output ${monitor} --primary
    else
        xrandr --output ${monitor} --off
    fi
done

after
Make a archive with name 'lightdm.conf' in /etc/lightdm/, with 755 permissions
With the content:

#{ /etc/lightdm/lightdm.conf }
[Seat:*]
greeter-setup-script=/usr/local/bin/correct-screen-pantheon-greeter

I did what @pawamej said and I added the permissions, before this (without writing permission) too my eOS failed to boot, stucked with the boot logo 'e' @kt1024

@NoisyFlake

This comment has been minimized.

Copy link

commented Jul 11, 2018

If anyone ends up with a black screen or the elementary logo: you need to make the script executable! So start up in recovery mode and then (as root):

chmod +x /usr/local/bin/set-primary-monitor-pantheon-greeter

Took me a few hours to find this and wanted to share (though it's actually quite obvious why it didn't work before).

@ytccgs

This comment has been minimized.

Copy link

commented Jul 11, 2018

works! it's been annoying for years until I ran into this solution.
The file /etc/lightdm/lightdm.conf doesn't exist, I created it.

@toshe

This comment has been minimized.

Copy link

commented Jul 22, 2018

Just a note: there is no need to create a /etc/lightdm/lightdm.conf file. It's enough to append /usr/share/lightdm/lightdm.conf.d/40-pantheon-greeter.conf with the line. If you create a lightdm.conf file make sure you do not add a greeter-setup-script line to both files as this will result in an endless loop.

Also make sure you chmod +x /usr/local/bin/set-primary-monitor-pantheon-greeter as mentioned in the above comment.

@esfourteen

This comment has been minimized.

Copy link

commented Nov 19, 2018

this worked for login, but on juno locking the screen would result in both monitors being blank and what looked like and endless cycle of the primary display attempting to sync. adding the --auto option seemed to fix that

xrandr --output ${monitor} --primary --auto
@lhorace

This comment has been minimized.

Copy link

commented Mar 16, 2019

Caveat, this worked:

#  cat /usr/share/lightdm/lightdm.conf.d/40-pantheon-greeter.conf
[Seat:*]
greeter-setup-script=/usr/local/bin/set-primary-monitor-pantheon-greeter

You might want to include that in the doc head as the current documentation doesn't work for me on Juno 5.0.

@superhac

This comment has been minimized.

Copy link

commented Mar 28, 2019

Caveat, this worked:

#  cat /usr/share/lightdm/lightdm.conf.d/40-pantheon-greeter.conf
[Seat:*]
greeter-setup-script=/usr/local/bin/set-primary-monitor-pantheon-greeter

You might want to include that in the doc head as the current documentation doesn't work for me on Juno 5.0.

I was able to get it to work on Juno by also copying the monitors.xml file:

sudo cp /home/<_user_>/.config/monitors.xml /var/lib/lightdm/.config/

Reboot and it worked like a charm.

@nnmlss

This comment has been minimized.

Copy link

commented May 30, 2019

Yes, it works like all other similar 'solutions' - until the next shutdown, or plug-in/plug-out the external monitor..

I was able to get it to work on Juno by also copying the monitors.xml file:

sudo cp /home/<_user_>/.config/monitors.xml /var/lib/lightdm/.config/

Reboot and it worked like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.