|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | 3 | CONFIG_FILE="/etc/plymouth/plymouthd.conf" |
4 | | -HIDPI_THRESHOLD=180 # Min DPI of a HiDPI screen |
5 | 4 |
|
6 | | -TIMEOUT=300 # Set the maximum wait time in seconds |
| 5 | +TIMEOUT_SECONDS=300 # Maximum wait time in seconds |
7 | 6 | ELAPSED=0 |
8 | 7 |
|
9 | 8 | # Wait until Gala is running or timeout occurs |
10 | | -while ! pgrep -x "gala" > /dev/null && [ $ELAPSED -lt $TIMEOUT ]; do |
11 | | - sleep 1 |
12 | | - ((ELAPSED++)) |
| 9 | +while ! pgrep -x "gala" > /dev/null && [ $ELAPSED -lt $TIMEOUT_SECONDS ]; do |
| 10 | + sleep 5 |
| 11 | + ((ELAPSED += 5)) |
13 | 12 | done |
14 | 13 |
|
15 | | -if [ $ELAPSED -ge $TIMEOUT ]; then |
16 | | - echo "Timeout reached while waiting for Gala to start" >&2 |
| 14 | +if [ $ELAPSED -ge $TIMEOUT_SECONDS ]; then |
| 15 | + echo "Timeout reached while waiting for the required processes to start" >&2 |
17 | 16 | exit 1 |
18 | 17 | fi |
19 | 18 |
|
20 | | -# Get current DPI |
21 | | -export DISPLAY=":0" |
22 | | -DPI=$(xrdb -query | grep dpi | awk '{print $2}') |
| 19 | +# Get the active user based on the currently active graphical session |
| 20 | +ACTIVE_USER=$(who | grep -E '(:[0-9]+)' | awk '{print $1}' | head -n 1) |
| 21 | + |
| 22 | +if [[ -z "$ACTIVE_USER" ]]; then |
| 23 | + logger -t plymouth-hidpi "No active user with a graphical session." |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +USER_HOME=$(eval echo ~$ACTIVE_USER) # Get the home directory of the active user |
| 28 | +MONITORS_XML="$USER_HOME/.config/monitors.xml" |
| 29 | + |
| 30 | +if [[ ! -f "$MONITORS_XML" ]]; then |
| 31 | + logger -t plymouth-hidpi "Monitors XML file not found for user: $PRIMARY_USER" |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +PRIMARY_MONITOR_SCALE=$(awk ' |
| 36 | + /<primary>yes<\/primary>/ {print prev; exit} |
| 37 | + {prev=$0} |
| 38 | +' $MONITORS_XML | grep -oP '<scale>\K[0-9]+') |
| 39 | +# Scale=2 means 2x resolution ('Retina Display' in Apple computers) |
| 40 | +logger -t plymouth-hidpi "Primary monitor scale: '$PRIMARY_MONITOR_SCALE'" |
23 | 41 |
|
24 | 42 | create_config() { |
25 | 43 | cat <<EOF > "$CONFIG_FILE" |
|
30 | 48 | } |
31 | 49 |
|
32 | 50 | apply_hidpi_setting() { |
33 | | - if [[ "$DPI" -ge "$HIDPI_THRESHOLD" ]]; then |
| 51 | + if [[ "$PRIMARY_MONITOR_SCALE" -eq 2 ]]; then |
34 | 52 | if [[ ! -f "$CONFIG_FILE" ]]; then |
35 | 53 | create_config |
36 | 54 |
|
|
0 commit comments