Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ esac
ln -s /usr/share/apparmor/extra-profiles/bwrap-userns-restrict /etc/apparmor.d/ || true

#DEBHELPER#

# Plymouth HiDPI support

if [ -x /bin/systemctl ] || [ -x /usr/bin/systemctl ]; then
systemctl preset plymouth-hidpi.service || true
systemctl enable plymouth-hidpi.service || true
fi
7 changes: 7 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ subdir('skel')

# GTK settings
subdir('gtk')

# Plymouth HiDPI support
if get_option('enable-plymouth-hidpi')
subdir('plymouth')
else
message('Plymouth HiDPI support disabled.')
endif
5 changes: 5 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ option('default-gsettings-overrides',
type: 'boolean',
value: true,
description: 'Install default Pantheon GSettings Overrides')

option('enable-plymouth-hidpi',
type: 'boolean',
value: true,
description: 'Enable Plymouth HiDPI support.')
14 changes: 14 additions & 0 deletions plymouth/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Configure Plymouth for HiDPI screens
install_data(
'plymouth-hidpi.sh',
install_dir: get_option('bindir'),
install_mode: 'rwxr-xr-x'
)

configure_file(
input: 'plymouth-hidpi.service.in',
output: 'plymouth-hidpi.service',
configuration: { 'BINDIR': join_paths(get_option('prefix'), get_option('bindir')) },
install: true,
install_dir: '/etc/systemd/system'
)
12 changes: 12 additions & 0 deletions plymouth/plymouth-hidpi.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Configure Plymouth for HiDPI screens
After=graphical.target
Requires=graphical.target

[Service]
Type=oneshot
ExecStart="@BINDIR@/plymouth-hidpi.sh"
ExecStartPost=/bin/bash -c 'if [ $? -eq 0 ]; then systemctl disable plymouth-hidpi.service; rm -f /etc/systemd/system/plymouth-hidpi.service @BINDIR@/plymouth-hidpi.sh; fi'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if user upgrades their monitor? I guess we should update plymouth config in this case. What if we just run this session every boot, not just the first one? Will that give us any issues?

Copy link
Author

@rreina rreina Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that'd be a good improvement.

Hence, the following changes were added:

  1. The script now runs on every boot. It doesn't wait for 'Gala' to be running anymore, it just wait until the user logs in (max waiting time is 5 mins, otherwise it tries again on next boot).
  2. The Plymouth config file is created or updated based on needs, and when updated, the scaling setting is edited or removed based on the scaling factor detected.

Could you please review the latest commit?


[Install]
WantedBy=graphical.target
66 changes: 66 additions & 0 deletions plymouth/plymouth-hidpi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

CONFIG_FILE="/etc/plymouth/plymouthd.conf"

TIMEOUT_SECONDS=300 # Maximum wait time in seconds
ELAPSED=0

# Wait until Gala is running or timeout occurs
while ! pgrep -x "gala" > /dev/null && [ $ELAPSED -lt $TIMEOUT_SECONDS ]; do
sleep 5
((ELAPSED += 5))
done

if [ $ELAPSED -ge $TIMEOUT_SECONDS ]; then
echo "Timeout reached while waiting for Gala to start" >&2
exit 1
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed since this script no longer relies on gala

Copy link
Author

@rreina rreina Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thanks. The script was waiting for 'Gala' to be ready so there was certainty there's a logged in user, but it wasn't really necessary anymore.

I've pushed an update with the last commit to just check if there's an user logged in (5 mins timeout).

Also, I assume the '~.../monitors.xml' file might not be available immediately after installing elementary OS, at least not until the user logs in for the first time. This is the only reason the script waits for an active user session. Otherwise, I’d remove the session check as well. If you know when the file is created or how to confirm this assumption, that would be very helpful.


# Get the active user based on the currently active graphical session
ACTIVE_USER=$(who | grep -E '(:[0-9]+)' | awk '{print $1}' | head -n 1)

if [[ -z "$ACTIVE_USER" ]]; then
logger -t plymouth-hidpi "No active user with a graphical session."
exit 1
fi

USER_HOME=$(eval echo ~$ACTIVE_USER) # Get the home directory of the active user
MONITORS_XML="$USER_HOME/.config/monitors.xml"

if [[ ! -f "$MONITORS_XML" ]]; then
logger -t plymouth-hidpi "Monitors XML file not found for user: $PRIMARY_USER"
exit 1
fi

PRIMARY_MONITOR_SCALE=$(awk '
/<primary>yes<\/primary>/ {print prev; exit}
{prev=$0}
' $MONITORS_XML | grep -oP '<scale>\K[0-9]+')
# Scale=2 means 2x resolution ('Retina Display' in Apple computers)
logger -t plymouth-hidpi "Primary monitor scale: '$PRIMARY_MONITOR_SCALE'"

create_config() {
cat <<EOF > "$CONFIG_FILE"
[Daemon]
DeviceScale=1
EOF
logger -t plymouth-hidpi "Created new config: '$CONFIG_FILE' with HiDPI setting"
}

apply_hidpi_setting() {
if [[ "$PRIMARY_MONITOR_SCALE" -eq 2 ]]; then
if [[ ! -f "$CONFIG_FILE" ]]; then
create_config

# Apply the changes
update-initramfs -u
logger -t plymouth-hidpi "Updated initramfs after HiDPI change"
else
logger -t plymouth-hidpi "HiDPI config file already exists, no changes made"
fi
else
logger -t plymouth-hidpi "Skipped HiDPI settings (DPI: $DPI, Threshold: $HIDPI_THRESHOLD)"
fi
}

apply_hidpi_setting