From cf0e877dc90d26ba03a4dee268145d0e5e49e61b Mon Sep 17 00:00:00 2001 From: Fritz Date: Fri, 29 May 2026 16:49:41 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20Discord=20mute=20toggle=20fails=20on=20s?= =?UTF-8?q?econd=20press=20=E2=80=94=20use=20--name=20search=20for=20main?= =?UTF-8?q?=20window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bin/plugin.cjs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/discord-plugin/com.discord.streamdeck.sdPlugin/bin/plugin.cjs b/discord-plugin/com.discord.streamdeck.sdPlugin/bin/plugin.cjs index a7093a5..893708c 100644 --- a/discord-plugin/com.discord.streamdeck.sdPlugin/bin/plugin.cjs +++ b/discord-plugin/com.discord.streamdeck.sdPlugin/bin/plugin.cjs @@ -37,19 +37,27 @@ try { /** * Find Discord's X11 window ID. * Returns the window ID string, or null if Discord is not running / not found. + * + * Strategy: search by window NAME "Discord" first. Discord's main application + * window has a title of "Discord" (or "Discord - #channel"), while the GPU + * process, renderer sub-windows, and utility windows have empty or internal + * titles that do NOT contain "Discord". Taking the first (oldest) result from + * the name search reliably returns the main window across all button presses, + * even after Discord briefly gains and loses focus (which can cause it to + * create additional sub-windows, making a last-ID strategy unreliable). */ function getDiscordWindowId() { - // Try by window class first (most reliable) - const byClass = spawnSync('xdotool', ['search', '--class', 'discord'], { stdio: 'pipe' }) - if (byClass.status === 0) { - const ids = byClass.stdout.toString().trim().split('\n').filter(Boolean) - if (ids.length > 0) return ids[ids.length - 1] - } - // Fallback: search by window title + // Primary: name search — matches only the main Discord application window const byName = spawnSync('xdotool', ['search', '--name', 'Discord'], { stdio: 'pipe' }) if (byName.status === 0) { const ids = byName.stdout.toString().trim().split('\n').filter(Boolean) - if (ids.length > 0) return ids[ids.length - 1] + if (ids.length > 0) return ids[0] + } + // Fallback: class search — take the first (oldest/main) window + const byClass = spawnSync('xdotool', ['search', '--class', 'discord'], { stdio: 'pipe' }) + if (byClass.status === 0) { + const ids = byClass.stdout.toString().trim().split('\n').filter(Boolean) + if (ids.length > 0) return ids[0] } console.warn(`[${pluginUUID}] Could not find Discord window — sending key to focused window instead`) return null