Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/win32/window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,32 @@ bool focusWindow(const WindowHandle windowHandle) {
const auto allowSetForeground = AllowSetForegroundWindow(processId);
const auto setTopLevel = BringWindowToTop(hWnd);
const auto setForeground = SetForegroundWindow(hWnd);
const auto setActive = SetActiveWindow(hWnd);

// Try to set the window to the foreground
return allowSetForeground && setTopLevel && setForeground;
if (allowSetForeground && setTopLevel && setForeground && setActive)
{
return true;
}

// get the current thread id
DWORD dwCurrentThread = GetCurrentThreadId();
DWORD dwFGThread = GetWindowThreadProcessId(GetForegroundWindow(), NULL);

// attach the input to the current thread
AttachThreadInput(dwCurrentThread, dwFGThread, TRUE);

SetForegroundWindow(hWnd);
SetCapture(hWnd);
SetFocus(hWnd);
SetActiveWindow(hWnd);
EnableWindow(hWnd, TRUE);

// detach the input from the current thread
AttachThreadInput(dwCurrentThread, dwFGThread, FALSE);

// check if the window is now in the foreground
return GetForegroundWindow() == hWnd;
}
return false;
}
Expand Down