Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions bin/omarchy-launch-battlenet
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ if [[ ! -f $LAUNCHER ]]; then
exit 1
fi

# Hyprland leaves XWayland apps unscaled (xwayland:force_zero_scaling), and Wine
# reads its DPI from the prefix registry once at startup, so match it to the
# focused monitor's scale on every launch. Skipped while the prefix is running:
# the running launcher ignores it, and wineserver rewrites user.reg on exit.
prefix_running() {
local pid prefix
for pid in $(pgrep -x wineserver); do
prefix=$(tr '\0' '\n' </proc/"$pid"/environ 2>/dev/null | sed -n 's/^WINEPREFIX=//p')
[[ -n $prefix && $(realpath "$prefix" 2>/dev/null) == "$(realpath "$PREFIX")" ]] && return 0
done
return 1
}

match_dpi_to_monitor_scale() {
local scale dpi
scale=$(hyprctl monitors -j 2>/dev/null | jq -r '.[] | select(.focused == true).scale')
[[ $scale =~ ^[0-9]+(\.[0-9]+)?$ ]] || return 0
dpi=$(awk -v scale="$scale" 'BEGIN { printf "%d", scale * 96 + 0.5 }')
sed -i "s/^\"LogPixels\"=dword:[0-9a-f]\{8\}$/\"LogPixels\"=dword:$(printf '%08x' "$dpi")/" "$PREFIX/user.reg"
}

if ! prefix_running; then
match_dpi_to_monitor_scale
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
fi

env_args=(
WINEPREFIX="$PREFIX"
PROTONPATH=GE-Proton
Expand Down
71 changes: 71 additions & 0 deletions test/shell.d/launch-battlenet-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

tmp_dir="$(mktemp -d)"
wineserver_pid=""
trap '[[ -n $wineserver_pid ]] && kill "$wineserver_pid" 2>/dev/null; rm -rf "$tmp_dir"' EXIT

mkdir -p "$tmp_dir/bin" "$tmp_dir/home"
export TEST_LOG="$tmp_dir/log"
export PATH="$tmp_dir/bin:$PATH"
export HOME="$tmp_dir/home"

prefix="$HOME/Games/battlenet"
mkdir -p "$prefix/drive_c/Program Files (x86)/Battle.net"
touch "$prefix/drive_c/Program Files (x86)/Battle.net/Battle.net Launcher.exe"
# umu points WINEPREFIX at pfx/, a link back to the prefix itself.
ln -s . "$prefix/pfx"

# Wine's default 96 DPI, under both keys a prefix carries it in.
write_registry() {
cat >"$prefix/user.reg" <<'REG'
[Control Panel\\Desktop] 1793676771
"LogPixels"=dword:00000060
"MenuShowDelay"="400"

[Software\\Wine\\Fonts] 1793677064
"LogPixels"=dword:00000060
REG
}

cat >"$tmp_dir/bin/hyprctl" <<SCRIPT
#!/bin/bash
printf '[{"name":"DP-1","focused":false,"scale":1},{"name":"HDMI-A-1","focused":true,"scale":%s}]\n' "\$(cat "$tmp_dir/scale")"
SCRIPT
cat >"$tmp_dir/bin/umu-run" <<'SCRIPT'
#!/bin/bash
printf 'umu-run:%s\n' "$*" >>"$TEST_LOG"
SCRIPT
chmod +x "$tmp_dir/bin/hyprctl" "$tmp_dir/bin/umu-run"

# A fractional scale rounds to the nearest DPI: 1.6 x 96 = 153.6, so 154.
write_registry
echo 1.6 >"$tmp_dir/scale"
"$ROOT/bin/omarchy-launch-battlenet"

[[ $(grep -c '^"LogPixels"=dword:0000009a$' "$prefix/user.reg") == "2" ]] ||
fail "Battle.net launch matches the DPI to the focused monitor's scale" "$(cat "$prefix/user.reg")"
grep -q '^"MenuShowDelay"="400"$' "$prefix/user.reg" ||
fail "Battle.net launch matches the DPI to the focused monitor's scale" "other registry values changed"
grep -q '^umu-run:.*Battle.net Launcher.exe$' "$TEST_LOG" ||
fail "Battle.net launch matches the DPI to the focused monitor's scale" "launcher never started"
pass "Battle.net launch matches the DPI to the focused monitor's scale"

# While the prefix's wineserver runs, the registry is its to write back on
# exit, so the launch leaves it alone and still hands off to the launcher.
ln -s "$(command -v sleep)" "$tmp_dir/wineserver"
WINEPREFIX="$prefix/pfx/" "$tmp_dir/wineserver" 60 &
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
wineserver_pid=$!
write_registry
echo 2 >"$tmp_dir/scale"
: >"$TEST_LOG"
"$ROOT/bin/omarchy-launch-battlenet"

[[ $(grep -c '^"LogPixels"=dword:00000060$' "$prefix/user.reg") == "2" ]] ||
fail "Battle.net launch leaves a running prefix's DPI alone" "$(cat "$prefix/user.reg")"
grep -q '^umu-run:.*Battle.net Launcher.exe$' "$TEST_LOG" ||
fail "Battle.net launch leaves a running prefix's DPI alone" "launcher never started"
pass "Battle.net launch leaves a running prefix's DPI alone"
Loading