From 71cb9273463a200b63c4d4e8dc14e2c1ecf569bf Mon Sep 17 00:00:00 2001 From: rreina Date: Tue, 25 Mar 2025 23:35:18 +0100 Subject: [PATCH 1/9] Add HiDPI support for Plymouth boot --- meson.build | 3 ++ plymouth/meson.build | 18 +++++++++++ plymouth/plymouth-hidpi.service | 11 +++++++ plymouth/plymouth-hidpi.sh | 54 +++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 plymouth/meson.build create mode 100644 plymouth/plymouth-hidpi.service create mode 100755 plymouth/plymouth-hidpi.sh diff --git a/meson.build b/meson.build index 7c214a9..e49e2b8 100644 --- a/meson.build +++ b/meson.build @@ -49,3 +49,6 @@ subdir('skel') # GTK settings subdir('gtk') + +# Plymouth HiDPI support +subdir('plymouth') diff --git a/plymouth/meson.build b/plymouth/meson.build new file mode 100644 index 0000000..b08c74b --- /dev/null +++ b/plymouth/meson.build @@ -0,0 +1,18 @@ +# Configure Plymouth for HiDPI screens +install_data( + 'plymouth-hidpi.sh', + install_dir: '/usr/local/bin', + install_mode: 'rwxr-xr-x' +) + +install_data( + 'plymouth-hidpi.service', + install_dir: '/etc/systemd/system' +) + +# Enable the service so it runs once on boot +meson.add_install_script('systemctl', 'enable', 'plymouth-hidpi.service') + +# Reload systemd daemon after installation +meson.add_install_script('systemctl', 'daemon-reload') + diff --git a/plymouth/plymouth-hidpi.service b/plymouth/plymouth-hidpi.service new file mode 100644 index 0000000..04cde23 --- /dev/null +++ b/plymouth/plymouth-hidpi.service @@ -0,0 +1,11 @@ +[Unit] +Description=Configure Plymouth for HiDPI screens +After=graphical.target + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/plymouth-hidpi.sh +ExecStartPost=/bin/bash -c "systemctl disable plymouth-hidpi.service; rm -f /etc/systemd/system/plymouth-hidpi.service /usr/local/bin/plymouth-hidpi.sh" + +[Install] +WantedBy=multi-user.target diff --git a/plymouth/plymouth-hidpi.sh b/plymouth/plymouth-hidpi.sh new file mode 100755 index 0000000..c424c4f --- /dev/null +++ b/plymouth/plymouth-hidpi.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +CONFIG_FILE="/etc/plymouth/plymouthd.conf" +DAEMON_SECTION="[Daemon]" +SCALE_SETTING="DeviceScale=1" +HIDPI_THRESHOLD=180 # Min DPI of a HiDPI screen + +# Get current DPI +DPI=$(xrdb -query | grep dpi | awk '{print $2}') + +# Adds +# [Daemon] +# DeviceScale=1 +# only if missing in the file +add_setting() { + # Remove first line if it's blank + sed -i '1{/^$/d}' "$CONFIG_FILE" + + if ! grep -q "$DAEMON_SECTION" "$CONFIG_FILE"; then + echo -e "$DAEMON_SECTION" >> "$CONFIG_FILE" + fi + + sed -i "/$DAEMON_SECTION/a $SCALE_SETTING" "$CONFIG_FILE" +} + +# Creates the configuration file with the necessary settings. +create_config() { + echo -e "$DAEMON_SECTION\n$SCALE_SETTING" > "$CONFIG_FILE" +} + +apply_hidpi_setting() { + if [[ "$DPI" -ge "$HIDPI_THRESHOLD" ]]; then + if [[ -f "$CONFIG_FILE" ]]; then + if ! grep -q "^DeviceScale" "$CONFIG_FILE"; then + add_setting + logger -t plymouth-hidpi "Added '$SCALE_SETTING' to '$CONFIG_FILE'" + else + logger -t plymouth-hidpi "HiDPI setting already present in '$CONFIG_FILE' no changes made" + fi + else + create_config + logger -t plymouth-hidpi "Created new config: '$CONFIG_FILE' with HiDPI setting" + fi + + # Apply the changes + update-initramfs -u + logger -t plymouth-hidpi "Updated initramfs after HiDPI change" + else + logger -t plymouth-hidpi "Skipped HiDPI settings (DPI: $DPI, Threshold: $HIDPI_THRESHOLD)" + + fi +} + +apply_hidpi_setting From 9c48ddc9bf5b89e6ec031884df33b2e922431398 Mon Sep 17 00:00:00 2001 From: rreina Date: Wed, 26 Mar 2025 22:23:47 +0100 Subject: [PATCH 2/9] Set the plymouth-hidpi service environment --- plymouth/plymouth-hidpi.service | 5 ++++- plymouth/plymouth-hidpi.sh | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plymouth/plymouth-hidpi.service b/plymouth/plymouth-hidpi.service index 04cde23..eb27905 100644 --- a/plymouth/plymouth-hidpi.service +++ b/plymouth/plymouth-hidpi.service @@ -1,11 +1,14 @@ [Unit] Description=Configure Plymouth for HiDPI screens -After=graphical.target +After=display-manager.service +Requires=display-manager.service [Service] Type=oneshot +Environment="DISPLAY=:0" ExecStart=/usr/local/bin/plymouth-hidpi.sh ExecStartPost=/bin/bash -c "systemctl disable plymouth-hidpi.service; rm -f /etc/systemd/system/plymouth-hidpi.service /usr/local/bin/plymouth-hidpi.sh" + [Install] WantedBy=multi-user.target diff --git a/plymouth/plymouth-hidpi.sh b/plymouth/plymouth-hidpi.sh index c424c4f..38b1fd0 100755 --- a/plymouth/plymouth-hidpi.sh +++ b/plymouth/plymouth-hidpi.sh @@ -41,7 +41,7 @@ apply_hidpi_setting() { create_config logger -t plymouth-hidpi "Created new config: '$CONFIG_FILE' with HiDPI setting" fi - + # Apply the changes update-initramfs -u logger -t plymouth-hidpi "Updated initramfs after HiDPI change" From bea89442e0523b4666e0cc042c36f368d237a51e Mon Sep 17 00:00:00 2001 From: rreina Date: Wed, 26 Mar 2025 22:26:50 +0100 Subject: [PATCH 3/9] Remove blank line --- plymouth/plymouth-hidpi.service | 1 - 1 file changed, 1 deletion(-) diff --git a/plymouth/plymouth-hidpi.service b/plymouth/plymouth-hidpi.service index eb27905..4784f7d 100644 --- a/plymouth/plymouth-hidpi.service +++ b/plymouth/plymouth-hidpi.service @@ -9,6 +9,5 @@ Environment="DISPLAY=:0" ExecStart=/usr/local/bin/plymouth-hidpi.sh ExecStartPost=/bin/bash -c "systemctl disable plymouth-hidpi.service; rm -f /etc/systemd/system/plymouth-hidpi.service /usr/local/bin/plymouth-hidpi.sh" - [Install] WantedBy=multi-user.target From 6f115ea3efc602354f6649a3dc1191000b968154 Mon Sep 17 00:00:00 2001 From: rreina Date: Fri, 28 Mar 2025 15:27:10 +0100 Subject: [PATCH 4/9] Remove blank line --- plymouth/plymouth-hidpi.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/plymouth/plymouth-hidpi.sh b/plymouth/plymouth-hidpi.sh index 38b1fd0..fac39a2 100755 --- a/plymouth/plymouth-hidpi.sh +++ b/plymouth/plymouth-hidpi.sh @@ -47,7 +47,6 @@ apply_hidpi_setting() { logger -t plymouth-hidpi "Updated initramfs after HiDPI change" else logger -t plymouth-hidpi "Skipped HiDPI settings (DPI: $DPI, Threshold: $HIDPI_THRESHOLD)" - fi } From 02cd7bd0bbb8ef8c8d6296c64d1eb3e7b658ec5d Mon Sep 17 00:00:00 2001 From: rreina Date: Sat, 29 Mar 2025 11:43:47 +0100 Subject: [PATCH 5/9] Set up the Plymouth-HiDPI service after primary deb package installs --- debian/postinst | 7 +++++++ plymouth/meson.build | 6 ------ 2 files changed, 7 insertions(+), 6 deletions(-) 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/plymouth/meson.build b/plymouth/meson.build index b08c74b..034f155 100644 --- a/plymouth/meson.build +++ b/plymouth/meson.build @@ -10,9 +10,3 @@ install_data( install_dir: '/etc/systemd/system' ) -# Enable the service so it runs once on boot -meson.add_install_script('systemctl', 'enable', 'plymouth-hidpi.service') - -# Reload systemd daemon after installation -meson.add_install_script('systemctl', 'daemon-reload') - From 03cf5da146ece7e31c5f7b28a1eb748d88ecc31f Mon Sep 17 00:00:00 2001 From: rreina Date: Sat, 29 Mar 2025 23:02:36 +0100 Subject: [PATCH 6/9] Fix service target and ensure Gala is available for xrdb command to work --- plymouth/meson.build | 1 - plymouth/plymouth-hidpi.service | 9 +++--- plymouth/plymouth-hidpi.sh | 57 +++++++++++++++------------------ 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/plymouth/meson.build b/plymouth/meson.build index 034f155..3ec0dd5 100644 --- a/plymouth/meson.build +++ b/plymouth/meson.build @@ -9,4 +9,3 @@ install_data( 'plymouth-hidpi.service', install_dir: '/etc/systemd/system' ) - diff --git a/plymouth/plymouth-hidpi.service b/plymouth/plymouth-hidpi.service index 4784f7d..ecc6c05 100644 --- a/plymouth/plymouth-hidpi.service +++ b/plymouth/plymouth-hidpi.service @@ -1,13 +1,14 @@ [Unit] Description=Configure Plymouth for HiDPI screens -After=display-manager.service -Requires=display-manager.service +After=graphical.target +Requires=graphical.target [Service] Type=oneshot Environment="DISPLAY=:0" ExecStart=/usr/local/bin/plymouth-hidpi.sh -ExecStartPost=/bin/bash -c "systemctl disable plymouth-hidpi.service; rm -f /etc/systemd/system/plymouth-hidpi.service /usr/local/bin/plymouth-hidpi.sh" +ExecStartPost=/bin/bash -c 'if [ $? -eq 0 ]; then systemctl disable plymouth-hidpi.service; rm -f /etc/systemd/system/plymouth-hidpi.service /usr/local/bin/plymouth-hidpi.sh; fi' [Install] -WantedBy=multi-user.target +WantedBy=graphical.target + diff --git a/plymouth/plymouth-hidpi.sh b/plymouth/plymouth-hidpi.sh index fac39a2..115ea71 100755 --- a/plymouth/plymouth-hidpi.sh +++ b/plymouth/plymouth-hidpi.sh @@ -1,50 +1,45 @@ #!/bin/bash CONFIG_FILE="/etc/plymouth/plymouthd.conf" -DAEMON_SECTION="[Daemon]" -SCALE_SETTING="DeviceScale=1" HIDPI_THRESHOLD=180 # Min DPI of a HiDPI screen -# Get current DPI -DPI=$(xrdb -query | grep dpi | awk '{print $2}') +TIMEOUT=300 # Set the maximum wait time in seconds +ELAPSED=0 -# Adds -# [Daemon] -# DeviceScale=1 -# only if missing in the file -add_setting() { - # Remove first line if it's blank - sed -i '1{/^$/d}' "$CONFIG_FILE" +# Wait until Gala is running or timeout occurs +while ! pgrep -x "gala" > /dev/null && [ $ELAPSED -lt $TIMEOUT ]; do + sleep 1 + ((ELAPSED++)) +done - if ! grep -q "$DAEMON_SECTION" "$CONFIG_FILE"; then - echo -e "$DAEMON_SECTION" >> "$CONFIG_FILE" - fi +if [ $ELAPSED -ge $TIMEOUT ]; then + echo "Timeout reached while waiting for Gala to start" >&2 + exit 1 +fi - sed -i "/$DAEMON_SECTION/a $SCALE_SETTING" "$CONFIG_FILE" -} +# Get current DPI +export DISPLAY=":0" +DPI=$(xrdb -query | grep dpi | awk '{print $2}') -# Creates the configuration file with the necessary settings. create_config() { - echo -e "$DAEMON_SECTION\n$SCALE_SETTING" > "$CONFIG_FILE" + cat < "$CONFIG_FILE" +[Daemon] +DeviceScale=1 +EOF + logger -t plymouth-hidpi "Created new config: '$CONFIG_FILE' with HiDPI setting" } apply_hidpi_setting() { if [[ "$DPI" -ge "$HIDPI_THRESHOLD" ]]; then - if [[ -f "$CONFIG_FILE" ]]; then - if ! grep -q "^DeviceScale" "$CONFIG_FILE"; then - add_setting - logger -t plymouth-hidpi "Added '$SCALE_SETTING' to '$CONFIG_FILE'" - else - logger -t plymouth-hidpi "HiDPI setting already present in '$CONFIG_FILE' no changes made" - fi - else + if [[ ! -f "$CONFIG_FILE" ]]; then create_config - logger -t plymouth-hidpi "Created new config: '$CONFIG_FILE' with HiDPI setting" - fi - # Apply the changes - update-initramfs -u - logger -t plymouth-hidpi "Updated initramfs after HiDPI change" + # 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 From 17167810810bef1003237eb607f02b4f8335cbf6 Mon Sep 17 00:00:00 2001 From: rreina Date: Sun, 30 Mar 2025 20:48:26 +0200 Subject: [PATCH 7/9] Support Wayland & X11 by reading the scaling factor from Gnome's monitors.xml file. Also respect get_option('bindir') for improved configuration handling. --- plymouth/meson.build | 9 +++-- ...idpi.service => plymouth-hidpi.service.in} | 6 +-- plymouth/plymouth-hidpi.sh | 38 ++++++++++++++----- 3 files changed, 36 insertions(+), 17 deletions(-) rename plymouth/{plymouth-hidpi.service => plymouth-hidpi.service.in} (71%) diff --git a/plymouth/meson.build b/plymouth/meson.build index 3ec0dd5..4e13edf 100644 --- a/plymouth/meson.build +++ b/plymouth/meson.build @@ -1,11 +1,14 @@ # Configure Plymouth for HiDPI screens install_data( 'plymouth-hidpi.sh', - install_dir: '/usr/local/bin', + install_dir: get_option('bindir'), install_mode: 'rwxr-xr-x' ) -install_data( - 'plymouth-hidpi.service', +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 b/plymouth/plymouth-hidpi.service.in similarity index 71% rename from plymouth/plymouth-hidpi.service rename to plymouth/plymouth-hidpi.service.in index ecc6c05..8e81db3 100644 --- a/plymouth/plymouth-hidpi.service +++ b/plymouth/plymouth-hidpi.service.in @@ -5,10 +5,8 @@ Requires=graphical.target [Service] Type=oneshot -Environment="DISPLAY=:0" -ExecStart=/usr/local/bin/plymouth-hidpi.sh -ExecStartPost=/bin/bash -c 'if [ $? -eq 0 ]; then systemctl disable plymouth-hidpi.service; rm -f /etc/systemd/system/plymouth-hidpi.service /usr/local/bin/plymouth-hidpi.sh; fi' +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' [Install] WantedBy=graphical.target - diff --git a/plymouth/plymouth-hidpi.sh b/plymouth/plymouth-hidpi.sh index 115ea71..8443d1b 100755 --- a/plymouth/plymouth-hidpi.sh +++ b/plymouth/plymouth-hidpi.sh @@ -1,25 +1,43 @@ #!/bin/bash CONFIG_FILE="/etc/plymouth/plymouthd.conf" -HIDPI_THRESHOLD=180 # Min DPI of a HiDPI screen -TIMEOUT=300 # Set the maximum wait time in seconds +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 ]; do - sleep 1 - ((ELAPSED++)) +while ! pgrep -x "gala" > /dev/null && [ $ELAPSED -lt $TIMEOUT_SECONDS ]; do + sleep 5 + ((ELAPSED += 5)) done -if [ $ELAPSED -ge $TIMEOUT ]; then +if [ $ELAPSED -ge $TIMEOUT_SECONDS ]; then echo "Timeout reached while waiting for Gala to start" >&2 exit 1 fi -# Get current DPI -export DISPLAY=":0" -DPI=$(xrdb -query | grep dpi | awk '{print $2}') +# 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 ' + /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" @@ -30,7 +48,7 @@ EOF } apply_hidpi_setting() { - if [[ "$DPI" -ge "$HIDPI_THRESHOLD" ]]; then + if [[ "$PRIMARY_MONITOR_SCALE" -eq 2 ]]; then if [[ ! -f "$CONFIG_FILE" ]]; then create_config From 070185303c7553aa595621540d08873e8a74137c Mon Sep 17 00:00:00 2001 From: rreina Date: Sun, 30 Mar 2025 21:24:27 +0200 Subject: [PATCH 8/9] Add a Meson option to enable/disable Plymouth HiDPI support. --- meson.build | 6 +++++- meson_options.txt | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index e49e2b8..993cfd6 100644 --- a/meson.build +++ b/meson.build @@ -51,4 +51,8 @@ subdir('skel') subdir('gtk') # Plymouth HiDPI support -subdir('plymouth') +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.') From ab61f47d20cae9bcf2342f5535d63205de54c60f Mon Sep 17 00:00:00 2001 From: rreina Date: Tue, 1 Apr 2025 15:45:19 +0200 Subject: [PATCH 9/9] Update Plymouth HiDPI settings on every boot based on the primary monitor --- plymouth/plymouth-hidpi.service.in | 1 - plymouth/plymouth-hidpi.sh | 61 ++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/plymouth/plymouth-hidpi.service.in b/plymouth/plymouth-hidpi.service.in index 8e81db3..9e7c5ae 100644 --- a/plymouth/plymouth-hidpi.service.in +++ b/plymouth/plymouth-hidpi.service.in @@ -6,7 +6,6 @@ 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' [Install] WantedBy=graphical.target diff --git a/plymouth/plymouth-hidpi.sh b/plymouth/plymouth-hidpi.sh index 8443d1b..09fc75f 100755 --- a/plymouth/plymouth-hidpi.sh +++ b/plymouth/plymouth-hidpi.sh @@ -2,25 +2,22 @@ CONFIG_FILE="/etc/plymouth/plymouthd.conf" +logger -t plymouth-hidpi "Running plymouth-hidpi.sh..." + 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)) +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 [ $ELAPSED -ge $TIMEOUT_SECONDS ]; then - echo "Timeout reached while waiting for Gala to start" >&2 - exit 1 -fi - -# 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." + logger -t plymouth-hidpi "No active user with a graphical session within timeout period." exit 1 fi @@ -28,7 +25,7 @@ USER_HOME=$(eval echo ~$ACTIVE_USER) # Get the home directory of the active use 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" + logger -t plymouth-hidpi "Monitors XML file not found for user: $ACTIVE_USER" exit 1 fi @@ -47,19 +44,43 @@ 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 - - # Apply the changes - update-initramfs -u - logger -t plymouth-hidpi "Updated initramfs after HiDPI change" + commit_changes "Updated initramfs after adding HiDPI setting" else - logger -t plymouth-hidpi "HiDPI config file already exists, no changes made" + 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 (DPI: $DPI, Threshold: $HIDPI_THRESHOLD)" + logger -t plymouth-hidpi "Skipped HiDPI settings (scale: $PRIMARY_MONITOR_SCALE)" fi }