|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | 3 | CONFIG_FILE="/etc/plymouth/plymouthd.conf" |
4 | | -DAEMON_SECTION="[Daemon]" |
5 | | -SCALE_SETTING="DeviceScale=1" |
6 | 4 | HIDPI_THRESHOLD=180 # Min DPI of a HiDPI screen |
7 | 5 |
|
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 |
10 | 8 |
|
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 |
18 | 14 |
|
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 |
22 | 19 |
|
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}') |
25 | 23 |
|
26 | | -# Creates the configuration file with the necessary settings. |
27 | 24 | 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" |
29 | 30 | } |
30 | 31 |
|
31 | 32 | apply_hidpi_setting() { |
32 | 33 | 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 |
41 | 35 | create_config |
42 | | - logger -t plymouth-hidpi "Created new config: '$CONFIG_FILE' with HiDPI setting" |
43 | | - fi |
44 | 36 |
|
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 |
48 | 43 | else |
49 | 44 | logger -t plymouth-hidpi "Skipped HiDPI settings (DPI: $DPI, Threshold: $HIDPI_THRESHOLD)" |
50 | 45 | fi |
|
0 commit comments