mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 21:35:59 +00:00
* fix: Red Dead Redemption 2 launches again, its Vulkan runtime installer is left to run droiddeck-seed-redists marked every process in every game's install script as already run, Red Dead Redemption 2's VulkanRT-1.1.108.0 installer included. Steam's compat config for the game says nativevulkanloader, so Proton loads vulkan-1.dll native only, and Khronos' loader is in the prefix only once that installer has run. Without it the Rockstar launcher starts RDR2.exe and it exits with STATUS_DLL_NOT_FOUND (0xc0000135) before it opens a window. A Vulkan runtime installer is now left out of the seeding, and a marker an earlier seeding wrote for one comes out of each prefix and Proton template once (dates kept), so the client runs the installer on the next launch. The installer finishes in a few seconds under FEX. * fix: Steam's screensaver no longer covers a running game The client's defaults show screensavers while a game runs, after 300 s on AC power without a button press - and a held stick or trigger is no press. Red Dead Redemption 2's intro runs longer than that: the slideshow covered the game, and the button that woke it reached the game too (B asked to quit to the desktop). Customization/Screensaver/WhileInGame is seeded "0" in config.vdf once, like the UI scale and native resolution, so turning it back on in Settings stays the user's choice. On the RedMagic: 18 minutes from the last button press through the intro and riding, focus never left the game and no screensaver was created. * fix: Rockstar's hidden launcher no longer takes cores from its game The Rockstar Games Launcher keeps drawing its Chromium interface (SocialClubHelper.exe: renderers, and a GPU process compositing through DXVK) for as long as the game runs, hidden behind it - and Wine passes Chromium's priorities on, so those threads ran above the game's (the GPU process at nice -10), across every core. With Red Dead Redemption 2 in front that was 1.3 to 2.5 cores under FEX for a page nobody sees. droiddeck-launcher-cores follows gamescope's focus from the agent's focus.json: while a game window has it, every SocialClubHelper thread runs on the last core of the slowest cluster at nice 19; when the launcher's own window has focus again each thread gets its own mask and priority back (also on exit). Stopping the helpers would not hold - proot resumes a stopped tracee. Started for Steam sessions; BL_LAUNCHER_CORES=0 turns it off. RedMagic, RDR2 all Low, riding at the thermal limit, same spot and session: released 46.5 fps, 1% low 27.5, p99 31.8 ms, CPU 89%, 2200 MHz; held 48.7 fps, 1% low 32.6, p99 27.6 ms, CPU 79%, 2638 MHz. * fix: sessions clean up what earlier ones left in /tmp The guest's /tmp is a directory in the rootfs that no boot ever empties, and Android ends sessions by killing them. Every session left a /tmp/mangohud.XXXXXXXX (mktemp, never removed), and the Steam client, its web helper, Chromium apps, dbus-run-session, AppImage runs and KDE their own temporary files and sockets: 1,422 entries on the RedMagic. mangoapp's config is now one fixed file rewritten each session, and the session's first pass sweeps each kind of leftover while nothing that could own one is running, with a single find. On the device that cleared 1,391 entries over two sessions, leaving 38.
215 lines
8.6 KiB
Python
Executable File
215 lines
8.6 KiB
Python
Executable File
#!/usr/bin/python3
|
|
"""Initialize Steam's own display settings once; subsequent choices belong to Steam.
|
|
|
|
The UI scale, and native resolution: the client treats our gamescope as an external display and,
|
|
unless "Enable Native Resolution on External Displays" is on, draws itself at 1920x1080 on any
|
|
larger output - a 2340x1080 session came up as 16:9 with bars. The session's size is already the
|
|
user's Resolution choice, so the client should use all of it.
|
|
|
|
And the screensaver over a running game. The client's defaults (steamui.so's settings descriptor)
|
|
show screensavers while a game runs, after 300 s on AC power with no button pressed - and a stick or
|
|
trigger held is no press. Red Dead Redemption 2's cutscenes run longer than that: the slideshow
|
|
covered the game, and the button that woke it reached the game as well (B asked to quit to the
|
|
desktop). Customization > Screensaver > "Show screensavers when playing a game" still turns it on."""
|
|
import math
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import sys
|
|
import tempfile
|
|
|
|
|
|
DISPLAY = "External: gamescope|||Windowed"
|
|
NATIVE_RESOLUTION = "EnableSteamNativeExternalResolution"
|
|
# screensaver_while_ingame: kept in config.vdf like the Gamescope settings, under this path.
|
|
SCREENSAVER_IN_GAME = ("Customization", "Screensaver", "WhileInGame")
|
|
TOKEN = re.compile(r'\s+|//[^\n]*|"(?:\\.|[^"\\])*"|[{}]')
|
|
|
|
|
|
class Block:
|
|
def __init__(self, pairs, end):
|
|
self.pairs = pairs
|
|
self.end = end
|
|
|
|
def get(self, name):
|
|
matches = [value for key, value in self.pairs if key.lower() == name.lower()]
|
|
if len(matches) > 1:
|
|
raise ValueError("duplicate UI setting")
|
|
return matches[0] if matches else None
|
|
|
|
|
|
def parse(text):
|
|
tokens = []
|
|
position = 0
|
|
for match in TOKEN.finditer(text):
|
|
if match.start() != position:
|
|
raise ValueError("invalid config.vdf")
|
|
position = match.end()
|
|
token = match.group()
|
|
if not token.isspace() and not token.startswith('//'):
|
|
tokens.append((token, match.start()))
|
|
if position != len(text):
|
|
raise ValueError("invalid config.vdf")
|
|
|
|
def block(index, nested=False):
|
|
pairs = []
|
|
while index < len(tokens):
|
|
token, offset = tokens[index]
|
|
if token == '}':
|
|
if not nested:
|
|
raise ValueError("unexpected closing brace")
|
|
return Block(pairs, offset), index + 1
|
|
if not token.startswith('"') or index + 1 == len(tokens):
|
|
raise ValueError("missing config value")
|
|
key = token[1:-1]
|
|
value = tokens[index + 1][0]
|
|
index += 2
|
|
if value == '{':
|
|
value, index = block(index, True)
|
|
elif value.startswith('"'):
|
|
value = value[1:-1]
|
|
else:
|
|
raise ValueError("invalid config value")
|
|
pairs.append((key, value))
|
|
if nested:
|
|
raise ValueError("unclosed config block")
|
|
return Block(pairs, len(text)), index
|
|
|
|
return block(0)[0]
|
|
|
|
|
|
def initial_scale(width, height):
|
|
# The Thor setting chosen on device at 1280x720 was 140% of its automatic scale.
|
|
# Adjust with canvas area so choosing a different session resolution keeps the UI usable.
|
|
if not 320 <= width <= 16384 or not 320 <= height <= 16384:
|
|
raise ValueError("invalid session size")
|
|
return 1.3281567096710205 * math.sqrt(width * height / (1280 * 720))
|
|
|
|
|
|
def seed_text(text, scale):
|
|
root = parse(text).get('InstallConfigStore')
|
|
if not isinstance(root, Block):
|
|
raise ValueError("missing InstallConfigStore")
|
|
ui = root.get('UI')
|
|
display = ui.get('display') if isinstance(ui, Block) else None
|
|
if ui is not None and not isinstance(ui, Block):
|
|
raise ValueError("invalid UI settings")
|
|
if display is not None and not isinstance(display, Block):
|
|
raise ValueError("invalid display settings")
|
|
if display is not None:
|
|
# Current describes the active display and is written even with automatic scaling.
|
|
# Named display entries are the user's saved choices, including a return to Auto.
|
|
if any(name.lower() != 'current' and isinstance(value, Block)
|
|
and value.get('ScaleFactor') is not None for name, value in display.pairs):
|
|
return text, False
|
|
entry = f'"{DISPLAY}"\n{{\n"ScaleFactor" "{scale:.9f}"\n}}\n'
|
|
if display is not None:
|
|
at, indent = display.end, 3
|
|
elif ui is not None:
|
|
entry = '"display"\n{\n' + entry + '}\n'
|
|
at, indent = ui.end, 2
|
|
else:
|
|
entry = '"UI"\n{\n"display"\n{\n' + entry + '}\n}\n'
|
|
at, indent = root.end, 1
|
|
# Insert only the new block; leave every existing byte, comment and credential untouched.
|
|
insertion = '\n' + '\n'.join('\t' * indent + line for line in entry.splitlines()) + '\n'
|
|
return text[:at] + insertion + text[at:], True
|
|
|
|
|
|
def seed_value(text, path, value):
|
|
"""InstallConfigStore/<path> = value, unless the client already has a value there (the
|
|
user's), adding only the blocks that are missing."""
|
|
root = parse(text).get('InstallConfigStore')
|
|
if not isinstance(root, Block):
|
|
raise ValueError("missing InstallConfigStore")
|
|
*sections, name = path
|
|
block, depth = root, 1
|
|
while sections:
|
|
child = block.get(sections[0])
|
|
if child is None:
|
|
break
|
|
if not isinstance(child, Block):
|
|
raise ValueError(f"invalid {sections[0]} settings")
|
|
block, depth = child, depth + 1
|
|
sections.pop(0)
|
|
if not sections and block.get(name) is not None:
|
|
return text, False
|
|
lines = [(len(sections), f'"{name}"\t\t"{value}"')]
|
|
for level, section in reversed(list(enumerate(sections))):
|
|
lines = [(level, f'"{section}"'), (level, '{')] + lines + [(level, '}')]
|
|
insertion = ''.join('\t' * (depth + level) + line + '\n' for level, line in lines)
|
|
# Before the line the block closes on, when it has one of its own; else beside the brace.
|
|
at = text.rfind('\n', 0, block.end) + 1
|
|
if text[at:block.end].strip():
|
|
at, insertion = block.end, '\n' + insertion
|
|
return text[:at] + insertion + text[at:], True
|
|
|
|
|
|
def seed_native_resolution(text):
|
|
return seed_value(text, ('Gamescope', NATIVE_RESOLUTION), '1')
|
|
|
|
|
|
def seed_no_screensaver_in_game(text):
|
|
return seed_value(text, SCREENSAVER_IN_GAME, '0')
|
|
|
|
|
|
def atomic_write(path, text):
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
fd, temporary = tempfile.mkstemp(prefix='.' + path.name, dir=path.parent)
|
|
try:
|
|
with os.fdopen(fd, 'w') as output:
|
|
output.write(text)
|
|
os.replace(temporary, path)
|
|
finally:
|
|
if os.path.exists(temporary):
|
|
os.unlink(temporary)
|
|
|
|
|
|
def initialize(steam_root, width, height):
|
|
scale = initial_scale(width, height)
|
|
return seed_once(steam_root, 'droiddeck-ui-scale-initialized', lambda text: seed_text(text, scale),
|
|
f'== steam: initial handheld UI scale {scale:.3f}')
|
|
|
|
|
|
def seed_once(steam_root, marker_name, seed, message):
|
|
"""Applies seed to config.vdf the first time only: the marker keeps a later choice - including
|
|
a return to the client's own default, which the client may store by dropping the key - the
|
|
user's."""
|
|
config = Path(steam_root) / 'config/config.vdf'
|
|
marker = config.with_name(marker_name)
|
|
if marker.exists():
|
|
return False
|
|
text = config.read_text() if config.exists() else '"InstallConfigStore"\n{\n}\n'
|
|
updated, changed = seed(text)
|
|
if changed:
|
|
atomic_write(config, updated)
|
|
print(message)
|
|
atomic_write(marker, '1\n')
|
|
return changed
|
|
|
|
|
|
def initialize_native_resolution(steam_root):
|
|
return seed_once(steam_root, 'droiddeck-native-resolution-initialized', seed_native_resolution,
|
|
'== steam: native resolution on the session display')
|
|
|
|
|
|
def initialize_screensaver(steam_root):
|
|
return seed_once(steam_root, 'droiddeck-screensaver-initialized', seed_no_screensaver_in_game,
|
|
'== steam: no screensaver over a running game')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
status = 0
|
|
try:
|
|
initialize(sys.argv[1], int(sys.argv[2]), int(sys.argv[3]))
|
|
except (OSError, ValueError, RecursionError) as error:
|
|
print('== steam: left UI scale unchanged: ' + str(error), file=sys.stderr)
|
|
status = 1
|
|
for what, step in (('native resolution', initialize_native_resolution), ('screensaver', initialize_screensaver)):
|
|
try:
|
|
step(sys.argv[1])
|
|
except (OSError, ValueError, RecursionError) as error:
|
|
print(f'== steam: left {what} unchanged: {error}', file=sys.stderr)
|
|
status = 1
|
|
sys.exit(status)
|