Skip to content

Commit 9168f4c

Browse files
committed
修复切换桌面图标闪烁问题
1 parent 96909e1 commit 9168f4c

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

notes/dev.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
`VirtualDesktopSwitcher::ActivateTopWindowOnMonitor(HMONITOR hMon)`
1616

17-
- **跨屏**`MouseFocus` 钩子检测到显示器切换 → `SendInput(MOUSEEVENTF_MOVE)` + `ActivateTopWindowOnMonitor(hMon)`
18-
- **切桌面**`OnDesktopSwitch``SwitchToDesktop``ActivateTopWindowOnMonitor(nullptr)`(内部自动获取光标位置)
19-
20-
`AllowSetForegroundWindow(ASFW_ANY)` 内置在 `ActivateWindow` 中(`src/util/Utils.cpp`),调用方无需关心前台锁。
21-
17+
- `ActivateTopWindowOnMonitor` 内部无条件调用 `SendInput(MOUSEEVENTF_MOVE)` 重置输入来源,绕过 Alt 后前台锁限制
18+
- **跨屏**`MouseFocus` 钩子检测显示器切换 → `ActivateTopWindowOnMonitor(hMon)`
19+
- **切桌面**`OnDesktopSwitch``SwitchToDesktop``ActivateTopWindowOnMonitor(nullptr)`(自动获取光标位置)
20+
- `AllowSetForegroundWindow(ASFW_ANY)` 内置在 `ActivateWindow` 中(`src/util/Utils.cpp`),调用方无需关心前台锁
2221

2322
| 问题 | 方案 |
2423
|---|---|

src/core/Application.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,6 @@ bool Application::Initialize() {
390390
}
391391

392392
m_mouseFocus->SetActivateFn([this](HMONITOR hMon) {
393-
INPUT input{.type = INPUT_MOUSE,
394-
.mi = {.dwFlags = MOUSEEVENTF_MOVE}};
395-
SendInput(1, &input, sizeof(input));
396393
VirtualDesktopSwitcher::ActivateTopWindowOnMonitor(hMon);
397394
});
398395
m_mouseFocus->SetEnabled(m_indicatorCfg.autoFocus);

src/core/VirtualDesktopSwitcher.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ bool VirtualDesktopSwitcher::ActivateTopWindowOnMonitor(HMONITOR hMon) {
191191
return false;
192192
}
193193
}
194+
195+
INPUT input{.type = INPUT_MOUSE,
196+
.mi = {.dwFlags = MOUSEEVENTF_MOVE}};
197+
SendInput(1, &input, sizeof(input));
198+
194199
HWND hwnd = FindTopWindowOnMonitor(hMon);
195200
if (hwnd == nullptr || hwnd == GetShellWindow()) {
196201
Log(L"[DEBUG] ActivateTopWindowOnMonitor: no window");

0 commit comments

Comments
 (0)