diff --git a/modules/home/battlenet.nix b/modules/home/battlenet.nix new file mode 100644 index 0000000..dca4230 --- /dev/null +++ b/modules/home/battlenet.nix @@ -0,0 +1,48 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; +let + cfg = config.modules.battlenet; + yq = "${pkgs.yq}/bin/yq"; + jq = "${pkgs.jq}/bin/jq"; +in +{ + config = mkIf cfg.enable { + # Battle.net is installed manually through Lutris, which creates the game + # config and wine prefix outside of Home Manager's control. The Lutris + # installer script writes HardwareAcceleration "false" (software rendering, + # which breaks Battle.net's CEF UI repainting under XWayland), so patch it + # and the game env after every rebuild. Re-run the rebuild after installing + # Battle.net for these tweaks to land. + home.activation.battlenetClientTweaks = hm.dag.entryAfter [ "writeBoundary" ] '' + shopt -s nullglob + for game in "$HOME"/.local/share/lutris/games/battlenet*.yml; do + prefix=$(${yq} -r '.game.prefix // ""' "$game" 2>/dev/null) || continue + + for configFile in "$prefix"/drive_c/users/*/AppData/Roaming/Battle.net/Battle.net.config; do + [ -e "$configFile" ] || continue + if [ "$(${jq} -r '.Client.HardwareAcceleration // ""' "$configFile" 2>/dev/null)" != "true" ]; then + ${jq} '.Client.HardwareAcceleration = "true"' "$configFile" > "$configFile.tmp" && mv "$configFile.tmp" "$configFile" + fi + done + + # GE-Proton's Wayland driver breaks Battle.net's CEF window sizing and + # painting, and Xalia misrenders the client, so pin both off. + if [ "$(${yq} -r '.system.env.PROTON_USE_XALIA // ""' "$game" 2>/dev/null)" != "0" ]; then + ${yq} --in-place --yaml-output '.system.env.PROTON_USE_XALIA = "0"' "$game" + fi + if [ "$(${yq} -r '.system.env.WINE_SIMULATE_WRITECOPY // ""' "$game" 2>/dev/null)" != "1" ]; then + ${yq} --in-place --yaml-output '.system.env.WINE_SIMULATE_WRITECOPY = "1"' "$game" + fi + if [ -n "$(${yq} -r '.system.env.PROTON_ENABLE_WAYLAND // ""' "$game" 2>/dev/null)" ]; then + ${yq} --in-place --yaml-output 'del(.system.env.PROTON_ENABLE_WAYLAND)' "$game" + fi + done + shopt -u nullglob + ''; + }; +} diff --git a/modules/home/default.nix b/modules/home/default.nix index ad45815..3569945 100644 --- a/modules/home/default.nix +++ b/modules/home/default.nix @@ -3,6 +3,7 @@ }: { imports = [ + ./battlenet.nix ./direnv.nix ./discord.nix ./dictation.nix