Show a tray warning when held input blocks LAN switching

Refs #227
This commit is contained in:
agrynco committed 2026-12-01 22:51:41 +02:00
1 parent 86346df08e
commit f76796c7ea
6 files changed
+109 -25

No files matched your search

+36 -11
View File
@@ -80,28 +80,51 @@ void chooseInputAction(HWND resident, DWORD pid, const wchar_t *expected)
}
}
bool trayIconMatchesInput(HICON icon, bool active)
namespace {
template<class Check> bool renderedTrayIconMatches(HICON icon, int size, Check check)
{
HDC dc = CreateCompatibleDC(nullptr);
HBITMAP bitmap = CreateBitmap(16, 16, 1, 32, nullptr);
HBITMAP bitmap = CreateBitmap(size, size, 1, 32, nullptr);
bool matches = false;
if (dc && bitmap) {
const auto previous = SelectObject(dc, bitmap);
if (icon && DrawIconEx(dc, 0, 0, icon, 16, 16, 0, nullptr, DI_NORMAL)) {
const auto tile = GetPixel(dc, 2, 8);
const auto white = RGB(255, 255, 255);
const auto gap = GetPixel(dc, 8, 8);
// The active keycap is purple. The pause glyph has two white strokes with a gap.
matches = active ? GetBValue(tile) > GetRValue(tile) + 70 :
GetPixel(dc, 5, 8) == white && GetPixel(dc, 10, 8) == white &&
GetRValue(gap) < 160 && std::abs(GetBValue(gap) - GetRValue(gap)) < 32;
}
if (icon && DrawIconEx(dc, 0, 0, icon, size, size, 0, nullptr, DI_NORMAL)) matches = check(dc);
SelectObject(dc, previous);
}
if (bitmap) DeleteObject(bitmap);
if (dc) DeleteDC(dc);
return matches;
}
}
bool trayIconMatchesInput(HICON icon, bool active)
{
return renderedTrayIconMatches(icon, 16, [active](HDC dc) {
const auto tile = GetPixel(dc, 2, 8);
const auto white = RGB(255, 255, 255);
const auto gap = GetPixel(dc, 8, 8);
// The active keycap is purple. The pause glyph has two white strokes with a gap.
return active ? GetBValue(tile) > GetRValue(tile) + 70 :
GetPixel(dc, 5, 8) == white && GetPixel(dc, 10, 8) == white &&
GetRValue(gap) < 160 && std::abs(GetBValue(gap) - GetRValue(gap)) < 32;
});
}
bool trayIconMatchesLanBadge(HICON icon, int size, bool blocked)
{
return renderedTrayIconMatches(icon, size, [=](HDC dc) {
if (!blocked)
{
const int center = size - 1 - 3 * size / 16;
return GetPixel(dc, center, center) == RGB(69, 213, 140);
}
const int center = size - 1 - size / 4;
const auto amber = RGB(255, 196, 87), ink = RGB(36, 36, 36);
return GetPixel(dc, center - size / 8, center) == amber &&
GetPixel(dc, center, center) == ink && GetPixel(dc, center, center + 1) == amber &&
GetPixel(dc, center, center + size / 8) == ink;
});
}
int testInputPause()
{
@@ -129,6 +152,7 @@ int testInputPause()
return resident && query(resident, ProbeInputState) == 1;
}, "resident did not start with both hooks and shortcuts");
require(query(resident, ProbeTrayIcon, TRUE), "active tray icon missing at startup");
require(query(resident, ProbeTrayBlock), "tray shows a distinct warning during a LAN handoff block and restores green afterward");
constexpr UINT mods = MOD_CONTROL | MOD_SHIFT;
require(!RegisterHotKey(nullptr, 1, mods, VK_F23) && GetLastError() == ERROR_HOTKEY_ALREADY_REGISTERED,
"Files shortcut should be owned by resident before pause");
@@ -136,6 +160,7 @@ int testInputPause()
until([&] { return query(resident, ProbeInputState) == 2; },
"pause did not release both hooks and bindings and cancel the queued snippet");
require(query(resident, ProbeTrayIcon), "pause bars missing after pause");
require(query(resident, ProbeTrayBlock), "the handoff warning does not cover the paused tray icon");
require(RegisterHotKey(nullptr, 1, mods, VK_F23), "another process could not acquire Files shortcut");
require(query(resident, ProbeInputState, 1) == 2, "settings, layout reload or IPC restarted input");
chooseInputAction(resident, child.dwProcessId, L"Resume &input processing");