Skip to content

Instantly share code, notes, and snippets.

@murar8
Created May 1, 2023 12:33
Show Gist options
  • Save murar8/80af35c72edb07d92711c6df1882a4d0 to your computer and use it in GitHub Desktop.
Save murar8/80af35c72edb07d92711c6df1882a4d0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Description | Copy the latest monitor configuration to GDM.
# Author | Lorenzo Murarotto
# Email | lnzmrr@gmail.com
shopt -s nullglob # Unmatched globs expand to null.
GDM_CONFIG_DIR=/var/lib/gdm/.config
GDM_CONFIG_FILE=$GDM_CONFIG_DIR/monitors.xml
if [ ! -d $GDM_CONFIG_DIR ]; then
echo "GDM configuration directory not present, exiting."
exit 1
fi
for config in /home/*/.config/monitors.xml; do
if [ ! -f "$GDM_CONFIG_FILE" ] || [[ $(date +%s -r "$config") > $(date +%s -r "$GDM_CONFIG_FILE") ]]; then
echo "Copying newest file version from '$config' to '$GDM_CONFIG_FILE'."
cp "$config" "$GDM_CONFIG_FILE"
chown gdm:gdm "$GDM_CONFIG_FILE"
fi
done
@murar8
Copy link
Author

murar8 commented May 1, 2023

Copy the latest monitor configuration to gdm at every boot.

Note: If you use GDM under Wayland, you must also use a monitors.xml that was created under Wayland.

More info: https://wiki.archlinux.org/title/GDM

Installation

Install the script:

curl https://gist.githubusercontent.com/murar8/80af35c72edb07d92711c6df1882a4d0/raw/5545d604f627c0180ba2953fd345d501b5926e47/copy-gdm-config | sudo tee /usr/local/bin/copy-gdm-config
sudo chmod +x /usr/local/bin/copy-gdm-config

Make it run before gdm starts

sudo systemctl edit gdm.service

Make the file look like this:

### Editing /etc/systemd/system/gdm.service.d/override.conf
### Anything between here and the comment below will become the contents of the drop-in file

[Service]
ExecStartPre=-/usr/local/bin/copy-gdm-config

# Edits below this comment will be discarded

Now the last modified monitor configuration will be applied to gdm at each boot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment