Restore wine access after program loses and regains focus.

This commit is contained in:
Storm Dragon committed 2026-10-12 04:17:31 -04:00
1 parent f40e471938
commit c3e981b4c2
12 files changed
+351 -2

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "foreground_focus.h"
#include "review_x11.h"
namespace {
struct Candidate {
HWND window = nullptr;
unsigned count = 0;
};
BOOL CALLBACK find_candidate(HWND window, LPARAM data) {
if (!IsWindowVisible(window) || !IsWindowEnabled(window) || IsIconic(window) ||
(GetWindowLongPtrW(window, GWL_EXSTYLE) & (WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE)) ||
!GetPropW(window, L"__wine_x11_whole_window"))
return TRUE;
auto &candidate = *reinterpret_cast<Candidate *>(data);
candidate.window = window;
return ++candidate.count < 2;
}
}
bool restore_virtual_desktop_focus() {
if (GetForegroundWindow() || !wine_x11_desktop_focused()) return false;
Candidate candidate;
EnumWindows(find_candidate, reinterpret_cast<LPARAM>(&candidate));
// Recheck focus after enumeration so a Linux/application transition cannot
// turn a recovery into activation of a background Wine application.
if (candidate.count != 1 || GetForegroundWindow() || !wine_x11_desktop_focused())
return false;
return wine_x11_restore_focus(candidate.window);
}