Skip to content

Commit 439d370

Browse files
G3darclaude
andcommitted
Fix: Ultra-aggressive window activation for Stream Deck integration
This release fixes the window activation behavior when using Stream Deck hardware buttons. Previously, windows would activate but not reliably come to the foreground, especially when multiple windows from other applications (e.g., Cursor) were on top. Changes: - Enhanced BringToFrontWindowHandle() to use HWND_TOPMOST technique - Temporarily sets target window as topmost to force Z-order priority - Immediately removes topmost flag to prevent always-on-top behavior - Fixed MonsterDeck.StreamDeck.csproj to use correct AssemblyName - Fixed package.bat to reference monsterdeck.iss instead of appswitcher.iss - Updated version to 0.1.2 - Added test-ipc.ps1 for IPC debugging This ensures identical window activation behavior between MonsterDeck UI clicks and Stream Deck button presses, even with many windows from other applications in front. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ce18403 commit 439d370

File tree

6 files changed

+46
-2
lines changed

6 files changed

+46
-2
lines changed

apps/MonsterDeck.StreamDeck/MonsterDeck.StreamDeck.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8+
<AssemblyName>AppSwitcher.StreamDeck</AssemblyName>
89
</PropertyGroup>
910

1011
<ItemGroup>

apps/MonsterDeck/MainWindow.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,20 @@ public bool ActivateSlot(int slotIndex)
12341234
if (string.IsNullOrWhiteSpace(slot.TargetPath))
12351235
return false;
12361236

1237+
// Bring MonsterDeck to foreground first to gain foreground privilege
1238+
// This is critical for IPC-triggered activations (e.g., from Stream Deck)
1239+
try
1240+
{
1241+
var myHandle = new WindowInteropHelper(this).Handle;
1242+
if (myHandle != IntPtr.Zero)
1243+
{
1244+
// Use the same aggressive activation we use for target windows
1245+
ShellHelpers.BringToFrontWindowHandle(myHandle);
1246+
System.Threading.Thread.Sleep(100); // Increased delay to ensure Windows grants foreground privilege
1247+
}
1248+
}
1249+
catch { }
1250+
12371251
// Try to find and activate existing window
12381252
if (slot.ProcessId is int pid || slot.Hwnd.HasValue)
12391253
{

apps/MonsterDeck/ShellHelpers.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ public static bool BringToFrontWindowHandle(IntPtr hWnd)
111111
BringWindowToTop(hWnd);
112112
SetForegroundWindow(hWnd);
113113
SetFocus(hWnd);
114+
115+
// ULTRA-AGGRESSIVE: Temporarily make window topmost to force it above all others
116+
// This ensures the window comes to front even when many other windows are on top
117+
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
118+
// Immediately remove topmost flag so window doesn't stay always-on-top
119+
SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
120+
114121
return true;
115122
}
116123
finally

installer/monsterdeck.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define MyAppName "MonsterDeck"
55
#ifndef MyAppVersion
6-
#define MyAppVersion "0.1.1"
6+
#define MyAppVersion "0.1.2"
77
#endif
88
#define MyAppPublisher "G3dar"
99
#define MyAppURL "https://github.com/G3dar/worktools"

package.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if not exist "%ISCC%" (
3131

3232
echo [3/3] Compiling installer...
3333
pushd installer
34-
"%ISCC%" appswitcher.iss || (
34+
"%ISCC%" monsterdeck.iss || (
3535
popd
3636
echo Inno Setup compilation failed.
3737
exit /b 1

test-ipc.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
$pipeName = "MonsterDeck_IPC"
2+
try {
3+
$pipeClient = New-Object System.IO.Pipes.NamedPipeClientStream(".", $pipeName, [System.IO.Pipes.PipeDirection]::InOut)
4+
$pipeClient.Connect(3000)
5+
$writer = New-Object System.IO.StreamWriter($pipeClient)
6+
$writer.AutoFlush = $true
7+
$reader = New-Object System.IO.StreamReader($pipeClient)
8+
9+
# Send PING command
10+
$writer.WriteLine("PING")
11+
$response = $reader.ReadLine()
12+
13+
Write-Host "SUCCESS: Connected to MonsterDeck IPC"
14+
Write-Host "Response: $response"
15+
16+
$pipeClient.Close()
17+
exit 0
18+
} catch {
19+
Write-Host "FAILED: Could not connect to MonsterDeck IPC"
20+
Write-Host "Error: $_"
21+
exit 1
22+
}

0 commit comments

Comments
 (0)