Skip to content

Commit 03cf5da

Browse files
committed
Fix service target and ensure Gala is available for xrdb command to work
1 parent 02cd7bd commit 03cf5da

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

plymouth/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ install_data(
99
'plymouth-hidpi.service',
1010
install_dir: '/etc/systemd/system'
1111
)
12-

plymouth/plymouth-hidpi.service

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
[Unit]
22
Description=Configure Plymouth for HiDPI screens
3-
After=display-manager.service
4-
Requires=display-manager.service
3+
After=graphical.target
4+
Requires=graphical.target
55

66
[Service]
77
Type=oneshot
88
Environment="DISPLAY=:0"
99
ExecStart=/usr/local/bin/plymouth-hidpi.sh
10-
ExecStartPost=/bin/bash -c "systemctl disable plymouth-hidpi.service; rm -f /etc/systemd/system/plymouth-hidpi.service /usr/local/bin/plymouth-hidpi.sh"
10+
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'
1111

1212
[Install]
13-
WantedBy=multi-user.target
13+
WantedBy=graphical.target
14+

plymouth/plymouth-hidpi.sh

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,45 @@
11
#!/bin/bash
22

33
CONFIG_FILE="/etc/plymouth/plymouthd.conf"
4-
DAEMON_SECTION="[Daemon]"
5-
SCALE_SETTING="DeviceScale=1"
64
HIDPI_THRESHOLD=180 # Min DPI of a HiDPI screen
75

8-
# Get current DPI
9-
DPI=$(xrdb -query | grep dpi | awk '{print $2}')
6+
TIMEOUT=300 # Set the maximum wait time in seconds
7+
ELAPSED=0
108

11-
# Adds
12-
# [Daemon]
13-
# DeviceScale=1
14-
# only if missing in the file
15-
add_setting() {
16-
# Remove first line if it's blank
17-
sed -i '1{/^$/d}' "$CONFIG_FILE"
9+
# Wait until Gala is running or timeout occurs
10+
while ! pgrep -x "gala" > /dev/null && [ $ELAPSED -lt $TIMEOUT ]; do
11+
sleep 1
12+
((ELAPSED++))
13+
done
1814

19-
if ! grep -q "$DAEMON_SECTION" "$CONFIG_FILE"; then
20-
echo -e "$DAEMON_SECTION" >> "$CONFIG_FILE"
21-
fi
15+
if [ $ELAPSED -ge $TIMEOUT ]; then
16+
echo "Timeout reached while waiting for Gala to start" >&2
17+
exit 1
18+
fi
2219

23-
sed -i "/$DAEMON_SECTION/a $SCALE_SETTING" "$CONFIG_FILE"
24-
}
20+
# Get current DPI
21+
export DISPLAY=":0"
22+
DPI=$(xrdb -query | grep dpi | awk '{print $2}')
2523

26-
# Creates the configuration file with the necessary settings.
2724
create_config() {
28-
echo -e "$DAEMON_SECTION\n$SCALE_SETTING" > "$CONFIG_FILE"
25+
cat <<EOF > "$CONFIG_FILE"
26+
[Daemon]
27+
DeviceScale=1
28+
EOF
29+
logger -t plymouth-hidpi "Created new config: '$CONFIG_FILE' with HiDPI setting"
2930
}
3031

3132
apply_hidpi_setting() {
3233
if [[ "$DPI" -ge "$HIDPI_THRESHOLD" ]]; then
33-
if [[ -f "$CONFIG_FILE" ]]; then
34-
if ! grep -q "^DeviceScale" "$CONFIG_FILE"; then
35-
add_setting
36-
logger -t plymouth-hidpi "Added '$SCALE_SETTING' to '$CONFIG_FILE'"
37-
else
38-
logger -t plymouth-hidpi "HiDPI setting already present in '$CONFIG_FILE' no changes made"
39-
fi
40-
else
34+
if [[ ! -f "$CONFIG_FILE" ]]; then
4135
create_config
42-
logger -t plymouth-hidpi "Created new config: '$CONFIG_FILE' with HiDPI setting"
43-
fi
4436

45-
# Apply the changes
46-
update-initramfs -u
47-
logger -t plymouth-hidpi "Updated initramfs after HiDPI change"
37+
# Apply the changes
38+
update-initramfs -u
39+
logger -t plymouth-hidpi "Updated initramfs after HiDPI change"
40+
else
41+
logger -t plymouth-hidpi "HiDPI config file already exists, no changes made"
42+
fi
4843
else
4944
logger -t plymouth-hidpi "Skipped HiDPI settings (DPI: $DPI, Threshold: $HIDPI_THRESHOLD)"
5045
fi

0 commit comments

Comments
 (0)