Skip to content

Commit d9bde3d

Browse files
committed
Support Wayland & X11 by reading the scaling factor from Gnome's monitors.xml file. Also respect get_option('bindir') for improved configuration handling.
1 parent 03cf5da commit d9bde3d

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

plymouth/meson.build

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Configure Plymouth for HiDPI screens
22
install_data(
33
'plymouth-hidpi.sh',
4-
install_dir: '/usr/local/bin',
4+
install_dir: get_option('bindir'),
55
install_mode: 'rwxr-xr-x'
66
)
77

8-
install_data(
9-
'plymouth-hidpi.service',
8+
configure_file(
9+
input: 'plymouth-hidpi.service.in',
10+
output: 'plymouth-hidpi.service',
11+
configuration: { 'BINDIR': join_paths(get_option('prefix'), get_option('bindir')) },
12+
install: true,
1013
install_dir: '/etc/systemd/system'
1114
)

plymouth/plymouth-hidpi.service.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=Configure Plymouth for HiDPI screens
3+
After=graphical.target
4+
Requires=graphical.target
5+
6+
[Service]
7+
Type=oneshot
8+
ExecStart="@BINDIR@/plymouth-hidpi.sh"
9+
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'
10+
11+
[Install]
12+
WantedBy=graphical.target

plymouth/plymouth-hidpi.sh

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
#!/bin/bash
22

33
CONFIG_FILE="/etc/plymouth/plymouthd.conf"
4-
HIDPI_THRESHOLD=180 # Min DPI of a HiDPI screen
54

6-
TIMEOUT=300 # Set the maximum wait time in seconds
5+
TIMEOUT_SECONDS=300 # Maximum wait time in seconds
76
ELAPSED=0
87

98
# 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))
1312
done
1413

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
1716
exit 1
1817
fi
1918

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'"
2341

2442
create_config() {
2543
cat <<EOF > "$CONFIG_FILE"
@@ -30,7 +48,7 @@ EOF
3048
}
3149

3250
apply_hidpi_setting() {
33-
if [[ "$DPI" -ge "$HIDPI_THRESHOLD" ]]; then
51+
if [[ "$PRIMARY_MONITOR_SCALE" -eq 2 ]]; then
3452
if [[ ! -f "$CONFIG_FILE" ]]; then
3553
create_config
3654

0 commit comments

Comments
 (0)