diff --git a/debian/postinst b/debian/postinst index 220aee3..8213eb3 100644 --- a/debian/postinst +++ b/debian/postinst @@ -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 diff --git a/meson.build b/meson.build index 7c214a9..993cfd6 100644 --- a/meson.build +++ b/meson.build @@ -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 diff --git a/meson_options.txt b/meson_options.txt index 9ca0bbc..c0d4573 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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.') diff --git a/plymouth/meson.build b/plymouth/meson.build new file mode 100644 index 0000000..4e13edf --- /dev/null +++ b/plymouth/meson.build @@ -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' +) diff --git a/plymouth/plymouth-hidpi.service.in b/plymouth/plymouth-hidpi.service.in new file mode 100644 index 0000000..9e7c5ae --- /dev/null +++ b/plymouth/plymouth-hidpi.service.in @@ -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 diff --git a/plymouth/plymouth-hidpi.sh b/plymouth/plymouth-hidpi.sh new file mode 100755 index 0000000..09fc75f --- /dev/null +++ b/plymouth/plymouth-hidpi.sh @@ -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 ' + /yes<\/primary>/ {print prev; exit} + {prev=$0} +' $MONITORS_XML | grep -oP '\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 < "$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