Merge pull request 'Prepare KSwitcher v0.8.12 with LAN input recovery' (#228) from codex/release-v0.8.12 into prerelease
This commit was merged in pull request #228.
This commit is contained in:
commit
86346df08e
17 files changed
+387
-66
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(KSwitcher VERSION 0.8.11 LANGUAGES C CXX RC)
|
||||
project(KSwitcher VERSION 0.8.12 LANGUAGES C CXX RC)
|
||||
if(NOT WIN32)
|
||||
message(FATAL_ERROR "KSwitcher uses native Windows APIs")
|
||||
endif()
|
||||
|
||||
@@ -139,6 +139,13 @@ a green dot when all online paired PCs are connected, and a red dot if the LAN
|
||||
worker stops. Hover over the icon to see the connection status and the connected
|
||||
count when only some paired PCs are connected.
|
||||
|
||||
If a held key or button blocks a handoff, the tray and **Settings → Computers**
|
||||
identify the PC and name the input when available. The hint clears when the
|
||||
input is released or a handoff succeeds. If Windows still sees an input as held,
|
||||
choose **Reset held keys and mouse buttons** in the tray menu on the PC named
|
||||
in the hint. Both computers need v0.8.12 or later for the source PC to display
|
||||
which input is held on the destination.
|
||||
|
||||
The source cursor is parked and hidden beneath a tiny no-activation window. A
|
||||
small banner identifies remote control; no full-screen layered bitmap is retained.
|
||||
The destination uses its own keyboard layout and runs its own hotkeys/snippets.
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# Latest Windows release
|
||||
|
||||
## v0.8.12 — 2026-12-01
|
||||
|
||||
**LAN cursor handoff.** The tray and **Settings → Computers** identify the computer and, when known, the key or mouse button holding up the handoff. If Windows still sees an input as held after you release it, choose **Reset held keys and mouse buttons** from the tray menu on that PC. Update both computers to see which input on the other PC is blocking the handoff.
|
||||
|
||||
**Українською.** Трей і **Налаштування → Комп’ютери** показують, на якому ПК заблоковано перехід курсора та яка клавіша або кнопка миші його блокує, якщо її вдалося визначити. Якщо Windows продовжує вважати ввід затиснутим після відпускання, виберіть **«Скинути затиснуті клавіші й кнопки миші»** у треї на цьому ПК. Оновіть обидва комп’ютери, щоб бачити, який ввід на іншому ПК блокує перехід.
|
||||
|
||||
## v0.8.11 — 2026-11-30
|
||||
|
||||
**Open URL** is a new action in **Settings → Shortcuts → Custom shortcuts**. Open an HTTP or HTTPS address in the default browser, Google Chrome, or another browser by picking its executable. Choose a Chrome profile from its standard data folder if needed. The shortcut editor uses a white content area and the same tinted footer style as Settings.
|
||||
|
||||
@@ -1 +1 @@
|
||||
fbae717c7a2ea07f29bb4f034e7c7169d17eedfab425a8666e74de237f9a3fdb KSwitcher-win-x64.zip
|
||||
f21c0f10aeb188f688bf4f3cfec8020d9ffbf92d86f15ad09efbb507dcbe7c49 KSwitcher-win-x64.zip
|
||||
+12
-12
@@ -2,23 +2,23 @@
|
||||
"files": [
|
||||
{
|
||||
"path": "KSwitcher.exe",
|
||||
"size": 3298816,
|
||||
"sha256": "5be88613e9e3b7cf7b8eddc78bd44e9cf54ae0e7f6b6ed329d8095c76d60a1ae"
|
||||
"size": 3311104,
|
||||
"sha256": "a5454e72ec1dc0acfebd8ed713b8ca9a124cf501ef7ae7ee28e66a865b3e821f"
|
||||
},
|
||||
{
|
||||
"path": "KSwitcher.Config.exe",
|
||||
"size": 2889728,
|
||||
"sha256": "fb67fc2ac9e075a6925bb4aae0f772d2d4077d7adbc2a87508315cf9ba1ac73a"
|
||||
"size": 2897408,
|
||||
"sha256": "3695f4c1f02fdf9aa27230b22f855685e028c82402c1d05f1198e01c28e023aa"
|
||||
},
|
||||
{
|
||||
"path": "KSwitcher.Screenshot.exe",
|
||||
"size": 3209216,
|
||||
"sha256": "69c56f621be5c6ca9aaa98d98d892004141508067809c7a39511371bfd797e7a"
|
||||
"sha256": "cc0bb2b9bfab49d1c639a97b6ca55aca1bc502f6ca3cc03525f84ff646b7bfd3"
|
||||
},
|
||||
{
|
||||
"path": "KSwitcher.Files.exe",
|
||||
"size": 6030336,
|
||||
"sha256": "7f0a12afe77c0ab5142700069c7bc360206bd00dc5fb5d1595502c66cfacb637"
|
||||
"size": 6039040,
|
||||
"sha256": "2ccbd71bff0dd09f3f00aa063c33307dcfb7bf94811a9cd5f15213af73499f2a"
|
||||
},
|
||||
{
|
||||
"path": "WebView2Loader.dll",
|
||||
@@ -127,8 +127,8 @@
|
||||
},
|
||||
{
|
||||
"path": "LAN-PREVIEW.md",
|
||||
"size": 17245,
|
||||
"sha256": "4eac1f410e6b544aa45756e24f4fdfe9193c6f732410656160be54ab27a0d7e4"
|
||||
"size": 17689,
|
||||
"sha256": "d8418e72fe7d78862bc101fe7df6de44a185a49d6001afee1a20bd8d98cffcd5"
|
||||
},
|
||||
{
|
||||
"path": "dictionaries/en.txt",
|
||||
@@ -168,7 +168,7 @@
|
||||
{
|
||||
"path": "tools/StayHere.exe",
|
||||
"size": 133120,
|
||||
"sha256": "465450da62ad16c1c89e3a6cf79435d1fa06c5e347f5149b9825297c6196c5e8"
|
||||
"sha256": "ad8fa1e781e817f9b04c5148be484d757913941387ffedd4b73fffeb1d119f6a"
|
||||
},
|
||||
{
|
||||
"path": "tools/StayHere-README.md",
|
||||
@@ -176,6 +176,6 @@
|
||||
"sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413"
|
||||
}
|
||||
],
|
||||
"version": "0.8.11",
|
||||
"schema": 1
|
||||
"schema": 1,
|
||||
"version": "0.8.12"
|
||||
}
|
||||
+3
-3
@@ -14,8 +14,8 @@ IDC_SCREENSHOT_PENCIL CURSOR "icons/lucide/pencil.cur"
|
||||
1 RT_MANIFEST "app.manifest"
|
||||
201 RCDATA "update.ps1"
|
||||
1 VERSIONINFO
|
||||
FILEVERSION 0,8,11,0
|
||||
PRODUCTVERSION 0,8,11,0
|
||||
FILEVERSION 0,8,12,0
|
||||
PRODUCTVERSION 0,8,12,0
|
||||
FILEOS VOS_NT_WINDOWS32
|
||||
FILETYPE VFT_APP
|
||||
BEGIN
|
||||
@@ -25,7 +25,7 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "FileDescription", "KSwitcher — native keyboard and clipboard utility"
|
||||
VALUE "ProductName", "KSwitcher"
|
||||
VALUE "FileVersion", "0.8.11"
|
||||
VALUE "FileVersion", "0.8.12"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
+76
-21
@@ -4,6 +4,7 @@
|
||||
#include "../resources/resource.h"
|
||||
#include "ocr.h"
|
||||
#include "lan_clipboard_image.h"
|
||||
#include "lan_input.h"
|
||||
#include "lan_files.h"
|
||||
#include "configuration.h"
|
||||
#include "google_drive.h"
|
||||
@@ -226,6 +227,7 @@ ULONG_PTR snippetReplayMarker()
|
||||
}
|
||||
constexpr int OpenFiles = 25, FilesHotkeyFirst = 0x4B10, FilesHotkeySecond = 0x4B11;
|
||||
constexpr int ToggleInputProcessing = 26, DonateViaMonobank = 27, OpenHelp = 28, OpenWhatsNew = 29, OpenAbout = 16;
|
||||
constexpr int ResetHeldInput = 30;
|
||||
constexpr wchar_t MonobankDonationUrl[] = L"https://send.monobank.ua/jar/88h2TddKfS";
|
||||
constexpr int ShortcutProbeId = FilesHotkeySecond + 1;
|
||||
constexpr int FirstCustomShortcut = 0x5000;
|
||||
@@ -1147,6 +1149,7 @@ bool App::updateTray(DWORD action)
|
||||
std::to_wstring(trayInput.paired) + L" PCs connected)";
|
||||
}
|
||||
}
|
||||
if (state == InputState::Active && !trayInputBlock.empty()) tip = trayInputBlock;
|
||||
wcsncpy_s(icon.szTip, tip.c_str(), _TRUNCATE);
|
||||
const bool updated = Shell_NotifyIconW(action, &icon) != FALSE;
|
||||
if (badge) DestroyIcon(badge);
|
||||
@@ -1155,6 +1158,7 @@ bool App::updateTray(DWORD action)
|
||||
|
||||
void App::refreshTrayInput()
|
||||
{
|
||||
refreshTrayInputBlock();
|
||||
const auto state = lanService ? lanService->inputConnections() : LanInputConnections{};
|
||||
if (state == trayInput) return;
|
||||
trayInput = state;
|
||||
@@ -1166,6 +1170,41 @@ void App::refreshTrayInput()
|
||||
updateTray(NIM_MODIFY);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
bool trayNotice(HWND window, const std::wstring &text)
|
||||
{
|
||||
NOTIFYICONDATAW icon{sizeof(icon)};
|
||||
icon.hWnd = window;
|
||||
icon.uID = 1;
|
||||
icon.uFlags = NIF_INFO;
|
||||
wcsncpy_s(icon.szInfo, text.c_str(), _TRUNCATE);
|
||||
wcscpy_s(icon.szInfoTitle, L"KSwitcher");
|
||||
icon.dwInfoFlags = NIIF_WARNING;
|
||||
return Shell_NotifyIconW(NIM_MODIFY, &icon) != FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void App::refreshTrayInputBlock()
|
||||
{
|
||||
auto block = lanService ? lanService->inputBlockText() : std::wstring{};
|
||||
if (block == trayInputBlock) return;
|
||||
const bool newlyBlocked = trayInputBlock.empty();
|
||||
trayInputBlock = std::move(block);
|
||||
updateTray(NIM_MODIFY);
|
||||
const auto now = GetTickCount64();
|
||||
if (newlyBlocked && now >= nextInputBlockNotice)
|
||||
{
|
||||
inputBlockNoticeVisible = trayNotice(window, trayInputBlock);
|
||||
nextInputBlockNotice = now + 4000;
|
||||
}
|
||||
else if (inputBlockNoticeVisible)
|
||||
{
|
||||
trayNotice(window, {});
|
||||
inputBlockNoticeVisible = false;
|
||||
}
|
||||
}
|
||||
|
||||
void App::addTray()
|
||||
{
|
||||
if (updateTray(NIM_ADD))
|
||||
@@ -1234,13 +1273,18 @@ bool App::registerHotkeys(const Settings &s, bool rollback)
|
||||
return true;
|
||||
}
|
||||
|
||||
void App::startLanService()
|
||||
{
|
||||
lanService = std::make_unique<LanService>(data, window, inputState != InputState::Active, [this] {
|
||||
// Mouse actions may consume a button press before it reaches Windows.
|
||||
const auto held = std::find_if(mousePresses.begin(), mousePresses.end(), [](const auto &press) { return press.held; });
|
||||
return held == mousePresses.end() ? 0 : lan::MouseInputKeys[size_t(held - mousePresses.begin())];
|
||||
});
|
||||
if (!smoke) lanService->startClients();
|
||||
}
|
||||
Bytes App::lanCommand(const Bytes &command)
|
||||
{
|
||||
if (!lanService)
|
||||
{
|
||||
lanService = std::make_unique<LanService>(data,window,inputState != InputState::Active);
|
||||
if (!smoke) lanService->startClients();
|
||||
}
|
||||
if (!lanService) startLanService();
|
||||
auto reply = lanService->command(command);
|
||||
updateLanInputTimer();
|
||||
if (lanService->takeInputChange()) resetLanInput();
|
||||
@@ -1257,6 +1301,7 @@ void App::pollLanInput()
|
||||
// Temporary text transactions only block new handoffs. A tray pause removes
|
||||
// the router entirely, including for already queued network notifications.
|
||||
if (lanService && lanService->tickInput(!busy && !suspended && !hotkeyCapture)) resetLanInput();
|
||||
refreshTrayInputBlock();
|
||||
}
|
||||
void App::applySettings(const Settings &requested, const Bytes &supplement)
|
||||
{
|
||||
@@ -2330,6 +2375,8 @@ LRESULT CALLBACK App::mouseProc(int code, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
auto &app = *current;
|
||||
const auto &mouse = *reinterpret_cast<const MSLLHOOKSTRUCT *>(lp);
|
||||
if ((mouse.flags & LLMHF_INJECTED) && mouse.dwExtraInfo == inputMarker())
|
||||
return CallNextHookEx(nullptr, code, wp, lp);
|
||||
// Forwarded mouse events use the same bindings as local events on this PC.
|
||||
const int button = mouseButton(UINT(wp), HIWORD(mouse.mouseData));
|
||||
const auto wheelDelta = static_cast<SHORT>(HIWORD(mouse.mouseData));
|
||||
@@ -2358,10 +2405,8 @@ LRESULT CALLBACK App::mouseProc(int code, WPARAM wp, LPARAM lp)
|
||||
}
|
||||
if (app.lanService)
|
||||
{
|
||||
const bool mouseActionHeld = std::any_of(app.mousePresses.begin(), app.mousePresses.end(),
|
||||
[](const MousePress &press) { return press.held; });
|
||||
bool consumed = app.lanService->mouse(UINT(wp), mouse,
|
||||
!app.busy && !app.suspended && !app.hotkeyCapture && !mouseActionHeld);
|
||||
!app.busy && !app.suspended && !app.hotkeyCapture);
|
||||
if (app.lanService->takeInputChange()) app.resetLanInput();
|
||||
if (consumed) return 1;
|
||||
}
|
||||
@@ -3349,6 +3394,15 @@ void App::recognizeEntry(std::wstring id)
|
||||
}
|
||||
});
|
||||
}
|
||||
void App::clearMousePresses()
|
||||
{
|
||||
mousePresses = {};
|
||||
pendingMouseClicks = {};
|
||||
KillTimer(window, MouseClickTimer);
|
||||
for (size_t i = 0; i < mousePresses.size(); ++i) KillTimer(window, FirstMouseVolumeTimer + i);
|
||||
PostMessageW(window, MouseVolumeReleasedMessage, 0, 0);
|
||||
}
|
||||
|
||||
void App::toggleInputProcessing()
|
||||
{
|
||||
if (inputState == InputState::Pausing) return;
|
||||
@@ -3362,10 +3416,7 @@ void App::toggleInputProcessing()
|
||||
if (shortcutAvailable(window, binding.second)) availableBeforePause.push_back(binding.second);
|
||||
releaseInputHooks();
|
||||
resetLanInput();
|
||||
mousePresses = {};
|
||||
KillTimer(window, MouseClickTimer);
|
||||
for (size_t i = 0; i < mousePresses.size(); ++i) KillTimer(window, FirstMouseVolumeTimer + i);
|
||||
PostMessageW(window, MouseVolumeReleasedMessage, 0, 0);
|
||||
clearMousePresses();
|
||||
hideSnippetPopup();
|
||||
if (lanService) lanService->setInputPaused(true);
|
||||
KillTimer(window, 8);
|
||||
@@ -3418,6 +3469,8 @@ void App::trayMenu()
|
||||
AppendMenuW(menu, MF_STRING | (inputState == InputState::Pausing ? MF_GRAYED : 0), ToggleInputProcessing,
|
||||
inputState == InputState::Active ? L"Pause &input processing" :
|
||||
inputState == InputState::Paused ? L"Resume &input processing" : L"Pausing input processing…");
|
||||
AppendMenuW(menu, MF_STRING, ResetHeldInput, PRIMARYLANGID(GetThreadUILanguage()) == LANG_UKRAINIAN ?
|
||||
L"Скинути затиснуті клавіші й кнопки миші" : L"Reset held keys and mouse buttons");
|
||||
AppendMenuW(menu, MF_SEPARATOR, 0, nullptr);
|
||||
AppendMenuW(menu, MF_STRING, 10, L"Clipboard &history");
|
||||
AppendMenuW(menu, MF_STRING, 24, L"&Capture screen region…");
|
||||
@@ -3495,6 +3548,14 @@ void App::trayMenu()
|
||||
case ToggleInputProcessing:
|
||||
toggleInputProcessing();
|
||||
break;
|
||||
case ResetHeldInput:
|
||||
if (lan::resetWindowsHeldInput())
|
||||
{
|
||||
if (lanService) lanService->forgetHeldInput();
|
||||
clearMousePresses();
|
||||
}
|
||||
else report(L"Windows could not release all held keys or mouse buttons.");
|
||||
break;
|
||||
case OpenFiles:
|
||||
dispatch(OpenFiles);
|
||||
break;
|
||||
@@ -3852,14 +3913,8 @@ LRESULT CALLBACK App::windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
case ErrorMessage:
|
||||
{
|
||||
std::unique_ptr<std::wstring> text((std::wstring *)lp);
|
||||
NOTIFYICONDATAW icon{sizeof(icon)};
|
||||
icon.hWnd = hwnd;
|
||||
icon.uID = 1;
|
||||
icon.uFlags = NIF_INFO;
|
||||
wcsncpy_s(icon.szInfo, text->c_str(), _TRUNCATE);
|
||||
wcscpy_s(icon.szInfoTitle, L"KSwitcher");
|
||||
icon.dwInfoFlags = NIIF_WARNING;
|
||||
Shell_NotifyIconW(NIM_MODIFY, &icon);
|
||||
app->inputBlockNoticeVisible = false;
|
||||
trayNotice(hwnd, *text);
|
||||
return 0;
|
||||
}
|
||||
case LanInputStatusMessage:
|
||||
@@ -4112,7 +4167,7 @@ int App::execute()
|
||||
if (!smoke && inputState == InputState::Active) startBrowserChatMonitor();
|
||||
if (!smoke && (std::filesystem::exists(data / L"lan-pairing.bin") ||
|
||||
std::filesystem::exists(data / L"lan-clients.bin")))
|
||||
try { lanService = std::make_unique<LanService>(data,window,inputState != InputState::Active); lanService->startClients(); }
|
||||
try { startLanService(); }
|
||||
catch (const std::exception &e) { report(L"LAN module: " + wide(e.what())); }
|
||||
updateLanInputTimer();
|
||||
refreshTrayInput();
|
||||
|
||||
@@ -126,6 +126,7 @@ class App
|
||||
void toggleInputProcessing();
|
||||
void updateLanInputTimer();
|
||||
void pollLanInput();
|
||||
void startLanService();
|
||||
struct MousePress
|
||||
{
|
||||
HWND target{};
|
||||
@@ -180,9 +181,14 @@ class App
|
||||
bool trayRetryPending{};
|
||||
LanInputConnections trayInput;
|
||||
bool trayInputPulse{};
|
||||
std::wstring trayInputBlock;
|
||||
ULONGLONG nextInputBlockNotice{};
|
||||
bool inputBlockNoticeVisible{};
|
||||
HICON trayBaseIcon(int width, int height) const;
|
||||
bool updateTray(DWORD action);
|
||||
void refreshTrayInput();
|
||||
void refreshTrayInputBlock();
|
||||
void clearMousePresses();
|
||||
uint64_t transformAttempt{}, previousAttemptVersion{};
|
||||
std::atomic<uint64_t> activeTransformAttempt{};
|
||||
ULONGLONG previousAttemptAt{};
|
||||
|
||||
+36
-4
@@ -148,6 +148,7 @@ struct LanService::Impl
|
||||
std::mutex inputMutex;
|
||||
std::vector<lan::RoutedInput> inputOut,inputIn;
|
||||
std::map<std::string,uint64_t> inputReady;
|
||||
std::function<int()> additionalHeldKey;
|
||||
std::unique_ptr<lan::InputMesh> router;
|
||||
std::string inputStatus="Input sharing disabled.";
|
||||
size_t inputConnectedPeers{}, inputOnlinePeers{};
|
||||
@@ -155,8 +156,8 @@ struct LanService::Impl
|
||||
bool inputNeedsHelp{};
|
||||
HWND inputWindow{};std::atomic<bool> inputNotification{false};
|
||||
lan::LanClients clients;
|
||||
explicit Impl(const std::filesystem::path &root,HWND window,bool paused)
|
||||
: path(root/L"lan-pairing.bin"),inputPaused(paused),inputWindow(window),clients(root)
|
||||
explicit Impl(const std::filesystem::path &root,HWND window,bool paused,std::function<int()> heldKey)
|
||||
: path(root/L"lan-pairing.bin"),inputPaused(paused),additionalHeldKey(std::move(heldKey)),inputWindow(window),clients(root)
|
||||
{
|
||||
if(std::filesystem::exists(path))
|
||||
{
|
||||
@@ -239,7 +240,8 @@ struct LanService::Impl
|
||||
router.reset();++inputConfiguration;
|
||||
if(enabled&&shareInput&&!inputPaused){
|
||||
std::map<std::string,POINT> layout;for(auto &[peer,cell]:positions.items())if(trusted.contains(peer))layout[peer]={cell[0].get<LONG>(),cell[1].get<LONG>()};
|
||||
router=std::make_unique<lan::InputMesh>(id,lan::windowsInputEnvironment(),std::move(layout),[this](const auto &peer,auto f){return queue(peer,f);});
|
||||
router=std::make_unique<lan::InputMesh>(id,lan::windowsInputEnvironment(additionalHeldKey),std::move(layout),
|
||||
[this](const auto &peer,auto f){return queue(peer,f);});
|
||||
}
|
||||
inputStatus=enabled&&shareInput?"Connecting input channels...":"Input sharing disabled.";
|
||||
observedRevision=0;
|
||||
@@ -282,6 +284,26 @@ struct LanService::Impl
|
||||
router->receive(frame.peer,frame.frame,GetTickCount64(),allowEnter);
|
||||
return takeChange();
|
||||
}
|
||||
std::wstring inputBlockText(const lan::HandoffBlock &block) const
|
||||
{
|
||||
if(!block.key)return {};
|
||||
std::wstring location=L"this PC";
|
||||
if(!block.peer.empty())
|
||||
{
|
||||
auto paired=trusted.find(block.peer);
|
||||
if(paired==trusted.end())return {};
|
||||
location=wide(paired->value("name",block.peer.substr(0,8)));
|
||||
if(location.size()>50)
|
||||
{
|
||||
const bool highSurrogate=location[48]>=0xd800&&location[48]<=0xdbff;
|
||||
location.resize(highSurrogate?48:49);
|
||||
location+=L"…";
|
||||
}
|
||||
}
|
||||
auto input=lan::heldInputName(block.key);
|
||||
return L"Cursor handoff blocked on "+location+L": "+
|
||||
(input.empty()?L"a key or mouse button is held.":input+L" is held.");
|
||||
}
|
||||
void start()
|
||||
{
|
||||
stopping=false; epoch=lan::randomHex(16); status="Searching for KSwitcher computers...";
|
||||
@@ -827,6 +849,7 @@ struct LanService::Impl
|
||||
{"positions",positions},{"shareInput",shareInput},{"inputPeer",inputPeer},{"controlPeer",router?router->peer():std::string{}},{"inputEdge",inputEdge},{"inputConnected",inputConnectedPeers!=0},
|
||||
{"inputStatus",inputPaused?"Input processing paused in the tray.":enabled&&shareInput?inputStatus:"Input sharing disabled."},{"inputNeedsHelp",!inputPaused&&enabled&&shareInput&&inputNeedsHelp},{"controlMode",router?int(router->mode()):0}};
|
||||
{std::lock_guard inputLock(inputMutex);result["inputReady"]=inputReady;}
|
||||
result["inputBlock"]=router?utf8(inputBlockText(router->handoffBlock())):std::string{};
|
||||
result["shareLogs"]=shareLogs;
|
||||
result["files"]=Json::array();
|
||||
result["transferStatus"]=transfers->status;
|
||||
@@ -853,7 +876,8 @@ struct LanService::Impl
|
||||
return encoded(result);
|
||||
}
|
||||
};
|
||||
LanService::LanService(const std::filesystem::path &path,HWND window,bool paused) : impl(std::make_unique<Impl>(path,window,paused)) {}
|
||||
LanService::LanService(const std::filesystem::path &path,HWND window,bool paused,std::function<int()> heldKey)
|
||||
:impl(std::make_unique<Impl>(path,window,paused,std::move(heldKey))) {}
|
||||
LanService::~LanService()=default;
|
||||
Bytes LanService::command(const Bytes &command) { return impl->command(command); }
|
||||
void LanService::startClients() { impl->startClients(); }
|
||||
@@ -888,6 +912,14 @@ LanInputConnections LanService::inputConnections()const
|
||||
return {std::min(impl->inputConnectedPeers,paired),std::min(impl->inputOnlinePeers,paired),paired,impl->inputWorkerStopped};
|
||||
}
|
||||
bool LanService::tickInput(bool allowEnter){return impl->tickInput(allowEnter);}
|
||||
std::wstring LanService::inputBlockText()const
|
||||
{
|
||||
const auto block=impl->router?impl->router->handoffBlock():lan::HandoffBlock{};
|
||||
if(!block.key)return {};
|
||||
std::lock_guard lock(impl->mutex);
|
||||
return impl->inputBlockText(block);
|
||||
}
|
||||
void LanService::forgetHeldInput(){if(impl->router)impl->router->forgetHeldKeys();}
|
||||
bool LanService::keyboard(const KBDLLHOOKSTRUCT &k,bool down){return impl->router&&impl->router->keyboard(k,down,GetTickCount64());}
|
||||
bool LanService::mouse(UINT message,const MSLLHOOKSTRUCT &m,bool allowEnter){return impl->router&&impl->router->mouse(message,m,GetTickCount64(),allowEnter);}
|
||||
bool LanService::takeInputChange(){return impl->takeChange();}
|
||||
|
||||
@@ -21,7 +21,8 @@ class LanService
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
public:
|
||||
explicit LanService(const std::filesystem::path &, HWND inputWindow=nullptr, bool inputPaused=false);
|
||||
explicit LanService(const std::filesystem::path &, HWND inputWindow=nullptr, bool inputPaused=false,
|
||||
std::function<int()> additionalHeldKey={});
|
||||
~LanService();
|
||||
Bytes command(const Bytes &);
|
||||
void startClients();
|
||||
@@ -31,6 +32,8 @@ class LanService
|
||||
bool inputEnabled() const;
|
||||
void setInputPaused(bool);
|
||||
LanInputConnections inputConnections() const;
|
||||
std::wstring inputBlockText() const;
|
||||
void forgetHeldInput();
|
||||
bool tickInput(bool allowEnter = true);
|
||||
bool keyboard(const KBDLLHOOKSTRUCT &, bool down);
|
||||
bool mouse(UINT, const MSLLHOOKSTRUCT &, bool allowEnter);
|
||||
|
||||
+85
-11
@@ -82,8 +82,11 @@ INPUT button(unsigned index,bool down)
|
||||
{MOUSEEVENTF_MIDDLEUP,MOUSEEVENTF_MIDDLEDOWN},{MOUSEEVENTF_XUP,MOUSEEVENTF_XDOWN},{MOUSEEVENTF_XUP,MOUSEEVENTF_XDOWN}};
|
||||
input.mi.dwFlags=flags[index][down];if(index>=3)input.mi.mouseData=index==3?XBUTTON1:XBUTTON2;return input;
|
||||
}
|
||||
bool windowsKeyDown(int key){return (GetAsyncKeyState(key)&0x8000)!=0;}
|
||||
UINT keyScan(int key){return MapVirtualKeyW(UINT(key),MAPVK_VK_TO_VSC_EX);}
|
||||
bool extendedKey(UINT scan){return (scan&0xff00)==0xe000;}
|
||||
}
|
||||
InputEnvironment windowsInputEnvironment()
|
||||
InputEnvironment windowsInputEnvironment(std::function<int()> additionalHeldKey)
|
||||
{
|
||||
auto overlay=std::make_shared<ControlOverlay>();
|
||||
return {
|
||||
@@ -91,7 +94,10 @@ InputEnvironment windowsInputEnvironment()
|
||||
[]{POINT p{};GetCursorPos(&p);return p;},
|
||||
[](const INPUT &i){INPUT input=i;return SendInput(1,&input,sizeof(input))==1;},
|
||||
ordinaryDesktop,
|
||||
[]{for(int key=1;key<256;++key)if(GetAsyncKeyState(key)&0x8000)return true;return false;},
|
||||
[additionalHeldKey=std::move(additionalHeldKey)]{
|
||||
if(additionalHeldKey)if(const int key=additionalHeldKey())return key;
|
||||
for(int key=1;key<256;++key)if(windowsKeyDown(key))return key;
|
||||
return 0;},
|
||||
[]{POINT p{};GetCursorPos(&p);MONITORINFO info{sizeof(info)};
|
||||
if(GetMonitorInfoW(MonitorFromPoint(p,MONITOR_DEFAULTTONEAREST),&info))p={(info.rcMonitor.left+info.rcMonitor.right)/2,(info.rcMonitor.top+info.rcMonitor.bottom)/2};
|
||||
return p;},
|
||||
@@ -99,6 +105,55 @@ InputEnvironment windowsInputEnvironment()
|
||||
monitorDpi
|
||||
};
|
||||
}
|
||||
std::wstring heldInputName(int key)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
case VK_LBUTTON:return L"Left mouse button";
|
||||
case VK_RBUTTON:return L"Right mouse button";
|
||||
case VK_MBUTTON:return L"Middle mouse button";
|
||||
case VK_XBUTTON1:return L"Mouse button 4";
|
||||
case VK_XBUTTON2:return L"Mouse button 5";
|
||||
case VK_MEDIA_PLAY_PAUSE:return L"Play/Pause";
|
||||
}
|
||||
if(key>0&&key<UnknownHeldInput)
|
||||
{
|
||||
if(auto name=Hotkey{0,UINT(key)}.format();!name.empty())return name;
|
||||
const auto scan=keyScan(key);
|
||||
wchar_t name[64]{};
|
||||
if(scan&&GetKeyNameTextW(LONG(((scan&0xff)<<16)|(extendedKey(scan)?1u<<24:0u)),name,int(std::size(name))))
|
||||
return name;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
std::vector<INPUT> heldInputReleases(const std::function<bool(int)> &isDown)
|
||||
{
|
||||
std::vector<INPUT> releases;
|
||||
for(int key=1;key<256;++key)
|
||||
{
|
||||
if(!isDown(key))continue;
|
||||
// Windows reports a generic modifier along with its left/right key.
|
||||
if((key==VK_SHIFT&&(isDown(VK_LSHIFT)||isDown(VK_RSHIFT)))||
|
||||
(key==VK_CONTROL&&(isDown(VK_LCONTROL)||isDown(VK_RCONTROL)))||
|
||||
(key==VK_MENU&&(isDown(VK_LMENU)||isDown(VK_RMENU))))continue;
|
||||
const auto mouse=std::find(MouseInputKeys.begin(),MouseInputKeys.end(),key);
|
||||
if(mouse!=MouseInputKeys.end())
|
||||
{
|
||||
auto release=button(unsigned(mouse-MouseInputKeys.begin()),false);
|
||||
release.mi.dwExtraInfo=inputMarker();
|
||||
releases.push_back(release);
|
||||
}
|
||||
else releases.push_back(keyboardInput(WORD(key),KEYEVENTF_KEYUP|
|
||||
(extendedKey(keyScan(key))||key==VK_MEDIA_PLAY_PAUSE?KEYEVENTF_EXTENDEDKEY:0)));
|
||||
}
|
||||
return releases;
|
||||
}
|
||||
bool resetWindowsHeldInput()
|
||||
{
|
||||
if(!ordinaryDesktop())return false;
|
||||
auto releases=heldInputReleases(windowsKeyDown);
|
||||
return releases.empty()||SendInput(UINT(releases.size()),releases.data(),sizeof(INPUT))==releases.size();
|
||||
}
|
||||
bool atEdge(POINT p,RECT r,int side)
|
||||
{return side==0?p.x<=r.left:side==1?p.x>=r.right-1:side==2?p.y<=r.top:p.y>=r.bottom-1;}
|
||||
int edgePosition(POINT p,RECT r,int side)
|
||||
@@ -140,9 +195,15 @@ bool InputRouter::move(POINT p,bool warp)
|
||||
return ok;
|
||||
}
|
||||
bool InputRouter::post(InputFrame f){return connected&&send(f);}
|
||||
bool InputRouter::held()const
|
||||
int InputRouter::heldKey()const
|
||||
{
|
||||
return std::any_of(physical.begin(),physical.end(),[](bool b){return b;})||env.held();
|
||||
const auto key=std::find(physical.begin(),physical.end(),true);
|
||||
return key!=physical.end()?int(key-physical.begin()):env.heldKey();
|
||||
}
|
||||
void InputRouter::noteHeldInput(int key)
|
||||
{
|
||||
if(!blockedKey_)log(L"LAN input: cursor handoff blocked by local input (VK "+std::to_wstring(key)+L")");
|
||||
blockedKey_=key;
|
||||
}
|
||||
void InputRouter::release()
|
||||
{
|
||||
@@ -159,7 +220,7 @@ void InputRouter::local(uint64_t now,int position)
|
||||
}
|
||||
bool InputRouter::handoff(int side,int position,uint64_t now)
|
||||
{
|
||||
if(!multi||mode_!=ControlMode::Sending||held()||side<0||side>3)return false;
|
||||
if(!multi||mode_!=ControlMode::Sending||heldKey()||side<0||side>3)return false;
|
||||
edge=side;transit=true;token=ownershipToken();
|
||||
requested=now;mode(ControlMode::Requesting);
|
||||
if(!post({InputType::Enter,token,edge,std::clamp(position,0,65535)})){cancel(now,"next computer unavailable");return false;}
|
||||
@@ -185,8 +246,10 @@ void InputRouter::tick(bool ready,uint64_t now)
|
||||
{returning=false;if(env.modeChanged)env.modeChanged(ControlMode::Local);}
|
||||
}
|
||||
connected=ready;
|
||||
const bool desktop=ready&&env.desktop();
|
||||
if(blockedKey_)blockedKey_=desktop?heldKey():0;
|
||||
if(!ready)cancel(now,"channel unavailable");
|
||||
else if(!env.desktop())cancel(now,"input desktop unavailable");
|
||||
else if(!desktop)cancel(now,"input desktop unavailable");
|
||||
else if(mode_==ControlMode::Requesting&&now-requested>1000)cancel(now,"handoff acknowledgement timed out");
|
||||
if(mode_==ControlMode::Sending&&awaitingWarp)
|
||||
{
|
||||
@@ -212,9 +275,14 @@ void InputRouter::receive(const InputFrame &f,uint64_t now)
|
||||
if(f.type==InputType::Enter)
|
||||
{
|
||||
const wchar_t *declined=nullptr;
|
||||
int blocked=0;
|
||||
if(!f.token||f.a<0||f.a>3||(!multi&&f.a!=(edge^1))||f.b<0||f.b>65535)
|
||||
declined=L"invalid edge or position";
|
||||
else if(held())declined=L"a local key or mouse button is held";
|
||||
else if((blocked=heldKey())!=0)
|
||||
{
|
||||
noteHeldInput(blocked);
|
||||
post({InputType::Return,f.token,32768,blocked});return;
|
||||
}
|
||||
else if(returning||mode_==ControlMode::Sending||mode_==ControlMode::Receiving||
|
||||
(mode_==ControlMode::Requesting&&preferLocal))
|
||||
declined=L"another handoff is active";
|
||||
@@ -225,7 +293,7 @@ void InputRouter::receive(const InputFrame &f,uint64_t now)
|
||||
}
|
||||
if(mode_==ControlMode::Requesting)cancel(now);
|
||||
if(multi)edge=f.a^1;
|
||||
crossEdge=-1;token=f.token;remainderX=remainderY=0;mode(ControlMode::Receiving);
|
||||
blockedKey_=0;crossEdge=-1;token=f.token;remainderX=remainderY=0;mode(ControlMode::Receiving);
|
||||
receivedPoint=edgePoint(env.bounds(),edge,f.b);
|
||||
awaitingEntry=true;entryStarted=now;
|
||||
if(!move(receivedPoint))cancel(now,"destination cursor injection failed");
|
||||
@@ -233,8 +301,13 @@ void InputRouter::receive(const InputFrame &f,uint64_t now)
|
||||
}
|
||||
if(f.type==InputType::Accept)
|
||||
{
|
||||
if(mode_!=ControlMode::Requesting||f.token!=token||held()||(!transit&&!atEdge(env.cursor(),env.bounds(),edge))){post({InputType::Return,f.token,32768});if(f.token==token)cancel(now);return;}
|
||||
transit=false;auto r=env.bounds();anchor=env.anchor?env.anchor():POINT{(r.left+r.right)/2,(r.top+r.bottom)/2};mode(ControlMode::Sending);
|
||||
const int blocked=mode_==ControlMode::Requesting&&f.token==token?heldKey():0;
|
||||
if(mode_!=ControlMode::Requesting||f.token!=token||blocked||(!transit&&!atEdge(env.cursor(),env.bounds(),edge)))
|
||||
{
|
||||
if(blocked)noteHeldInput(blocked);
|
||||
post({InputType::Return,f.token,32768});if(f.token==token)cancel(now);return;
|
||||
}
|
||||
blockedKey_=0;transit=false;auto r=env.bounds();anchor=env.anchor?env.anchor():POINT{(r.left+r.right)/2,(r.top+r.bottom)/2};mode(ControlMode::Sending);
|
||||
warpStarted=now;
|
||||
if(!move(anchor,true))cancel(now,"source cursor parking failed");
|
||||
return;
|
||||
@@ -358,8 +431,9 @@ bool InputRouter::mouse(UINT message,const MSLLHOOKSTRUCT &m,uint64_t now,bool a
|
||||
}
|
||||
if(index>=0&&outButtons[size_t(index)]){if(!down)outButtons[size_t(index)]=false;return true;}
|
||||
if(mode_==ControlMode::Local&&connected&&allowEnter&&message==WM_MOUSEMOVE&&now>=cooldown&&
|
||||
env.desktop()&&!held()&&atEdge(m.pt,env.bounds(),edge))
|
||||
env.desktop()&&atEdge(m.pt,env.bounds(),edge))
|
||||
{
|
||||
if(const int blocked=heldKey()){noteHeldInput(blocked);return false;}
|
||||
token=ownershipToken();
|
||||
returnPoint=m.pt;requested=now;mode(ControlMode::Requesting);
|
||||
if(!post({InputType::Enter,token,edge,edgePosition(m.pt,env.bounds(),edge)}))cancel(now);
|
||||
|
||||
+15
-4
@@ -4,18 +4,25 @@
|
||||
namespace ks::lan
|
||||
{
|
||||
enum class ControlMode { Local, Requesting, Sending, Receiving };
|
||||
// The Return frame's second field was unused. Older peers still return control.
|
||||
inline constexpr int UnknownHeldInput = 256;
|
||||
inline constexpr int HeldInputCleared = -1;
|
||||
struct InputEnvironment
|
||||
{
|
||||
std::function<RECT()> bounds;
|
||||
std::function<POINT()> cursor;
|
||||
std::function<bool(const INPUT &)> inject;
|
||||
std::function<bool()> desktop;
|
||||
std::function<bool()> held;
|
||||
std::function<int()> heldKey;
|
||||
std::function<POINT()> anchor;
|
||||
std::function<void(ControlMode)> modeChanged;
|
||||
std::function<int(POINT)> dpi;
|
||||
};
|
||||
InputEnvironment windowsInputEnvironment();
|
||||
inline constexpr std::array MouseInputKeys{VK_LBUTTON,VK_RBUTTON,VK_MBUTTON,VK_XBUTTON1,VK_XBUTTON2};
|
||||
InputEnvironment windowsInputEnvironment(std::function<int()> additionalHeldKey={});
|
||||
std::wstring heldInputName(int key);
|
||||
std::vector<INPUT> heldInputReleases(const std::function<bool(int)> &isDown);
|
||||
bool resetWindowsHeldInput();
|
||||
ULONG_PTR remoteInputMarker();
|
||||
ULONG_PTR cursorWarpMarker();
|
||||
bool atEdge(POINT,RECT,int edge);
|
||||
@@ -34,6 +41,7 @@ class InputRouter
|
||||
bool awaitingWarp{},awaitingEntry{};
|
||||
uint64_t warpStarted{},entryStarted{};
|
||||
bool returning{};POINT returnTarget{};uint64_t returnStarted{};
|
||||
int blockedKey_{};
|
||||
double remainderX{},remainderY{};
|
||||
std::array<bool,256> physical{},outKeys{},remoteKeys{};
|
||||
std::array<INPUT,256> releases{};
|
||||
@@ -42,7 +50,8 @@ class InputRouter
|
||||
bool emit(INPUT);
|
||||
bool move(POINT,bool warp=false);
|
||||
bool post(InputFrame);
|
||||
bool held() const;
|
||||
int heldKey() const;
|
||||
void noteHeldInput(int key);
|
||||
void release();
|
||||
void local(uint64_t now,int position=-1);
|
||||
public:
|
||||
@@ -50,7 +59,9 @@ class InputRouter
|
||||
~InputRouter();
|
||||
void selectEdge(int side,bool prefer){edge=side;preferLocal=prefer;}
|
||||
uint32_t sessionToken()const{return token;}
|
||||
bool canHandoff()const{return mode_==ControlMode::Sending&&!held();}
|
||||
bool canHandoff()const{return mode_==ControlMode::Sending&&!heldKey();}
|
||||
int blockedKey()const{return blockedKey_;}
|
||||
void forgetHeldKeys(){physical.fill(false);}
|
||||
bool handoff(int side,int position,uint64_t now);
|
||||
void returnAt(int side,int position,uint64_t now);
|
||||
ControlMode mode()const{return mode_;}
|
||||
|
||||
+53
-1
@@ -1,8 +1,14 @@
|
||||
#pragma once
|
||||
#include "lan_input.h"
|
||||
#include <map>
|
||||
#include <optional>
|
||||
namespace ks::lan
|
||||
{
|
||||
struct HandoffBlock
|
||||
{
|
||||
std::string peer; // Empty for this PC.
|
||||
int key{};
|
||||
};
|
||||
// The physical input source routes directly to the current destination. A
|
||||
// destination only reports edge crossings; it never relays injected key events.
|
||||
class InputMesh
|
||||
@@ -13,7 +19,17 @@ class InputMesh
|
||||
std::map<std::string,uint64_t> ready;
|
||||
std::function<bool(const std::string &,InputFrame)> send;
|
||||
uint64_t activeGeneration{},routeRevision{};
|
||||
struct Rejection {uint32_t token;uint64_t generation;int key;};
|
||||
std::map<std::string,Rejection> rejectedPeers;
|
||||
std::optional<std::pair<std::string,Rejection>> remoteBlock;
|
||||
InputRouter router;
|
||||
bool sendActive(InputFrame frame)
|
||||
{
|
||||
if(active.empty()||!ready.contains(active)||!send(active,frame))return false;
|
||||
if(frame.type==InputType::Return&&frame.b>0)
|
||||
rejectedPeers.insert_or_assign(active,Rejection{frame.token,ready.at(active),frame.b});
|
||||
return true;
|
||||
}
|
||||
std::string neighbor(const std::string &from,int side)const
|
||||
{
|
||||
POINT p{};if(from!=local){auto found=positions.find(from);if(found==positions.end())return {};p=found->second;}
|
||||
@@ -31,10 +47,17 @@ class InputMesh
|
||||
InputMesh(std::string id,InputEnvironment environment,std::map<std::string,POINT> layout,
|
||||
std::function<bool(const std::string &,InputFrame)> sender)
|
||||
:local(std::move(id)),env(std::move(environment)),positions(std::move(layout)),send(std::move(sender)),
|
||||
router(env,[this](InputFrame f){return !active.empty()&&ready.contains(active)&&send(active,f);},1,true,true){}
|
||||
router(env,[this](InputFrame f){return sendActive(f);},1,true,true){}
|
||||
ControlMode mode()const{return router.mode();}
|
||||
uint64_t revision()const{return router.revision()+routeRevision;}
|
||||
const std::string &peer()const{return active;}
|
||||
HandoffBlock handoffBlock()const
|
||||
{
|
||||
if(router.blockedKey())return {{},router.blockedKey()};
|
||||
if(remoteBlock)return {remoteBlock->first,remoteBlock->second.key};
|
||||
return {};
|
||||
}
|
||||
void forgetHeldKeys(){router.forgetHeldKeys();}
|
||||
void cancel(uint64_t now){router.cancel(now);}
|
||||
void tick(std::map<std::string,uint64_t> connections,uint64_t now)
|
||||
{
|
||||
@@ -44,10 +67,38 @@ class InputMesh
|
||||
if(connected&&activeGeneration!=ready.at(active)){router.cancel(now,"peer reconnected");activeGeneration=ready.at(active);}
|
||||
router.tick(connected,now);
|
||||
}
|
||||
const auto sameConnection=[this](const std::string &peer,const Rejection &rejection){
|
||||
auto connection=ready.find(peer);
|
||||
return connection!=ready.end()&&connection->second==rejection.generation;
|
||||
};
|
||||
if(remoteBlock&&!sameConnection(remoteBlock->first,remoteBlock->second))remoteBlock.reset();
|
||||
const int held=router.blockedKey();
|
||||
for(auto it=rejectedPeers.begin();it!=rejectedPeers.end();)
|
||||
{
|
||||
auto &[peer,rejection]=*it;
|
||||
if(!sameConnection(peer,rejection)){it=rejectedPeers.erase(it);continue;}
|
||||
if(held!=rejection.key&&send(peer,{InputType::Return,rejection.token,32768,held?held:HeldInputCleared}))
|
||||
rejection.key=held;
|
||||
if(!rejection.key)it=rejectedPeers.erase(it);
|
||||
else ++it;
|
||||
}
|
||||
}
|
||||
void receive(const std::string &peer,const InputFrame &f,uint64_t now,bool allowEnter=true)
|
||||
{
|
||||
if(!ready.contains(peer)||!positions.contains(peer))return;
|
||||
if(f.type==InputType::Return)
|
||||
{
|
||||
const bool held=f.b>0&&f.b<=UnknownHeldInput;
|
||||
if(remoteBlock&&remoteBlock->first==peer&&remoteBlock->second.token==f.token)
|
||||
{
|
||||
// These updates belong to a completed request, never the current owner.
|
||||
if(f.b==HeldInputCleared)remoteBlock.reset();
|
||||
else if(held)remoteBlock->second.key=f.b;
|
||||
return;
|
||||
}
|
||||
if(held&&active==peer&&router.mode()==ControlMode::Requesting&&router.sessionToken()==f.token)
|
||||
remoteBlock=std::pair{peer,Rejection{f.token,ready.at(peer),f.b}};
|
||||
}
|
||||
if(f.type==InputType::Enter){
|
||||
if(!allowEnter||f.a<0||f.a>3||(router.mode()!=ControlMode::Local&&active!=peer)){
|
||||
if(!allowEnter)log(L"LAN input: declined cursor handoff during a local text operation or shortcut capture");
|
||||
@@ -66,6 +117,7 @@ class InputMesh
|
||||
router.handoff(f.a,f.b,now);return;
|
||||
}
|
||||
router.receive(f,now);
|
||||
if(router.mode()==ControlMode::Sending||router.mode()==ControlMode::Receiving)remoteBlock.reset();
|
||||
}
|
||||
bool keyboard(const KBDLLHOOKSTRUCT &key,bool down,uint64_t now){return router.keyboard(key,down,now);}
|
||||
bool mouse(UINT message,const MSLLHOOKSTRUCT &mouse,uint64_t now,bool allowEnter=true)
|
||||
|
||||
@@ -364,6 +364,8 @@ void refreshLan(HWND w,LanView &v)
|
||||
auto mode=v.snapshot.value("controlMode",0);
|
||||
if(mode==2)inputStatus=L"Mouse and keyboard control the OTHER PC. Ctrl+Alt+Esc returns here.";
|
||||
else if(mode==3)inputStatus=L"This PC is controlled remotely. Local physical input takes control back.";
|
||||
const auto inputBlock=v.snapshot.value("inputBlock",std::string{});
|
||||
if(!inputBlock.empty()&&v.snapshot.value("shareInput",false))inputStatus=wide(inputBlock);
|
||||
if (v.draft.contains("shareInput"))
|
||||
inputStatus = L"Click Apply or Save to apply input sharing changes.";
|
||||
setStatus(718,v.layoutError.empty() ? inputStatus : v.layoutError);
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
#include "platform.h"
|
||||
namespace ks
|
||||
{
|
||||
inline constexpr wchar_t AppVersion[] = L"0.8.11";
|
||||
inline constexpr wchar_t AppVersion[] = L"0.8.12";
|
||||
inline constexpr UINT UpdateMessage = WM_APP + 7;
|
||||
inline constexpr UINT UpdateCheckIntervalMs = 6 * 60 * 60 * 1000;
|
||||
inline constexpr UINT UpdateNotificationRetryMs = 5 * 60 * 1000;
|
||||
|
||||
@@ -48,7 +48,7 @@ void chooseInputAction(HWND resident, DWORD pid, const wchar_t *expected)
|
||||
std::wstring_view(label).starts_with(expected), "incorrect input state in tray menu");
|
||||
HMENU help{};
|
||||
MENUITEMINFOW donation{sizeof(donation), MIIM_BITMAP};
|
||||
bool donationSeparated = false;
|
||||
bool donationSeparated = false, resetAvailable = false;
|
||||
const auto menuTitle = [&](HMENU source, int index) {
|
||||
if (!GetMenuStringW(source, index, label, std::size(label), MF_BYPOSITION)) return std::wstring_view{};
|
||||
const std::wstring_view text(label);
|
||||
@@ -56,6 +56,8 @@ void chooseInputAction(HWND resident, DWORD pid, const wchar_t *expected)
|
||||
};
|
||||
for (int i = 0, count = GetMenuItemCount(menu); i < count; ++i) {
|
||||
const auto title = menuTitle(menu, i);
|
||||
if (title == L"Reset held keys and mouse buttons" || title == L"Скинути затиснуті клавіші й кнопки миші")
|
||||
resetAvailable = (GetMenuState(menu, i, MF_BYPOSITION) & (MF_GRAYED | MF_DISABLED)) == 0;
|
||||
if (title == L"&Donate via Monobank" && i > 0 && i + 1 < count) {
|
||||
donationSeparated = (GetMenuState(menu, i - 1, MF_BYPOSITION) & MF_SEPARATOR) &&
|
||||
(GetMenuState(menu, i + 1, MF_BYPOSITION) & MF_SEPARATOR);
|
||||
@@ -66,6 +68,7 @@ void chooseInputAction(HWND resident, DWORD pid, const wchar_t *expected)
|
||||
break;
|
||||
}
|
||||
}
|
||||
require(resetAvailable, "the tray offers manual input reset while active or paused");
|
||||
require(donationSeparated && donation.hbmpItem, "tray donation item has an icon and both separators");
|
||||
require(help && GetMenuItemCount(help) == 3 && menuTitle(help, 0) == L"&User guide" &&
|
||||
menuTitle(help, 1) == ks::whatsNewTitle(GetThreadUILanguage()) &&
|
||||
|
||||
+75
-5
@@ -13,7 +13,8 @@ void check(bool value,const char *text){if(!value)throw std::runtime_error(text)
|
||||
template<class F>void rejects(F f,const char *text){bool failed=false;try{f();}catch(...){failed=true;}check(failed,text);}
|
||||
struct Desktop
|
||||
{
|
||||
RECT rect{-1920,-200,0,880};POINT point{-1000,300};bool available=true,physicalHeld=false,allow=true;
|
||||
RECT rect{-1920,-200,0,880};POINT point{-1000,300};bool available=true,allow=true;
|
||||
int heldKey{};
|
||||
std::vector<INPUT> events;int dpi=96;bool delayed=false;InputRouter *router{};
|
||||
InputEnvironment environment()
|
||||
{
|
||||
@@ -26,7 +27,7 @@ struct Desktop
|
||||
if(router){MSLLHOOKSTRUCT m{};m.pt=point;m.flags=LLMHF_INJECTED;m.dwExtraInfo=i.mi.dwExtraInfo;router->mouse(WM_MOUSEMOVE,m,1000);}
|
||||
}
|
||||
return true;
|
||||
},[this]{return available;},[this]{return physicalHeld;},{},{},[this](POINT){return dpi;}};
|
||||
},[this]{return available;},[this]{return heldKey;},{},{},[this](POINT){return dpi;}};
|
||||
}
|
||||
unsigned keyEvents(bool down)const
|
||||
{return unsigned(std::count_if(events.begin(),events.end(),[down](auto &i){return i.type==INPUT_KEYBOARD&&bool(i.ki.dwFlags&KEYEVENTF_KEYUP)!=down;}));}
|
||||
@@ -205,9 +206,9 @@ void routerChecks()
|
||||
p.b.available=true;p.right.tick(true,1400);check(p.b.keyEvents(false)==1,"blocked release retried when normal desktop returns");
|
||||
}
|
||||
{
|
||||
Pair p(1);p.a.physicalHeld=true;motion(p.left,p.a,edgePoint(p.a.rect,1,30000,0),1000);
|
||||
Pair p(1);p.a.heldKey=VK_TAB;motion(p.left,p.a,edgePoint(p.a.rect,1,30000,0),1000);
|
||||
check(p.left.mode()==ControlMode::Local,"no cross-screen handoff with physically held key/button");
|
||||
p.a.physicalHeld=false;motion(p.left,p.a,edgePoint(p.a.rect,1,30000,0),1100);
|
||||
p.a.heldKey=0;motion(p.left,p.a,edgePoint(p.a.rect,1,30000,0),1100);
|
||||
p.left.keyboard(key('X'),true,1101);p.deliver(1200);
|
||||
check(p.left.mode()==ControlMode::Local&&p.right.mode()==ControlMode::Local,"typing during handoff cancels stale accept");
|
||||
}
|
||||
@@ -298,6 +299,75 @@ void meshChecks()
|
||||
f.connections[0]["2"]=2;f.pump();check(f.meshes[0]->mode()==ControlMode::Local,"new connection generation does not continue stale ownership");
|
||||
}
|
||||
}
|
||||
void handoffBlockChecks()
|
||||
{
|
||||
for(int blockedPc:{0,1})
|
||||
for(int heldKey:{VK_TAB,VK_LBUTTON,UnknownHeldInput})
|
||||
{
|
||||
MeshFixture f;
|
||||
f.desktops[blockedPc].heldKey=heldKey;
|
||||
f.desktops[0].point={798,300};
|
||||
f.move(1,0);
|
||||
const auto sourceBlock=f.meshes[0]->handoffBlock();
|
||||
const auto blockedPcBlock=f.meshes[blockedPc]->handoffBlock();
|
||||
check(f.meshes[0]->mode()==ControlMode::Local&&sourceBlock.key==heldKey&&
|
||||
sourceBlock.peer==(blockedPc==0?"":"1")&&blockedPcBlock.key==heldKey&&blockedPcBlock.peer.empty(),
|
||||
"held input blocks the handoff and names the PC that is holding it");
|
||||
f.desktops[blockedPc].heldKey=0;
|
||||
f.pump();
|
||||
check(!f.meshes[0]->handoffBlock().key&&!f.meshes[blockedPc]->handoffBlock().key,
|
||||
"release clears both notices without another crossing attempt");
|
||||
f.now+=650;
|
||||
f.enter();
|
||||
}
|
||||
{
|
||||
MeshFixture f;
|
||||
f.meshes[1]->keyboard(key(VK_MEDIA_PLAY_PAUSE),true,f.now);
|
||||
f.desktops[1].heldKey=VK_MEDIA_PLAY_PAUSE;
|
||||
f.desktops[0].point={798,300};
|
||||
f.move(1,0);
|
||||
check(f.meshes[0]->handoffBlock().key==VK_MEDIA_PLAY_PAUSE,"tracked media key reports the Windows key identity");
|
||||
f.desktops[1].heldKey=0;
|
||||
f.meshes[1]->forgetHeldKeys();
|
||||
f.pump();
|
||||
check(!f.meshes[0]->handoffBlock().key&&!f.meshes[1]->handoffBlock().key,
|
||||
"manual reset also clears previously tracked held keys");
|
||||
f.now+=650;
|
||||
f.enter();
|
||||
}
|
||||
{
|
||||
MeshFixture f;
|
||||
f.desktops[1].heldKey=VK_TAB;
|
||||
f.desktops[0].point={798,300};
|
||||
f.move(1,0);
|
||||
f.desktops[1].heldKey=VK_XBUTTON2;
|
||||
f.pump();
|
||||
check(f.meshes[0]->handoffBlock().key==VK_XBUTTON2,"source notice updates when the destination blocker changes");
|
||||
f.connections[0]["1"]=2;
|
||||
f.pump();
|
||||
check(!f.meshes[0]->handoffBlock().key,"a reconnect discards notices from the prior connection generation");
|
||||
}
|
||||
}
|
||||
void heldInputReleaseChecks()
|
||||
{
|
||||
const auto releases=heldInputReleases([](int key){
|
||||
return key==VK_MEDIA_PLAY_PAUSE||key==VK_LBUTTON||key==VK_XBUTTON2||key==VK_CONTROL||key==VK_RCONTROL;
|
||||
});
|
||||
check(releases.size()==4,"reset includes only down inputs and does not duplicate a generic modifier");
|
||||
check(releases[0].type==INPUT_MOUSE&&releases[0].mi.dwFlags==MOUSEEVENTF_LEFTUP&&
|
||||
releases[0].mi.dwExtraInfo==inputMarker(),"reset releases the left mouse button without running mouse bindings");
|
||||
check(releases[1].type==INPUT_MOUSE&&releases[1].mi.dwFlags==MOUSEEVENTF_XUP&&
|
||||
releases[1].mi.mouseData==XBUTTON2,"reset releases the correct extra mouse button");
|
||||
check(releases[2].type==INPUT_KEYBOARD&&releases[2].ki.wVk==VK_RCONTROL&&
|
||||
(releases[2].ki.dwFlags&KEYEVENTF_KEYUP),"reset releases the specific modifier");
|
||||
check(releases[3].type==INPUT_KEYBOARD&&releases[3].ki.wVk==VK_MEDIA_PLAY_PAUSE&&
|
||||
releases[3].ki.dwFlags==(KEYEVENTF_KEYUP|KEYEVENTF_EXTENDEDKEY)&&releases[3].ki.dwExtraInfo==inputMarker(),
|
||||
"reset releases Play/Pause without generating a media key press");
|
||||
check(heldInputName(VK_TAB)==L"Tab"&&heldInputName(VK_MEDIA_PLAY_PAUSE)==L"Play/Pause"&&
|
||||
heldInputName(VK_LBUTTON)==L"Left mouse button"&&heldInputName(UnknownHeldInput).empty(),
|
||||
"known blockers have readable names and unknown ones use the general message");
|
||||
check(heldInputReleases([](int){return false;}).empty(),"reset with no down inputs is a no-op");
|
||||
}
|
||||
uint16_t freePort()
|
||||
{
|
||||
SOCKET s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);if(s==INVALID_SOCKET)throw std::runtime_error("test socket");
|
||||
@@ -567,6 +637,6 @@ void channelChecks()
|
||||
}
|
||||
int main()
|
||||
{
|
||||
try{channelChecks();hubChecks();offlineDiscoveryChecks();fallbackChecks();datagramChecks();routerChecks();meshChecks();std::cout<<"Passed "<<passed<<" LAN input checks\n";}
|
||||
try{channelChecks();hubChecks();offlineDiscoveryChecks();fallbackChecks();datagramChecks();routerChecks();meshChecks();handoffBlockChecks();heldInputReleaseChecks();std::cout<<"Passed "<<passed<<" LAN input checks\n";}
|
||||
catch(const std::exception &e){std::cerr<<"FAIL: "<<e.what()<<'\n';return 1;}
|
||||
}
|
||||
Reference in new issue
Block a user