fix(bionic): run games on Steam's game X server; focus check on gamescope's first server

DroidDeck's gamescope runs two X servers (--xwayland-count 2): Steam's UI on :0 and games on
STEAM_GAME_DISPLAY_0, which Steam passes to the tool as DISPLAY. launch.sh forced :0, so opening Steam's menu
took X focus from the game; with no Wine desktop, Wine then deactivated it and DiRT Showdown left fullscreen
and saved an 800x600 window. launch.sh now keeps Steam's DISPLAY (and GAMESCOPE_WAYLAND_DISPLAY) and logs it.

gstag tags windows on that display; gamescope publishes GAMESCOPE_FOCUSED_APP and reads
GAMESCOPECTRL_BASELAYER_APPID on its first server only, so gstag reads and writes those through a second
connection to :0.
This commit is contained in:
The412Banner committed 2026-11-16 21:17:15 -05:00
1 parent 1e659a5ea0
commit 7e4ed9b7df
2 files changed
+47 -20

No files matched your search

+39 -16
View File
@@ -2,6 +2,8 @@
// STEAM_GAME=<appid>, so gamescope treats a game started outside Steam's process tree
// as the game (stand-in until a bionic winex11 sets STEAM_GAME itself).
// Usage: gstag <display> <appid> <match> <seconds> [stop when this pid exits]
// gamescope publishes focus (GAMESCOPE_FOCUSED_APP) and reads GAMESCOPECTRL_BASELAYER_APPID on its first X server
// (:0, Steam's); with several (DroidDeck: games on :1) those two are read and written there.
// If gamescope still focuses another app 8 s after the tag, it sets GAMESCOPECTRL_BASELAYER_APPID once to
// <appid>,769 (what Steam writes when it shows a game); Steam can change it again later (e.g. the Steam button).
#define _GNU_SOURCE
@@ -123,6 +125,25 @@ static void set_card(uint32_t win, uint32_t prop, uint32_t value) {
wr(req, sizeof req);
}
// Connects to display :<disp> (abstract socket) and returns the socket, its root window in *root; -1 on failure.
static int x_connect(int disp, uint32_t *root) {
struct sockaddr_un sa = {.sun_family = AF_UNIX};
int n = snprintf(sa.sun_path + 1, sizeof sa.sun_path - 1, "/tmp/.X11-unix/X%d", disp);
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (connect(fd, (struct sockaddr *)&sa, (socklen_t)(offsetof(struct sockaddr_un, sun_path) + 1 + n))) {
printf("gstag: connect to :%d failed: %s\n", disp, strerror(errno)); close(fd); return -1;
}
uint8_t setup[12] = {'l', 0, 11, 0};
if (wr(setup, sizeof setup) || rd(rbuf, 8)) { close(fd); return -1; }
uint32_t extra = *(uint16_t *)(rbuf + 6) * 4u;
if (extra > sizeof rbuf - 8 || rd(rbuf + 8, extra) || rbuf[0] != 1) { printf("gstag: :%d refused\n", disp); close(fd); return -1; }
uint8_t *d = rbuf + 8;
uint16_t vlen = *(uint16_t *)(d + 16);
uint8_t nformats = d[21];
*root = *(uint32_t *)(d + 32 + pad4(vlen) + 8u * nformats);
return fd;
}
int main(int argc, char **argv) {
if (argc < 5) { fprintf(stderr, "usage: %s <display> <appid> <match> <seconds> [pid]\n", argv[0]); return 2; }
setvbuf(stdout, NULL, _IONBF, 0);
@@ -132,20 +153,16 @@ int main(int argc, char **argv) {
int seconds = atoi(argv[4]);
pid_t watch = argc > 5 ? (pid_t)atoi(argv[5]) : 0;
struct sockaddr_un sa = {.sun_family = AF_UNIX};
int n = snprintf(sa.sun_path + 1, sizeof sa.sun_path - 1, "/tmp/.X11-unix/X%d", disp);
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (connect(fd, (struct sockaddr *)&sa, (socklen_t)(offsetof(struct sockaddr_un, sun_path) + 1 + n))) {
printf("gstag: connect failed: %s\n", strerror(errno)); return 3;
uint32_t root, croot;
int tfd = x_connect(disp, &root), cfd = tfd;
if (tfd < 0) return 3;
croot = root;
if (disp != 0) {
int c = x_connect(0, &croot);
if (c >= 0) cfd = c;
else croot = root;
}
uint8_t setup[12] = {'l', 0, 11, 0};
if (wr(setup, sizeof setup) || rd(rbuf, 8)) return 4;
uint32_t extra = *(uint16_t *)(rbuf + 6) * 4u;
if (extra > sizeof rbuf - 8 || rd(rbuf + 8, extra) || rbuf[0] != 1) { printf("gstag: refused\n"); return 5; }
uint8_t *d = rbuf + 8;
uint16_t vlen = *(uint16_t *)(d + 16);
uint8_t nformats = d[21];
uint32_t root = *(uint32_t *)(d + 32 + pad4(vlen) + 8u * nformats);
fd = tfd;
uint32_t a_game = intern("STEAM_GAME");
uint8_t cwa[16] = {2, 0, 4, 0}; // ChangeWindowAttributes(root, CWEventMask=SubstructureNotify)
@@ -165,9 +182,11 @@ int main(int argc, char **argv) {
}
printf("gstag: watching display %d for WM_CLASS ~ \"%s\" -> STEAM_GAME=%u\n", disp, match, appid);
fd = cfd; // atoms belong to the server they are interned on
uint32_t a_apps = intern("GAMESCOPE_FOCUSABLE_APPS");
uint32_t a_focus = intern("GAMESCOPE_FOCUSED_APP");
uint32_t a_ctrl = intern("GAMESCOPECTRL_BASELAYER_APPID");
fd = tfd;
time_t tagged_at = 0; int focus_checked = 0;
time_t end = time(NULL) + seconds, next_status = time(NULL) + 3;
while (time(NULL) < end) {
@@ -176,9 +195,10 @@ int main(int argc, char **argv) {
printf("status:");
uint32_t props[3] = {a_apps, a_focus, a_ctrl};
const char *names[3] = {"focusable", "focused", "baselayer"};
fd = cfd;
for (int k = 0; k < 3; k++) {
uint8_t gp[24] = {20, 0, 6, 0};
*(uint32_t *)(gp + 4) = root;
*(uint32_t *)(gp + 4) = croot;
*(uint32_t *)(gp + 8) = props[k];
*(uint32_t *)(gp + 20) = 64;
if (wr(gp, sizeof gp) == 0 && reply() == 1) {
@@ -188,6 +208,7 @@ int main(int argc, char **argv) {
printf("]");
}
}
fd = tfd;
for (int i = 0; i < ntagged; i++) {
uint8_t ga[8] = {3, 0, 2, 0}; // GetWindowAttributes
*(uint32_t *)(ga + 4) = tagged[i];
@@ -202,12 +223,14 @@ int main(int argc, char **argv) {
}
if (tagged_at && !focus_checked && time(NULL) - tagged_at >= 8) {
focus_checked = 1;
uint32_t f = first_card(root, a_focus);
fd = cfd;
uint32_t f = first_card(croot, a_focus);
if (f != appid) {
uint32_t ids[2] = {appid, 769};
set_cards(root, a_ctrl, ids, 2);
set_cards(croot, a_ctrl, ids, 2);
printf("gstag: focus was %u, not %u, 8 s after the tag; set GAMESCOPECTRL_BASELAYER_APPID=%u,769\n", f, appid, appid);
} else printf("gstag: %u has focus\n", appid);
fd = tfd;
}
if (watch && kill(watch, 0) != 0 && errno == ESRCH) { printf("gstag: pid %d gone, stopping\n", watch); break; }
for (int i = 0; i < npending; ) {
+8 -4
View File
@@ -17,7 +17,7 @@ mkdir -p "$COMPAT"
LOG=$COMPAT/droiddeck-bionic.log
[ "$verb" = runinprefix ] || { [ -f "$LOG" ] && mv -f "$LOG" "$LOG.1"; }
exec >> "$LOG" 2>&1
echo "$(date +%H:%M:%S) $verb $EXE ($VERSION, uid $(id -u))"
echo "$(date +%H:%M:%S) $verb $EXE ($VERSION, uid $(id -u), DISPLAY ${DISPLAY:-unset})"
# Keep Steam's game identity and DroidDeck's input/display settings; drop the glibc guest's environment.
for v in $(env | sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p'); do
@@ -25,11 +25,14 @@ for v in $(env | sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p'); do
SteamAppId|SteamGameId|SteamOverlayGameId|SteamClientLaunch|SteamEnv|SteamAppUser|SteamUser|STEAM_COMPAT_*) ;;
ANDROID_*|BOOTCLASSPATH|DEX2OATBOOTCLASSPATH|SYSTEMSERVERCLASSPATH|EXTERNAL_STORAGE|ASEC_MOUNTPOINT) ;;
FAKE_*|SDL_*|BL_WIDTH|BL_HEIGHT|BL_VK_DRIVER|WINEDLLOVERRIDES) ;;
DISPLAY|GAMESCOPE_WAYLAND_DISPLAY) ;;
*) unset "$v" 2>/dev/null ;;
esac
done
export PATH=/system/bin:/system/xbin
export HOME=$COMPAT WINEPREFIX=$COMPAT/pfx TMPDIR=$ROOTFS/tmp LANG=en_US.UTF-8 DISPLAY=:0
# DISPLAY: the X server Steam gives games. DroidDeck's gamescope runs two (Steam's UI on :0, games on
# STEAM_GAME_DISPLAY_0), so Steam's menus do not take X focus from the game.
export HOME=$COMPAT WINEPREFIX=$COMPAT/pfx TMPDIR=$ROOTFS/tmp LANG=en_US.UTF-8 DISPLAY=${DISPLAY:-:0}
# Proton's user name: the same C:\users\steamuser (saves, settings) as DroidDeck-Proton in a shared prefix
export USER=steamuser LOGNAME=steamuser
@@ -43,7 +46,7 @@ echo "driver $DRVDIR"
RTD=$APP/.wayland-rt
export VK_ICD_FILENAMES=$PACK/adapter/icd.json ADRENOTOOLS_DRIVER_PATH=$DRVDIR/ ADRENOTOOLS_HOOKS_PATH=$PACK/lib
export ADRENOTOOLS_DRIVER_NAME=libvulkan_freedreno.so
export VK_ADD_IMPLICIT_LAYER_PATH=$PACK/layer ENABLE_GAMESCOPE_WSI=1 GAMESCOPE_WAYLAND_DISPLAY=gamescope-0
export VK_ADD_IMPLICIT_LAYER_PATH=$PACK/layer ENABLE_GAMESCOPE_WSI=1 GAMESCOPE_WAYLAND_DISPLAY=${GAMESCOPE_WAYLAND_DISPLAY:-gamescope-0}
export XDG_RUNTIME_DIR=$RTD DROIDDECK_WSI_BYPASS_CHECK_MS=100 GAMESCOPE_WSI_FORCE_BYPASS=1
[ -e "$RTD/droiddeck-gamescope-limiter" ] && export GAMESCOPE_LIMITER_FILE=$RTD/droiddeck-gamescope-limiter
@@ -155,7 +158,8 @@ WP=$!
# never shows them.
GT=
if [ "${SteamAppId:-0}" != 0 ]; then
"$LINKER" "$PACK/bin/gstag" 0 "$SteamAppId" .exe 86400 > "$COMPAT/gstag.log" 2>&1 &
XD=${DISPLAY#*:}; XD=${XD%%.*}
"$LINKER" "$PACK/bin/gstag" "${XD:-0}" "$SteamAppId" .exe 86400 > "$COMPAT/gstag.log" 2>&1 &
GT=$!
fi
trap 'echo "$(date +%H:%M:%S) stopped by Steam"; [ -n "$GT" ] && kill $GT 2>/dev/null; stop_wine; exit 0' TERM INT HUP