Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6621a49022 | |||
| a2b88f247c | |||
| 684ca1b3cc | |||
| 524a836cc0 |
+1
-1
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(KSwitcher VERSION 0.6.39 LANGUAGES CXX RC)
|
||||
project(KSwitcher VERSION 0.6.43 LANGUAGES CXX RC)
|
||||
if(NOT WIN32)
|
||||
message(FATAL_ERROR "KSwitcher uses native Windows APIs")
|
||||
endif()
|
||||
|
||||
@@ -75,6 +75,9 @@ Ctrl+Alt+Delete and Win+L; these cannot be assigned.
|
||||
|
||||
Keyboard and mouse input forwarded by Microsoft Mouse Without Borders follows the same input
|
||||
path as a local keyboard/mouse, including shortcuts, recent-word conversion and snippets.
|
||||
On the sending computer, KSwitcher ignores keyboard events consumed by another keyboard hook
|
||||
(including Mouse Without Borders forwarding). The receiving computer still processes delivered
|
||||
input normally, so both computers can run KSwitcher without starting duplicate snippet operations.
|
||||
KSwitcher marks its own generated input so copy/paste, selection, modifier releases and shell-mask
|
||||
keys cannot trigger recursive commands or overwrite the recorded typing run. Other injected input
|
||||
is accepted, including key-up events and VK-only keyboard events. Unicode packets do not provide
|
||||
@@ -274,10 +277,18 @@ thumbnails and source labels aligned with the scaled fonts and spacing.
|
||||
of the complete expected text. Browser/editor compatibility depends on its handling of simulated input.
|
||||
- Selection conversion and verified recent input (physical scan codes, 2-second typing-run boundary).
|
||||
- Same-process clipboard ownership plus verified WebView2 descendants, including the Teams fix.
|
||||
Clipboard synchronizers such as Mouse Without Borders may republish a copy only when
|
||||
KSwitcher first observed it owned by the target application and the selection text and
|
||||
editor selection metadata remain identical. Unobserved or altered foreign copies are rejected.
|
||||
Snippets require accessibility verification of their selected trigger and pasted text,
|
||||
even with logging disabled. If verification is unavailable or the paste differs, expansion
|
||||
stops without running cursor or Enter actions. Clipboard changes during paste also cancel actions.
|
||||
- Teams recent-word conversion uses a single word-selection command and validates the copied range.
|
||||
If the editor's word boundary differs from the recorded typing, it falls back to paced character
|
||||
selection: Teams can coalesce a burst of Shift+Left events into just one character.
|
||||
- Clipboard snapshot/restoration with concurrent-copy, foreground and input-version checks.
|
||||
A snapshot interrupted by a concurrent clipboard publication is retried up to three total
|
||||
attempts before selection starts, provided the foreground and input context remain unchanged.
|
||||
A silently dropped copy is retried up to three total attempts while the clipboard and input
|
||||
context remain unchanged. Temporary transaction contents are excluded from Windows clipboard
|
||||
history and cloud synchronization. Paste is not blindly retried: with manual paste readback
|
||||
@@ -720,7 +731,11 @@ Consecutive duplicates use SHA-256 fingerprints inside the encrypted history ind
|
||||
|
||||
Moving OCR isolates its temporary memory rather than reducing the combined processing peak. A controlled three-run comparison retained about 0.8 MiB less private RAM in the caller after recognition; combined peak RAM was about 55.6 MiB before and 56.6 MiB with the helper. Results depend on the image, OCR engine and system.
|
||||
|
||||
### History process and clipboard memory — v0.6.39
|
||||
### Pinned history checkbox — v0.6.42
|
||||
|
||||
Check **★ Pinned only** beside the history search box to show only pinned entries; uncheck it to show all entries. The checkbox sits on the left, immediately followed by the search box; its right edge stays aligned with the history list when resizing. The text search applies within that filter. Unpinning an item removes it from the pinned view immediately. The checkbox state and search are remembered after closing and reopening history. **Clear history…** still deletes the entire history after confirmation, including entries hidden by the filter.
|
||||
|
||||
### History process and clipboard memory — v0.6.40
|
||||
|
||||
History opens in a separate, short-lived instance of **KSwitcher.exe**. **Esc** closes it even when focus is on the window or an action button, releasing Windows UI allocations with the process. The resident keeps keyboard hooks, clipboard capture and history storage. Search, selection and the top entry are preserved in encrypted view state. If a full-text item viewer is still open, the helper stays alive until the last viewer closes. Pin/delete, formatted/plain paste and OCR remain available; settings and default shortcuts are unchanged.
|
||||
|
||||
|
||||
Binary file not shown.
+12
-11
@@ -1,22 +1,23 @@
|
||||
# Latest Windows release
|
||||
|
||||
## v0.6.39 — 2026-11-04
|
||||
## v0.6.43 — 2026-11-04
|
||||
|
||||
## Changes
|
||||
- Clipboard history runs in a separate, short-lived instance of KSwitcher.exe. Closing history with Esc releases its UI process instead of retaining Windows UI allocations in the resident. Esc also works when the window itself or an action button has focus.
|
||||
- Search, selected/top entry, pinning, deletion, formatted/plain paste and OCR remain available. Search and selection are saved in encrypted view state. An open full-text viewer keeps the history process alive until that viewer closes.
|
||||
- Large image clipboard backups and image thumbnail decoding run in KSwitcher.Screenshot.exe. Encrypted temporary files and clipboard-sequence checks preserve the clipboard without keeping full backup images in the resident. Selection reads avoid unnecessary image copies.
|
||||
- History paste waits briefly for the target application's foreground activation after the history process closes, while retaining input and clipboard ownership checks. Settings and default shortcuts are unchanged; UI Automation remains in the resident.
|
||||
- Respect downstream keyboard-hook suppression before tracking input or starting snippets. This prevents source-side expansion of keys forwarded by Mouse Without Borders. Update KSwitcher on both computers, especially the keyboard-sharing source.
|
||||
- Verify snippet selection and pasted text through accessibility even with logging disabled. Unavailable verification, incorrect text or clipboard changes cancel further cursor/Enter actions. No snippet syntax, shortcut or default changed.
|
||||
- Accept identical clipboard relays only after observing target-owned content, preserving text and editor selection metadata checks. Unicode allocation padding and format order do not cause false mismatches; changed content remains rejected.
|
||||
- Retry clipboard snapshots interrupted by concurrent publication up to three times before selection, while input context remains unchanged.
|
||||
- Clicking a warning notification opens Logs. Copy rejection diagnostics include observed/current text, clipboard sequences and the sentinel for troubleshooting.
|
||||
|
||||
## Validation and memory
|
||||
The complete staged build passed dictionary equivalence (140,939 words), 105 sync checks, 315 native checks, 561 input checks, screenshot UI/save/registration, 48 updater checks and progress UI, clipboard snapshot/image capture integration, conversion/snippet integration and Windows OCR. Dedicated 500-entry history tests cover repeated Esc, search persistence, pin/delete, full-viewer lifetime, text/image paste, clipboard restoration, rejected foreign requests and helper shutdown. Actual selected/repeated Viber conversion and live Esc were also checked during development.
|
||||
## Validation
|
||||
Release regression checks cover dictionary equivalence (140,939 words), 105 sync checks, 319 native checks, 569 input checks, screenshot UI/save/registration, 48 updater checks and updater progress UI. The isolated snippet suite exercises an actual downstream forwarding hook, verifies no source-side copy or text changes, and checks normal expansion, Enter, buffered typing, copy retries and suppression of Enter after incorrect pasted text.
|
||||
|
||||
A local live development-build comparison measured **4.37 MiB before opening history and 4.35 MiB after two open/Esc cycles**, versus an earlier roughly 8–9 MiB plateau after closing history. A same-image backup benchmark reduced retained private resident memory from 12.78 MiB to 0.05 MiB. These are workload-specific observations, not a guaranteed footprint. Count all helper processes while history/OCR is active: combined active memory can be higher. No forced working-set trimming was used.
|
||||
Live two-computer validation with both instances updated remains outstanding. An older instance on either computer can still interfere; the fix does not accept unrelated clipboard contents.
|
||||
|
||||
## Upgrade
|
||||
Choose **Update** in the tray menu. Legacy v0.3.0–v0.4.1 clients first receive the v0.4.2 compatibility bridge, then the current full release. v0.2.3 and earlier require manual installation.
|
||||
For manual installation, exit KSwitcher, close screenshot editors and extract the entire ZIP into its installation folder. Keep personal `data/` and customized dictionaries.
|
||||
Choose **Update** in the tray menu on both computers. Legacy v0.3.0–v0.4.1 clients first receive the v0.4.2 compatibility bridge, then the current full release. v0.2.3 and earlier require manual installation.
|
||||
For manual installation, exit KSwitcher, close its configurator and screenshot editors, and extract the entire ZIP into its installation folder. Keep personal `data/` and customized dictionaries.
|
||||
|
||||
Download **KSwitcher-win-x64.zip** with **SHA256SUMS.txt**. Keep all three executables together; history uses another instance of KSwitcher.exe, so no fourth executable is required. The package contains no personal settings, credentials or clipboard history.
|
||||
Download **KSwitcher-win-x64.zip** with **SHA256SUMS.txt**. Keep all three executables together; history uses another instance of KSwitcher.exe. The package contains no personal settings, credentials or clipboard history.
|
||||
|
||||
Publish stable `release-vX.Y.Z` tags matching the executable version. Keep `v0.4.2` as the last legacy tag.
|
||||
|
||||
@@ -1 +1 @@
|
||||
bf3a0fed23ea73dd8422b63fe2f2724e5b02e70c4c66f014c7ebb59222aa91fb KSwitcher-win-x64.zip
|
||||
008f34a2a4a875acb07d21a39c0fad3a0cb63371edbcb91d393edf72543aea5e KSwitcher-win-x64.zip
|
||||
|
||||
+3
-3
@@ -9,8 +9,8 @@ IDC_SCREENSHOT_PENCIL CURSOR "icons/lucide/pencil.cur"
|
||||
1 RT_MANIFEST "app.manifest"
|
||||
201 RCDATA "update.ps1"
|
||||
1 VERSIONINFO
|
||||
FILEVERSION 0,6,38,0
|
||||
PRODUCTVERSION 0,6,38,0
|
||||
FILEVERSION 0,6,43,0
|
||||
PRODUCTVERSION 0,6,43,0
|
||||
FILEOS VOS_NT_WINDOWS32
|
||||
FILETYPE VFT_APP
|
||||
BEGIN
|
||||
@@ -20,7 +20,7 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "FileDescription", "KSwitcher — native keyboard and clipboard utility"
|
||||
VALUE "ProductName", "KSwitcher"
|
||||
VALUE "FileVersion", "0.6.38"
|
||||
VALUE "FileVersion", "0.6.43"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
+101
-17
@@ -78,6 +78,8 @@ class Transaction
|
||||
mutable bool invalidLogged{};
|
||||
unsigned copyNumber{};
|
||||
std::wstring adopted;
|
||||
Bytes adoptedFormats;
|
||||
bool trustedContentsObserved{};
|
||||
std::unique_ptr<PasteProbe> selectionProof;
|
||||
std::wstring provenSelection;
|
||||
|
||||
@@ -87,10 +89,26 @@ class Transaction
|
||||
app.suspended = true;
|
||||
try
|
||||
{
|
||||
expected = GetClipboardSequenceNumber();
|
||||
snapshot.capture(app.window, expected);
|
||||
if (expected != GetClipboardSequenceNumber())
|
||||
throw std::runtime_error("Clipboard changed while taking snapshot");
|
||||
for (unsigned attempt = 0; ; ++attempt)
|
||||
{
|
||||
expected = GetClipboardSequenceNumber();
|
||||
try
|
||||
{
|
||||
snapshot.capture(app.window, expected);
|
||||
if (expected != GetClipboardSequenceNumber())
|
||||
throw std::runtime_error("Clipboard changed while taking snapshot");
|
||||
break;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// No selection or clipboard write has happened yet. Recapture
|
||||
// the latest clipboard after a concurrent publisher settles.
|
||||
if (attempt >= 2 || !valid() || expected == GetClipboardSequenceNumber())
|
||||
throw;
|
||||
diagnosticEvent(L"Snapshot retry: clipboard changed during capture");
|
||||
Sleep(20);
|
||||
}
|
||||
}
|
||||
captured = true;
|
||||
}
|
||||
catch (...)
|
||||
@@ -132,9 +150,19 @@ class Transaction
|
||||
if (GetClipboardSequenceNumber() != expected)
|
||||
{
|
||||
auto now = GetClipboardSequenceNumber();
|
||||
if (adopted.empty() || !ownsClipboard(target) || readClipboard(app.window, 32 * 1024 * 1024, ClipboardRead::Selection).text() != adopted ||
|
||||
GetClipboardSequenceNumber() != now)
|
||||
auto current = readClipboard(app.window, 32 * 1024 * 1024, ClipboardRead::Selection);
|
||||
const bool sameContents = selectionClipboardIdentity(current) == adoptedFormats;
|
||||
if (adopted.empty() || (!trustedContentsObserved && !ownsClipboard(target)) ||
|
||||
!sameContents || GetClipboardSequenceNumber() != now)
|
||||
{
|
||||
diagnosticEvent(L"Clipboard check rejected: expectedSequence=" + std::to_wstring(expected) +
|
||||
L" readSequence=" + std::to_wstring(now) + L" currentSequence=" +
|
||||
std::to_wstring(GetClipboardSequenceNumber()) + L" owner=" +
|
||||
std::to_wstring((uintptr_t)GetClipboardOwner()) + L" sameContents=" +
|
||||
std::to_wstring(sameContents) + L" expectedText=" + diagnosticText(adopted) +
|
||||
L" currentText=" + diagnosticText(current.text()));
|
||||
throw std::runtime_error("Operation cancelled: another application changed the clipboard");
|
||||
}
|
||||
expected = now;
|
||||
}
|
||||
}
|
||||
@@ -142,6 +170,8 @@ class Transaction
|
||||
{
|
||||
check();
|
||||
adopted.clear();
|
||||
adoptedFormats.clear();
|
||||
trustedContentsObserved = false;
|
||||
// These are temporary transaction contents, not a user's clipboard entry.
|
||||
// In particular, do not invite the Windows history service to read our
|
||||
// sentinel while the target editor is trying to open the clipboard.
|
||||
@@ -164,10 +194,12 @@ class Transaction
|
||||
const auto number = ++copyNumber;
|
||||
if (!valid())
|
||||
return {};
|
||||
write(textClip(L"\x2063KSwitcher-" + std::to_wstring(GetTickCount64())));
|
||||
const auto sentinel = L"\x2063KSwitcher-" + std::to_wstring(GetTickCount64());
|
||||
write(textClip(sentinel));
|
||||
DWORD before = expected;
|
||||
diagnosticEvent(L"Copy begin number=" + std::to_wstring(number) + L" sentinelSequence=" +
|
||||
std::to_wstring(before) + L" target=" + std::to_wstring((uintptr_t)target));
|
||||
std::to_wstring(before) + L" target=" + std::to_wstring((uintptr_t)target) +
|
||||
L" sentinel=" + diagnosticText(sentinel));
|
||||
if (!valid() || !chord(L'C', MOD_CONTROL))
|
||||
{
|
||||
diagnosticEvent(L"Copy failed: context changed or simulated Ctrl+C blocked");
|
||||
@@ -179,6 +211,7 @@ class Transaction
|
||||
DWORD changed = before;
|
||||
ULONGLONG stable = 0;
|
||||
bool changedAgain = false;
|
||||
std::optional<Bytes> observedTargetCopy;
|
||||
while (GetTickCount64() < deadline)
|
||||
{
|
||||
if (!valid())
|
||||
@@ -193,6 +226,18 @@ class Transaction
|
||||
changedAgain |= changed != before;
|
||||
changed = now;
|
||||
stable = GetTickCount64();
|
||||
// Clipboard synchronizers can republish a legitimate copy under
|
||||
// their own HWND. Record provenance before that handoff; an
|
||||
// unobserved or altered foreign copy must still be rejected.
|
||||
if (ownsClipboard(target))
|
||||
{
|
||||
auto candidate = readClipboard(app.window, 32 * 1024 * 1024, ClipboardRead::Selection);
|
||||
if (GetClipboardSequenceNumber() == now && ownsClipboard(target) && !candidate.text().empty())
|
||||
{
|
||||
observedTargetCopy = selectionClipboardIdentity(candidate);
|
||||
diagnosticEvent(L"Copy: target-owned selection observed number=" + std::to_wstring(number));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed != before && GetTickCount64() - stable >= 60)
|
||||
break;
|
||||
@@ -224,16 +269,31 @@ class Transaction
|
||||
L"Copy failed: context changed");
|
||||
return {};
|
||||
}
|
||||
if ((GetClipboardOwner() ? !ownsClipboard(target) : changedAgain) ||
|
||||
changed != GetClipboardSequenceNumber())
|
||||
throw std::runtime_error("Operation cancelled: copy did not belong to the target application");
|
||||
expected = changed;
|
||||
const bool targetOwned = ownsClipboard(target);
|
||||
auto clip = readClipboard(app.window, 32 * 1024 * 1024, ClipboardRead::Selection);
|
||||
const auto formats = selectionClipboardIdentity(clip);
|
||||
const bool verifiedRelay = observedTargetCopy && *observedTargetCopy == formats;
|
||||
if (((GetClipboardOwner() ? !targetOwned : changedAgain) && !verifiedRelay) ||
|
||||
changed != GetClipboardSequenceNumber())
|
||||
{
|
||||
diagnosticEvent(L"Copy rejected: observedTarget=" + std::to_wstring(observedTargetCopy.has_value()) +
|
||||
L" verifiedRelay=" + std::to_wstring(verifiedRelay) + L" expectedSequence=" +
|
||||
std::to_wstring(changed) + L" currentSequence=" + std::to_wstring(GetClipboardSequenceNumber()) +
|
||||
L" owner=" + std::to_wstring((uintptr_t)GetClipboardOwner()) + L" targetText=" +
|
||||
diagnosticText(observedTargetCopy ? decodeClip(*observedTargetCopy).text() : L"") +
|
||||
L" currentText=" + diagnosticText(clip.text()));
|
||||
throw std::runtime_error("Operation cancelled: copy did not belong to the target application");
|
||||
}
|
||||
if (!targetOwned && verifiedRelay)
|
||||
diagnosticEvent(L"Copy: identical target selection republished by clipboard synchronizer");
|
||||
expected = changed;
|
||||
auto text = clip.text();
|
||||
diagnosticEvent(L"Copy result number=" + std::to_wstring(number) + L" attempts=" +
|
||||
std::to_wstring(attempts) + L" elapsedMs=" + std::to_wstring(GetTickCount64() - started) +
|
||||
L" text=" + diagnosticText(text));
|
||||
adopted = text;
|
||||
adoptedFormats = formats;
|
||||
trustedContentsObserved = targetOwned || verifiedRelay;
|
||||
check();
|
||||
for (auto &f : clip.formats)
|
||||
{
|
||||
@@ -359,6 +419,14 @@ class Transaction
|
||||
if (!valid())
|
||||
return false;
|
||||
write(clip);
|
||||
// Our verified payload is also trusted across an identical relay. The
|
||||
// sentinel written by copy() deliberately does not get this allowance.
|
||||
if (clip.formats.size() == 1 && clip.formats.front().id == CF_UNICODETEXT)
|
||||
{
|
||||
adopted = clip.text();
|
||||
adoptedFormats = selectionClipboardIdentity(clip);
|
||||
trustedContentsObserved = true;
|
||||
}
|
||||
// Viber's Qt editor observes clipboard changes asynchronously. Give it
|
||||
// a chance to discard the data object from Ctrl+C before requesting paste.
|
||||
// Recheck ownership and input below; never retry a possibly applied paste.
|
||||
@@ -376,6 +444,10 @@ class Transaction
|
||||
if (!chord(L'V', MOD_CONTROL))
|
||||
throw std::runtime_error("Windows blocked simulated input; check application privilege levels");
|
||||
Sleep(300);
|
||||
// A clipboard synchronizer may replace our payload after Ctrl+V is
|
||||
// queued but before the editor consumes it. Do not run snippet actions
|
||||
// (especially Enter) after such a race.
|
||||
check();
|
||||
return true;
|
||||
}
|
||||
bool nativeSelectionIs(const std::wstring &original) const
|
||||
@@ -955,6 +1027,15 @@ void App::replayTyping()
|
||||
}
|
||||
LRESULT CALLBACK App::keyProc(int code, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
// MWB suppresses source-machine events that it forwards elsewhere. Let
|
||||
// downstream hooks route the event before tracking it or starting a snippet.
|
||||
// Call the chain exactly once; a local event can still be consumed below.
|
||||
const auto routed = CallNextHookEx(nullptr, code, wp, lp);
|
||||
return keyboardAfterHooks(code, wp, lp, routed);
|
||||
}
|
||||
LRESULT App::keyboardAfterHooks(int code, WPARAM wp, LPARAM lp, LRESULT routed)
|
||||
{
|
||||
if (routed) return routed;
|
||||
if (code == HC_ACTION && current &&
|
||||
(wp == WM_KEYDOWN || wp == WM_SYSKEYDOWN || wp == WM_KEYUP || wp == WM_SYSKEYUP))
|
||||
{
|
||||
@@ -969,7 +1050,7 @@ LRESULT CALLBACK App::keyProc(int code, WPARAM wp, LPARAM lp)
|
||||
wp == WM_KEYDOWN || wp == WM_SYSKEYDOWN, mods))
|
||||
return 1;
|
||||
}
|
||||
return CallNextHookEx(nullptr, code, wp, lp);
|
||||
return routed;
|
||||
}
|
||||
LRESULT CALLBACK App::mouseProc(int code, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
@@ -1398,11 +1479,11 @@ void App::transform(int command, int snippet)
|
||||
}
|
||||
}
|
||||
bool sent = false;
|
||||
const bool requireReadback = tx.recoveredSelection();
|
||||
const bool requireReadback = tx.recoveredSelection() || snippet >= 0;
|
||||
PasteProbe probe(((config.writeLog && manual) || requireReadback) && result != text, text, target);
|
||||
if (requireReadback && result != text && probe.status != L"ready")
|
||||
{
|
||||
reason = L"recovered-selection-unavailable";
|
||||
reason = snippet >= 0 ? L"snippet-verification-unavailable" : L"recovered-selection-unavailable";
|
||||
std::lock_guard lock(stateMutex);
|
||||
last.reset();
|
||||
run.reset();
|
||||
@@ -1416,7 +1497,7 @@ void App::transform(int command, int snippet)
|
||||
chord(VK_RIGHT);
|
||||
if (requireReadback && result != text && !sent)
|
||||
{
|
||||
reason = L"recovered-selection-paste-cancelled";
|
||||
reason = snippet >= 0 ? L"snippet-paste-cancelled" : L"recovered-selection-paste-cancelled";
|
||||
std::lock_guard lock(stateMutex);
|
||||
last.reset();
|
||||
run.reset();
|
||||
@@ -1900,7 +1981,9 @@ LRESULT CALLBACK App::windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
app->replayTyping();
|
||||
return 0;
|
||||
case TrayMessage:
|
||||
if (LOWORD(lp) == WM_CONTEXTMENU)
|
||||
if (LOWORD(lp) == NIN_BALLOONUSERCLICK)
|
||||
showLogs(*app);
|
||||
else if (LOWORD(lp) == WM_CONTEXTMENU)
|
||||
app->trayMenu();
|
||||
else if (LOWORD(lp) == WM_LBUTTONDBLCLK)
|
||||
// The shell still owns the mouse gesture on the second button-down.
|
||||
@@ -2078,6 +2161,7 @@ int App::execute()
|
||||
historySelection = wide(state.value("selection", std::string{}));
|
||||
historyTop = wide(state.value("top", std::string{}));
|
||||
historyQuery = wide(state.value("query", std::string{}));
|
||||
historyPinnedOnly = state.value("pinnedOnly", false);
|
||||
} catch (...) {}
|
||||
showHistory(*this);
|
||||
remoteHistory("ready", std::to_wstring(reinterpret_cast<uintptr_t>(historyWindow)));
|
||||
|
||||
@@ -37,6 +37,7 @@ class App
|
||||
bool isolateHistory{};
|
||||
unsigned historyEntryWindows{};
|
||||
std::wstring historySelection, historyTop, historyQuery;
|
||||
bool historyPinnedOnly{};
|
||||
HINSTANCE instance{};
|
||||
std::filesystem::path data;
|
||||
std::vector<Layout> layouts;
|
||||
@@ -80,7 +81,7 @@ class App
|
||||
void refreshHistoryProcess();
|
||||
void remoteHistory(const char *action, const std::wstring &id = {}, bool plain = false);
|
||||
LRESULT historyRequest(HWND, const COPYDATASTRUCT &);
|
||||
void saveHistoryView(const std::wstring &, const std::wstring &, const std::wstring &);
|
||||
void saveHistoryView(const std::wstring &, const std::wstring &, const std::wstring &, bool);
|
||||
void clearLog(bool previous);
|
||||
void setHotkeyCapture(HWND);
|
||||
bool isHotkey(DWORD, UINT);
|
||||
@@ -142,6 +143,7 @@ class App
|
||||
void replayTyping();
|
||||
static LRESULT CALLBACK windowProc(HWND, UINT, WPARAM, LPARAM);
|
||||
static LRESULT CALLBACK keyProc(int, WPARAM, LPARAM);
|
||||
static LRESULT keyboardAfterHooks(int, WPARAM, LPARAM, LRESULT);
|
||||
static LRESULT CALLBACK mouseProc(int, WPARAM, LPARAM);
|
||||
};
|
||||
void showHistory(App &, bool visible = true);
|
||||
|
||||
+2
-2
@@ -90,11 +90,11 @@ LRESULT App::historyRequest(HWND sender, const COPYDATASTRUCT &message)
|
||||
return TRUE;
|
||||
} catch (...) { return FALSE; }
|
||||
}
|
||||
void App::saveHistoryView(const std::wstring &selection, const std::wstring &top, const std::wstring &query)
|
||||
void App::saveHistoryView(const std::wstring &selection, const std::wstring &top, const std::wstring &query, bool pinnedOnly)
|
||||
{
|
||||
if (!historyService) return;
|
||||
try {
|
||||
auto text = HistoryJson{{"selection", utf8(selection)}, {"top", utf8(top)}, {"query", utf8(query)}}.dump();
|
||||
auto text = HistoryJson{{"selection", utf8(selection)}, {"top", utf8(top)}, {"query", utf8(query)}, {"pinnedOnly", pinnedOnly}}.dump();
|
||||
atomicWrite(data / L"history-view.bin", protect(Bytes(text.begin(), text.end())));
|
||||
} catch (...) {} // Closing the UI must still release its process if state cannot be saved.
|
||||
}
|
||||
|
||||
+16
-1
@@ -344,6 +344,20 @@ Bytes encodeClip(const Clip &clip)
|
||||
}
|
||||
return b;
|
||||
}
|
||||
Bytes selectionClipboardIdentity(const Clip &clip)
|
||||
{
|
||||
auto normalized = clip;
|
||||
// GlobalSize includes allocation slack. A clipboard relay may allocate a
|
||||
// different-sized block for the same NUL-terminated Unicode string.
|
||||
for (auto &format : normalized.formats)
|
||||
if (format.id == CF_UNICODETEXT)
|
||||
format = textClip(clip.text()).formats.front();
|
||||
std::sort(normalized.formats.begin(), normalized.formats.end(), [](const Format &a, const Format &b)
|
||||
{
|
||||
return std::tie(a.name, a.id) < std::tie(b.name, b.id);
|
||||
});
|
||||
return encodeClip(normalized);
|
||||
}
|
||||
Clip decodeClip(const Bytes &b)
|
||||
{
|
||||
size_t p = 0;
|
||||
@@ -924,9 +938,10 @@ std::optional<std::wstring> History::ocrText(const std::wstring &id, const std::
|
||||
if (bytes.empty() || bytes.front() != 1) throw std::runtime_error("Invalid OCR text format");
|
||||
return wide(std::string(bytes.begin() + 1, bytes.end()));
|
||||
}
|
||||
std::vector<Entry> History::search(const std::wstring &query) const
|
||||
std::vector<Entry> History::search(const std::wstring &query, bool pinnedOnly) const
|
||||
{
|
||||
auto items = entries();
|
||||
if (pinnedOnly) std::erase_if(items, [](const Entry &entry) { return !entry.pinned; });
|
||||
if (query.empty())
|
||||
return items;
|
||||
auto q = lower(query);
|
||||
|
||||
+2
-1
@@ -43,9 +43,10 @@ class History
|
||||
void remove(const std::wstring &);
|
||||
void pin(const std::wstring &);
|
||||
void clear();
|
||||
std::vector<Entry> search(const std::wstring &) const;
|
||||
std::vector<Entry> search(const std::wstring &, bool pinnedOnly = false) const;
|
||||
};
|
||||
Bytes encodeClip(const Clip &);
|
||||
Bytes selectionClipboardIdentity(const Clip &);
|
||||
Clip decodeClip(const Bytes &);
|
||||
bool sameClipboardImage(const Clip &, const Clip &);
|
||||
int runImageHistoryCapture(const std::filesystem::path &request);
|
||||
|
||||
+16
-5
@@ -514,15 +514,16 @@ void search(HWND w, HistoryView *v)
|
||||
v->previewActive = std::make_shared<std::atomic<bool>>(true);
|
||||
v->closed = false;
|
||||
auto q = value(w, 101);
|
||||
const bool pinnedOnly = SendDlgItemMessageW(w, 117, BM_GETCHECK, 0, 0) == BST_CHECKED;
|
||||
auto generation = ++v->generation;
|
||||
v->pending.clear();
|
||||
auto *app = v->app;
|
||||
app->enqueueHistorySearch(
|
||||
[w, app, q, generation]
|
||||
[w, app, q, generation, pinnedOnly]
|
||||
{
|
||||
try
|
||||
{
|
||||
auto result = new SearchResult{generation, app->history->search(q)};
|
||||
auto result = new SearchResult{generation, app->history->search(q, pinnedOnly)};
|
||||
if (!PostMessageW(w, ResultsMessage, 0, (LPARAM)result))
|
||||
delete result;
|
||||
}
|
||||
@@ -739,6 +740,12 @@ LRESULT CALLBACK historyProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
case WM_COMMAND:
|
||||
{
|
||||
int id = LOWORD(wp);
|
||||
if (id == 117 && HIWORD(wp) == BN_CLICKED)
|
||||
{
|
||||
KillTimer(w, 1);
|
||||
search(w, v);
|
||||
return 0;
|
||||
}
|
||||
if (id == 101 && HIWORD(wp) == EN_CHANGE)
|
||||
{
|
||||
// Reject an older result even during the debounce interval.
|
||||
@@ -910,7 +917,8 @@ LRESULT CALLBACK historyProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
v->rememberedSelection = selected(w, v);
|
||||
int top = (int)SendDlgItemMessageW(w,102,LB_GETTOPINDEX,0,0);
|
||||
v->rememberedTop = top >= 0 && top < (int)v->items.size() ? v->items[top].id : L"";
|
||||
v->app->saveHistoryView(v->rememberedSelection, v->rememberedTop, value(w, 101));
|
||||
v->app->saveHistoryView(v->rememberedSelection, v->rememberedTop, value(w, 101),
|
||||
SendDlgItemMessageW(w, 117, BM_GETCHECK, 0, 0) == BST_CHECKED);
|
||||
KillTimer(w, 1);
|
||||
v->closed = true;
|
||||
v->previewActive->store(false);
|
||||
@@ -1737,8 +1745,11 @@ void showHistory(App &app, bool visible)
|
||||
HWND w = makeWindow(app, L"KSwitcher.History", L"Clipboard history", historyProc, 760, 500);
|
||||
app.historyWindow = w;
|
||||
windowLayoutState(w)->history = true;
|
||||
label(w, L"&Search clipboard history", 16, 12, 500);
|
||||
edit(w, 101, 16, 38, 728);
|
||||
auto filter = control(w, L"BUTTON", L"★ Pinned only", WS_TABSTOP | BS_AUTOCHECKBOX,
|
||||
117, 16, 38, 112, 25);
|
||||
SendMessageW(filter, BM_SETCHECK, app.historyPinnedOnly ? BST_CHECKED : BST_UNCHECKED, 0);
|
||||
label(w, L"&Search clipboard history", 136, 12, 500);
|
||||
edit(w, 101, 136, 38, 608);
|
||||
auto list = control(w, L"LISTBOX", L"",
|
||||
WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | WS_BORDER |
|
||||
LBS_OWNERDRAWFIXED | LBS_HASSTRINGS,
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
#include "platform.h"
|
||||
namespace ks
|
||||
{
|
||||
inline constexpr wchar_t AppVersion[] = L"0.6.39";
|
||||
inline constexpr wchar_t AppVersion[] = L"0.6.43";
|
||||
inline constexpr UINT UpdateMessage = WM_APP + 7;
|
||||
inline constexpr UINT UpdateCheckIntervalMs = 6 * 60 * 60 * 1000;
|
||||
inline constexpr UINT UpdateNotificationRetryMs = 5 * 60 * 1000;
|
||||
|
||||
+16
-1
@@ -112,9 +112,24 @@ int main() {
|
||||
auto w=open();send(w,WM_COMMAND,112);
|
||||
until([&]{history.reload();return history.entries().front().pinned;},"resident pin mutation");
|
||||
require(history.entries().front().id==textId,"pin preserves history identity");
|
||||
auto filter=[&](HWND window,int index) {
|
||||
auto checkbox=GetDlgItem(window,117);
|
||||
if(send(checkbox,BM_GETCHECK)!=(index ? BST_CHECKED : BST_UNCHECKED)) send(checkbox,BM_CLICK);
|
||||
};
|
||||
filter(w,1);
|
||||
until([&]{return send(GetDlgItem(w,102),LB_GETCOUNT)==1;},"pinned filter hides unpinned entries");
|
||||
send(GetDlgItem(w,101),WM_SETTEXT,0,LPARAM(L"History fixture 497"));
|
||||
until([&]{return send(GetDlgItem(w,102),LB_GETCOUNT)==0;},"search cannot match an unpinned item in pinned view");
|
||||
send(GetDlgItem(w,101),WM_SETTEXT,0,LPARAM(L"History fixture 498"));
|
||||
until([&]{return send(GetDlgItem(w,102),LB_GETCOUNT)==1;},"history search");
|
||||
send(w,WM_COMMAND,112);
|
||||
until([&]{return send(GetDlgItem(w,102),LB_GETCOUNT)==0;},"unpin removes the last pinned result");
|
||||
filter(w,0);
|
||||
until([&]{return send(GetDlgItem(w,102),LB_GETCOUNT)==1;},"all items restores the matching unpinned entry");
|
||||
send(w,WM_COMMAND,112);
|
||||
filter(w,1);
|
||||
close(w);w=open();
|
||||
require(send(GetDlgItem(w,117),BM_GETCHECK)==BST_CHECKED,"pinned checkbox survives helper restart");
|
||||
wchar_t query[100]{};send(GetDlgItem(w,101),WM_GETTEXT,100,LPARAM(query));
|
||||
require(std::wstring(query)==L"History fixture 498","search survives helper restart");
|
||||
send(w,WM_COMMAND,114);
|
||||
@@ -124,7 +139,7 @@ int main() {
|
||||
require(WaitForSingleObject(child,0)==WAIT_TIMEOUT && IsWindow(entry),"full item remains usable after closing history");
|
||||
send(entry,WM_CLOSE);
|
||||
until([&]{return WaitForSingleObject(child,0)==WAIT_OBJECT_0;},"helper exits after last full item closes");CloseHandle(child);
|
||||
w=open();send(GetDlgItem(w,101),WM_SETTEXT,0,LPARAM(L""));
|
||||
w=open();filter(w,0);send(GetDlgItem(w,101),WM_SETTEXT,0,LPARAM(L""));
|
||||
until([&]{return send(GetDlgItem(w,102),LB_GETCOUNT)==500;},"clear search");close(w);
|
||||
ks::writeClipboard(target,excluded(image));
|
||||
w=open();send(w,WM_COMMAND,111);
|
||||
|
||||
@@ -94,6 +94,9 @@ struct InputRegressionAccess {
|
||||
}
|
||||
static void notificationSetup(App &a) { a.updateNotifier = notify; }
|
||||
static void setup(App &a) { a.hookBindings = {{Toggle,{MOD_CONTROL,VK_F12}}, {Case,{MOD_CONTROL|MOD_SHIFT,'U'}}}; }
|
||||
static LRESULT routedKey(int code, UINT message, const KBDLLHOOKSTRUCT &key, LRESULT routed) {
|
||||
return App::keyboardAfterHooks(code,message,(LPARAM)&key,routed);
|
||||
}
|
||||
static bool updateTimer(App &a) {
|
||||
a.updateRunning=true; // Exercise timer scheduling without launching a network request.
|
||||
App::windowProc(a.window,WM_TIMER,5,0);
|
||||
@@ -648,6 +651,22 @@ int main(int argc, char **argv) {
|
||||
};
|
||||
auto commands=[&] { MSG m{}; int n=0; while(PeekMessageW(&m,app.window,WM_HOTKEY,WM_HOTKEY,PM_REMOVE)) ++n; return n; };
|
||||
auto f12=event(VK_F12);
|
||||
{
|
||||
const auto before = app.inputVersion.load();
|
||||
const auto recorded = app.run.keys;
|
||||
for (UINT message : {WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP})
|
||||
require(ks::InputRegressionAccess::routedKey(HC_ACTION,message,event('A',30),7)==7,
|
||||
"forwarded keyboard events preserve downstream suppression");
|
||||
require(app.inputVersion==before && app.run.keys==recorded && commands()==0,
|
||||
"forwarded events never track text, invalidate transactions or dispatch shortcuts");
|
||||
require(ks::InputRegressionAccess::routedKey(-1,WM_KEYDOWN,event('A',30),0)==0 &&
|
||||
app.inputVersion==before,"negative hook codes do not process keyboard input");
|
||||
require(ks::InputRegressionAccess::routedKey(HC_ACTION,WM_KEYDOWN,event('A',30,true),0)==0 &&
|
||||
app.inputVersion==before,"own input remains excluded after downstream routing");
|
||||
require(ks::InputRegressionAccess::routedKey(HC_ACTION,WM_KEYDOWN,event('A',30),0)==0 &&
|
||||
app.inputVersion>before,"delivered remote input is still processed on the receiver");
|
||||
app.run.reset();
|
||||
}
|
||||
require(!app.handleKeyboard(event(VK_LCONTROL),true,0),"remote modifier passes through");
|
||||
require(app.handleKeyboard(f12,true,MOD_CONTROL),"remote Ctrl+F12 handled");
|
||||
require(app.handleKeyboard(f12,true,MOD_CONTROL),"remote repeat suppressed");
|
||||
|
||||
+58
-1
@@ -33,6 +33,17 @@ bool trimCopiedSpaces = false;
|
||||
int trimmedCopies = 0;
|
||||
bool temporaryClipboardExcluded = true;
|
||||
bool clipboardAccessTimedOut = false;
|
||||
uint64_t forwardedVersion{};
|
||||
int forwardedEvents{};
|
||||
LRESULT CALLBACK forwardingHook(int code, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
if (code == HC_ACTION && reinterpret_cast<KBDLLHOOKSTRUCT *>(lp)->dwExtraInfo == 456)
|
||||
{
|
||||
++forwardedEvents;
|
||||
return 1; // Model MWB consuming source input routed to another machine.
|
||||
}
|
||||
return CallNextHookEx(nullptr, code, wp, lp);
|
||||
}
|
||||
LRESULT CALLBACK observeEnter(HWND w, UINT message, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR)
|
||||
{
|
||||
if (message == WM_KEYDOWN && wp == VK_LEFT && droppedSelectionKeys > 0 &&
|
||||
@@ -577,10 +588,41 @@ LRESULT CALLBACK procedure(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
require(ks::readClipboard(app->window).text() == sentinel, "selected and repeated conversions restore clipboard");
|
||||
finish();
|
||||
break;
|
||||
case 62:
|
||||
saved = ks::readClipboard(app->window, 64 * 1024 * 1024);
|
||||
captured = true;
|
||||
app->ownSequence = ks::writeClipboard(app->window, ks::textClip(sentinel));
|
||||
app->settings.snippets = {{L";r", L"unexpected{enter}"}};
|
||||
ActivateKeyboardLayout(app->layouts[en].handle, 0);
|
||||
prepare(L"prefix ", false);
|
||||
forwardedVersion = app->inputVersion.load();
|
||||
copyRequests = forwardedEvents = 0;
|
||||
{
|
||||
std::vector<INPUT> inputs;
|
||||
for (WORD key : {WORD(VK_OEM_1), WORD('R')})
|
||||
for (DWORD flags : {DWORD(0), DWORD(KEYEVENTF_KEYUP)})
|
||||
{
|
||||
auto input = ks::keyboardInput(key, flags);
|
||||
input.ki.dwExtraInfo = 456;
|
||||
inputs.push_back(input);
|
||||
}
|
||||
require(SendInput((UINT)inputs.size(),inputs.data(),sizeof(INPUT))==inputs.size(),
|
||||
"forwarded snippet input submitted to real hook chain");
|
||||
}
|
||||
break;
|
||||
case 63:
|
||||
require(forwardedEvents==4,"downstream forwarding hook consumed every key event");
|
||||
require(app->inputVersion==forwardedVersion && copyRequests==0,
|
||||
"forwarded snippet does not start tracking or clipboard work on source computer");
|
||||
require(text()==L"prefix " && ks::readClipboard(app->window).text()==sentinel,
|
||||
"forwarded snippet leaves source editor and clipboard untouched");
|
||||
stage = 30;
|
||||
break;
|
||||
case 30:
|
||||
case 32:
|
||||
case 34:
|
||||
case 37:
|
||||
case 60:
|
||||
// Earlier password/word tests replace the original multiline
|
||||
// editor with a single-line EDIT. Restore the snippet fixture:
|
||||
// a single-line control cannot insert the tested Enter action.
|
||||
@@ -609,6 +651,11 @@ LRESULT CALLBACK procedure(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
enterPresses = 0;
|
||||
copyRequests = 0;
|
||||
copyFailuresRemaining = stage == 38 ? 10 : stage == 33 ? 1 : 0;
|
||||
if (stage == 61)
|
||||
{
|
||||
pasteBehavior = 2; // Editor inserts unrelated clipboard text.
|
||||
app->settings.writeLog = false;
|
||||
}
|
||||
temporaryClipboardExcluded = true;
|
||||
ActivateKeyboardLayout(app->layouts[en].handle, 0);
|
||||
prepare(L"prefix ", false);
|
||||
@@ -672,6 +719,13 @@ LRESULT CALLBACK procedure(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
require(ks::readClipboard(app->window).text() == sentinel,
|
||||
"exhausted copy retries restore the clipboard");
|
||||
copyFailuresRemaining = 0;
|
||||
stage = 60;
|
||||
break;
|
||||
case 61:
|
||||
require(text() == L"prefix other! x", "incorrect snippet paste preserves following typing");
|
||||
require(enterPresses == 0, "unverified snippet never submits Enter even without logging");
|
||||
require(ks::readClipboard(app->window).text() == sentinel, "rejected snippet restores clipboard");
|
||||
pasteBehavior = 0;
|
||||
finish();
|
||||
break;
|
||||
case 20:
|
||||
@@ -985,9 +1039,12 @@ int main(int argc, char **argv)
|
||||
if (typosOnly || (argc > 1 && std::string(argv[1]) == "--typing-only"))
|
||||
stage = 20;
|
||||
if (argc > 1 && std::string(argv[1]) == "--snippets-only")
|
||||
stage = 30;
|
||||
stage = 62;
|
||||
SetTimer(host, 1, 100, nullptr);
|
||||
auto forwarding = SetWindowsHookExW(WH_KEYBOARD_LL,forwardingHook,GetModuleHandleW(nullptr),0);
|
||||
require(forwarding!=nullptr,"downstream forwarding fixture installed before application hook");
|
||||
app->execute();
|
||||
UnhookWindowsHookEx(forwarding);
|
||||
}
|
||||
std::filesystem::remove_all(root);
|
||||
}
|
||||
|
||||
@@ -517,6 +517,24 @@ int main(int argc, char **argv)
|
||||
auto encoded = ks::encodeClip(clip);
|
||||
require(ks::decodeClip(encoded).text() == clip.text(), "clipboard Unicode roundtrip");
|
||||
require(ks::decodeClip(encoded).formats[1].name == L"HTML Format", "registered format identity");
|
||||
auto selection = ks::textClip(L";pa");
|
||||
selection.formats.push_back({0, L"vscode-editor-data", {1, 2, 3}});
|
||||
auto relayed = selection;
|
||||
relayed.formats.front().data.resize(128, 0xab);
|
||||
std::reverse(relayed.formats.begin(), relayed.formats.end());
|
||||
require(ks::selectionClipboardIdentity(selection) == ks::selectionClipboardIdentity(relayed),
|
||||
"clipboard relay tolerates Unicode allocation slack and format order");
|
||||
relayed.formats.front().data[0] ^= 1;
|
||||
require(ks::selectionClipboardIdentity(selection) != ks::selectionClipboardIdentity(relayed),
|
||||
"clipboard relay rejects changed editor metadata");
|
||||
relayed = selection;
|
||||
relayed.formats.pop_back();
|
||||
require(ks::selectionClipboardIdentity(selection) != ks::selectionClipboardIdentity(relayed),
|
||||
"clipboard relay rejects missing editor metadata");
|
||||
relayed = selection;
|
||||
relayed.formats.front() = ks::textClip(L";pb").formats.front();
|
||||
require(ks::selectionClipboardIdentity(selection) != ks::selectionClipboardIdentity(relayed),
|
||||
"clipboard relay rejects changed Unicode text");
|
||||
auto encrypted = ks::protect(encoded);
|
||||
require(encrypted != encoded, "history ciphertext differs");
|
||||
require(ks::unprotect(encrypted) == encoded, "Windows DPAPI roundtrip");
|
||||
|
||||
Reference in New Issue
Block a user