Skip to content
Open
Show file tree
Hide file tree
Changes from all 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'
)
11 changes: 11 additions & 0 deletions plymouth/plymouth-hidpi.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Configure Plymouth for HiDPI screens
After=graphical.target
Requires=graphical.target

[Service]
Type=oneshot
ExecStart="@BINDIR@/plymouth-hidpi.sh"

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

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

logger -t plymouth-hidpi "Running plymouth-hidpi.sh..."

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

while [[ -z "$ACTIVE_USER" && $ELAPSED -lt $TIMEOUT_SECONDS ]]; do
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 found yet."
sleep 5
((ELAPSED += 5))
fi
done

if [[ -z "$ACTIVE_USER" ]]; then
logger -t plymouth-hidpi "No active user with a graphical session within timeout period."
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: $ACTIVE_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"
}

update_device_scale_in_config() {
if grep -q "^DeviceScale=" "$CONFIG_FILE"; then
sed -i 's/^DeviceScale=.*/DeviceScale=1/' "$CONFIG_FILE"
logger -t plymouth-hidpi "Updated DeviceScale setting in '$CONFIG_FILE'"
elif grep -q "^\[Daemon\]" "$CONFIG_FILE"; then
sed -i '/^\[Daemon\]/a DeviceScale=1' "$CONFIG_FILE"
logger -t plymouth-hidpi "Added DeviceScale setting under [Daemon] in '$CONFIG_FILE'"
else
echo -e "[Daemon]\nDeviceScale=1" >> "$CONFIG_FILE"
logger -t plymouth-hidpi "Created [Daemon] section and added DeviceScale setting in '$CONFIG_FILE'"
fi
}

remove_device_scale_in_config() {
sed -i '/^DeviceScale=/d' "$CONFIG_FILE"
logger -t plymouth-hidpi "Removed DeviceScale setting from '$CONFIG_FILE'"
}

commit_changes() {
update-initramfs -u
logger -t plymouth-hidpi "$1"
}

apply_hidpi_setting() {
if [[ "$PRIMARY_MONITOR_SCALE" -eq 2 ]]; then
if [[ ! -f "$CONFIG_FILE" ]]; then
create_config
commit_changes "Updated initramfs after adding HiDPI setting"
else
update_device_scale_in_config
commit_changes "Updated initramfs after modifying HiDPI setting"
fi
elif [[ -f "$CONFIG_FILE" ]] && grep -q "^DeviceScale=" "$CONFIG_FILE"; then
remove_device_scale_in_config
commit_changes "Updated initramfs after removing HiDPI setting"
else
logger -t plymouth-hidpi "Skipped HiDPI settings (scale: $PRIMARY_MONITOR_SCALE)"
fi
}

apply_hidpi_setting