Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9cbb29c07 | ||
|
|
187334aed2 | ||
|
|
f7620d164f | ||
|
|
47e10477e1 | ||
|
|
f2e403dd39 | ||
|
|
85cdce1b01 | ||
|
|
4acff70e49 |
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(KSwitcher VERSION 0.8.3 LANGUAGES C CXX RC)
|
||||
project(KSwitcher VERSION 0.8.4 LANGUAGES C CXX RC)
|
||||
if(NOT WIN32)
|
||||
message(FATAL_ERROR "KSwitcher uses native Windows APIs")
|
||||
endif()
|
||||
|
||||
+10
-2
@@ -35,7 +35,8 @@ retain their original reply formats.
|
||||
|
||||
- `capabilities` optionally takes a `peer`. It returns the broker `protocol`
|
||||
(2), `hostRevision`, and boolean `write`, `delete`, `move`,
|
||||
`revisionRead`, `onHostTransfer`, and `localEndpoint` fields. With no peer,
|
||||
`revisionRead`, `onHostTransfer`, `localEndpoint`, and optional
|
||||
`conflictPrompt` fields. With no peer,
|
||||
the fields describe the local broker and its grants. With a peer, the flags
|
||||
also account for its supported protocol. A peer with revision 0 still
|
||||
supports legacy browsing and downloading.
|
||||
@@ -57,7 +58,8 @@ retain their original reply formats.
|
||||
The recycle bin is subject to Windows availability on the paired host.
|
||||
- `transfer` takes `source` and `target` objects with a `peer` and `path`
|
||||
each, optional `move` (default false), and a `conflict` policy of `fail`
|
||||
(default), `skip`, or `replace`. Replace merges directories and replaces
|
||||
(default), `skip`, `replace`, or `ask` when `conflictPrompt` is available.
|
||||
Replace merges directories and replaces
|
||||
regular files after validating the destination revision. The broker
|
||||
allows at most one local endpoint, represented by `"peer": null`. For a
|
||||
local endpoint the client must open the pipe with Windows impersonation
|
||||
@@ -69,6 +71,12 @@ retain their original reply formats.
|
||||
final frame has `type: "complete"` and counts, or an error. Transfers
|
||||
on one paired computer use its own file service even across drives. The
|
||||
local pipe exchanges only control and status for transfers.
|
||||
- Ask merges directories and reports individual collisions in a JSON frame
|
||||
with `type: "conflict"`, target `path`, `incoming` and `existing` metadata
|
||||
(as in `stat`), and boolean `replaceable`. Respond with a JSON frame
|
||||
containing `decision: "replace"`, `"skip"`, or `"cancel"`. Send
|
||||
`decision: "wait"` at least once every five seconds while a prompt is open.
|
||||
Access is checked again after each reply and before publishing the file.
|
||||
- For a move, the copy phase finishes before source deletion begins.
|
||||
Skipped items remain at the source. Cancellation or failure can leave
|
||||
previously completed destination items. Failure during source cleanup
|
||||
|
||||
@@ -1044,6 +1044,16 @@ embedded in KSwitcher.Files.exe.
|
||||
.\tests\configuration.ps1 # Separate-process settings tests; close KSwitcher first
|
||||
```
|
||||
|
||||
To check snippet suggestions in a WebView2 app, focus a blank editable field and
|
||||
run `KSwitcherIntegration.exe --snippet-external-editor` without changing the
|
||||
foreground window. The test types `;`, checks that the popup opens without
|
||||
stealing focus, dismisses it, and removes the test character. In Dirlume, repeat
|
||||
in the Command line, the terminal at an idle prompt, and the text editor. Use
|
||||
`--insert` as the second argument to test Tab insertion in a blank text field.
|
||||
With a Dirlume build that supports KSwitcher terminal insertion, use
|
||||
`--terminal-insert` at a blank shell prompt and check that `snippet test`
|
||||
appears as an editable draft. Clear that draft without submitting it.
|
||||
|
||||
`-Test` also checks remote/own input separation, hidden Settings layout and scrolling, and updater
|
||||
package validation, file preservation and rollback in temporary fixture directories. It does not
|
||||
replace a running installation. Optional read-only network checks:
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
# Latest Windows release
|
||||
|
||||
## v0.8.4 — 2026-11-27
|
||||
|
||||
- **Settings.** Open **Languages → Languages for a chat** in the Settings tree to search for a chat and choose its keyboard layouts. Save changes with **Apply** or **Save**.
|
||||
- **Trusted LAN clients.** Clients such as Dirlume can ask how to handle individual file conflicts during copy or move. When supported, choose to replace, skip or cancel.
|
||||
|
||||
**Українською.**
|
||||
|
||||
- **Налаштування.** Відкрийте **Languages → Languages for a chat** у дереві Settings, щоб знайти чат і вибрати його розкладки. Застосуйте зміни кнопкою **Apply** або **Save**.
|
||||
- **Довірені клієнти LAN.** Клієнти на кшталт Dirlume можуть запитувати, як обробити окремі конфлікти файлів під час копіювання або переміщення. Якщо клієнт підтримує цю можливість, виберіть заміну, пропуск або скасування.
|
||||
|
||||
## v0.8.3 — 2026-11-26
|
||||
|
||||
- **Files.** Lavender now shows compact path segments with chevrons above both panes. The current folder has a rounded highlight. Click an ancestor to open it, the current folder to edit the path, or an ellipsis to reveal hidden folders.
|
||||
|
||||
@@ -1 +1 @@
|
||||
0726c819b43cd1508c4fa22b717ab13b0da826f5a48bbc3a4b0f10e6418d207a KSwitcher-win-x64.zip
|
||||
9035578c4aa96533a78dd1830966cf0b2f8d9de623f51ec2d111e62249d1c65d KSwitcher-win-x64.zip
|
||||
+42
-42
@@ -1,181 +1,181 @@
|
||||
{
|
||||
"version": "0.8.3",
|
||||
"schema": 1,
|
||||
"files": [
|
||||
{
|
||||
"sha256": "134aff7d86cdba13eecf9e32a0556e0267c0900800bd6dc1e9b005729190eb7a",
|
||||
"path": "KSwitcher.exe",
|
||||
"size": 3247616
|
||||
"sha256": "a7ad4db3cb46825c65b851c7e4cbd214f779eb5325a91ca7cdb96a3fe944d8a4",
|
||||
"size": 3251712
|
||||
},
|
||||
{
|
||||
"sha256": "7f90f6af18c9ac7f9e0f8255bfd339c49c9ea28e2da88d6b6e3443f6a867a1dd",
|
||||
"path": "KSwitcher.Config.exe",
|
||||
"size": 2849792
|
||||
"sha256": "c9d2dddc6e2a5e14be02680c1177e4813515e207bada399f255fcbf4aef5e884",
|
||||
"size": 2850304
|
||||
},
|
||||
{
|
||||
"sha256": "f010f82aba8ace45abf0b90db991804964c1ec18f783a4169add56f478c96344",
|
||||
"path": "KSwitcher.Screenshot.exe",
|
||||
"sha256": "1112fd25921d49ef20b3f71b0b8234eea3e9df47b1c1d207bfa22a9f7da34028",
|
||||
"size": 3193344
|
||||
},
|
||||
{
|
||||
"sha256": "caa66e3d8cddd094f1de317fb1a6410d4413f30034cdb61f130d7fcee21004bb",
|
||||
"path": "KSwitcher.Files.exe",
|
||||
"size": 6000640
|
||||
"sha256": "b2843967c9b70839e45ec3b8b48bffde41ff8994ea345317beb1bda28e6d6dff",
|
||||
"size": 6002688
|
||||
},
|
||||
{
|
||||
"sha256": "d3fce90bdeecb08596e377dea6a316354dd8949e32ff09b89d51be00c14e21b6",
|
||||
"path": "WebView2Loader.dll",
|
||||
"sha256": "d3fce90bdeecb08596e377dea6a316354dd8949e32ff09b89d51be00c14e21b6",
|
||||
"size": 194912
|
||||
},
|
||||
{
|
||||
"sha256": "e256f01188af527e4d06d21d06fbf785ae9c50d4b328bf03cbe0ba7f0aa4228f",
|
||||
"path": "terminal/addon-fit-LICENSE.txt",
|
||||
"sha256": "e256f01188af527e4d06d21d06fbf785ae9c50d4b328bf03cbe0ba7f0aa4228f",
|
||||
"size": 1103
|
||||
},
|
||||
{
|
||||
"sha256": "ba3ea256ce0620a0992a197d6c9baea64823fc93d8da07a9e366ca9943c18527",
|
||||
"path": "terminal/addon-fit.js",
|
||||
"sha256": "ba3ea256ce0620a0992a197d6c9baea64823fc93d8da07a9e366ca9943c18527",
|
||||
"size": 1521
|
||||
},
|
||||
{
|
||||
"sha256": "084d97a727b778fb10d31adcd557ee7840a38377ed60e0ef0f3ece93b349b1ef",
|
||||
"path": "terminal/index.html",
|
||||
"sha256": "084d97a727b778fb10d31adcd557ee7840a38377ed60e0ef0f3ece93b349b1ef",
|
||||
"size": 527
|
||||
},
|
||||
{
|
||||
"sha256": "792c48c5a849a15fdf9e37e8bcf9e6d1dd13b32b46c642a748a0a46a9919d473",
|
||||
"path": "terminal/markdown-it-LICENSE.txt",
|
||||
"sha256": "792c48c5a849a15fdf9e37e8bcf9e6d1dd13b32b46c642a748a0a46a9919d473",
|
||||
"size": 1073
|
||||
},
|
||||
{
|
||||
"sha256": "391f2aa638e75e6c7859d0a5c5650ef0956722a45998f17e05b83bc655778e1e",
|
||||
"path": "terminal/markdown-it.js",
|
||||
"sha256": "391f2aa638e75e6c7859d0a5c5650ef0956722a45998f17e05b83bc655778e1e",
|
||||
"size": 100786
|
||||
},
|
||||
{
|
||||
"sha256": "98984c8f76bd231dab00ef54034bfc2f29b365ee0b31c05edb16ad5216bd5bc2",
|
||||
"path": "terminal/markdown.html",
|
||||
"sha256": "98984c8f76bd231dab00ef54034bfc2f29b365ee0b31c05edb16ad5216bd5bc2",
|
||||
"size": 3800
|
||||
},
|
||||
{
|
||||
"sha256": "8b5429a035ce8ce11f77a222b5ee946844fd1e2999e1bb5c8f7c030ddbb1ff96",
|
||||
"path": "terminal/markdown.js",
|
||||
"sha256": "8b5429a035ce8ce11f77a222b5ee946844fd1e2999e1bb5c8f7c030ddbb1ff96",
|
||||
"size": 18721
|
||||
},
|
||||
{
|
||||
"sha256": "ec9fb67dcb25eccc416ed56e1aab819222c805a2a4bfe4cb19e7556bf2ffde80",
|
||||
"path": "terminal/mermaid-LICENSE.txt",
|
||||
"sha256": "ec9fb67dcb25eccc416ed56e1aab819222c805a2a4bfe4cb19e7556bf2ffde80",
|
||||
"size": 1089
|
||||
},
|
||||
{
|
||||
"sha256": "336df803d87a38b70a01e736e666c8f7601d2ce42f5e47c8fafe5d721074b9a3",
|
||||
"path": "terminal/mermaid.js",
|
||||
"sha256": "336df803d87a38b70a01e736e666c8f7601d2ce42f5e47c8fafe5d721074b9a3",
|
||||
"size": 5537838
|
||||
},
|
||||
{
|
||||
"sha256": "838707e2813f7d007f7f60670a78ae4a4a6c97ca9a235d623cb85e16dc50e0c7",
|
||||
"path": "terminal/terminal.js",
|
||||
"sha256": "838707e2813f7d007f7f60670a78ae4a4a6c97ca9a235d623cb85e16dc50e0c7",
|
||||
"size": 6627
|
||||
},
|
||||
{
|
||||
"sha256": "b569f629d00f2626a8100df2a1798210535621e42164dfd426a6fe5aac7b0ccd",
|
||||
"path": "terminal/xterm-LICENSE.txt",
|
||||
"sha256": "b569f629d00f2626a8100df2a1798210535621e42164dfd426a6fe5aac7b0ccd",
|
||||
"size": 1261
|
||||
},
|
||||
{
|
||||
"sha256": "854a7c0fb70e8b1a083c16797ab827299fb18744f5ad34f227b48337e33293c6",
|
||||
"path": "terminal/xterm.css",
|
||||
"sha256": "854a7c0fb70e8b1a083c16797ab827299fb18744f5ad34f227b48337e33293c6",
|
||||
"size": 7112
|
||||
},
|
||||
{
|
||||
"sha256": "14903579ff54664cd72f8e8699e6961a6272c21863ec1c3b118cdc8af5d4a972",
|
||||
"path": "terminal/xterm.js",
|
||||
"sha256": "14903579ff54664cd72f8e8699e6961a6272c21863ec1c3b118cdc8af5d4a972",
|
||||
"size": 488663
|
||||
},
|
||||
{
|
||||
"sha256": "d3c81140cce01c26bf6cbf52aa40e0825e1fa35b9a91d1387170a65d2597082c",
|
||||
"path": "LICENSE",
|
||||
"sha256": "d3c81140cce01c26bf6cbf52aa40e0825e1fa35b9a91d1387170a65d2597082c",
|
||||
"size": 4401
|
||||
},
|
||||
{
|
||||
"sha256": "61e08da79c44061654015ce6b0c4061c23ee1dd18237fbf09e9bfda3c0ea2831",
|
||||
"path": "json-LICENSE.txt",
|
||||
"sha256": "61e08da79c44061654015ce6b0c4061c23ee1dd18237fbf09e9bfda3c0ea2831",
|
||||
"size": 1096
|
||||
},
|
||||
{
|
||||
"sha256": "185c5a37521316e940ead89cbf0b1ba5862d810c7c966e6c6a14a4a515b23625",
|
||||
"path": "files-text-license.txt",
|
||||
"sha256": "185c5a37521316e940ead89cbf0b1ba5862d810c7c966e6c6a14a4a515b23625",
|
||||
"size": 883
|
||||
},
|
||||
{
|
||||
"sha256": "57d6d9b1f85ac93b3bc73f6f7bdf4346e896c4644d6fa461c380ae29070c029d",
|
||||
"path": "files-archive-license.txt",
|
||||
"sha256": "57d6d9b1f85ac93b3bc73f6f7bdf4346e896c4644d6fa461c380ae29070c029d",
|
||||
"size": 4990
|
||||
},
|
||||
{
|
||||
"sha256": "7997c62a2f766674ceb99976485a6cf5c772309e79101a400c421d526b82f6e4",
|
||||
"path": "files-image-license.txt",
|
||||
"sha256": "7997c62a2f766674ceb99976485a6cf5c772309e79101a400c421d526b82f6e4",
|
||||
"size": 3044
|
||||
},
|
||||
{
|
||||
"sha256": "19c254c71ee49aefbd8854ac55b05d719c5f1e4f8ef9a982324b898501b39594",
|
||||
"path": "files-sftp-license.txt",
|
||||
"sha256": "19c254c71ee49aefbd8854ac55b05d719c5f1e4f8ef9a982324b898501b39594",
|
||||
"size": 2064
|
||||
},
|
||||
{
|
||||
"sha256": "be1b3fca2a291284ab550e9e77042fb27ecf927861d2d8fb8ec4907258477f01",
|
||||
"path": "README.md",
|
||||
"size": 105515
|
||||
"sha256": "7f179b561fab6125f167203a6ae180a7050d876b056c39f62f3be36cf4bad733",
|
||||
"size": 105904
|
||||
},
|
||||
{
|
||||
"sha256": "917c2f41b3943647fdfafa911d93f72b8c6fb0d08592016ce1a698d256e038bb",
|
||||
"path": "LAN-PREVIEW.md",
|
||||
"size": 16722
|
||||
"sha256": "4eac1f410e6b544aa45756e24f4fdfe9193c6f732410656160be54ab27a0d7e4",
|
||||
"size": 17245
|
||||
},
|
||||
{
|
||||
"sha256": "d0c022b27b9fbc2ff7b6b8bec723cc1adc4eef517202f9ff77eed5d8bea3acb9",
|
||||
"path": "dictionaries/en.txt",
|
||||
"sha256": "d0c022b27b9fbc2ff7b6b8bec723cc1adc4eef517202f9ff77eed5d8bea3acb9",
|
||||
"size": 732485
|
||||
},
|
||||
{
|
||||
"sha256": "0bdfb0201d1803634f268cdff0993b8349d2c70e956a06dbb667c8dd65254ec5",
|
||||
"path": "dictionaries/LICENSE-CC-BY-SA-4.0.txt",
|
||||
"sha256": "0bdfb0201d1803634f268cdff0993b8349d2c70e956a06dbb667c8dd65254ec5",
|
||||
"size": 20566
|
||||
},
|
||||
{
|
||||
"sha256": "3017bf44d3be9d9dfab21bd6778aa52b7947e61acf9ce2bc86b41d6e949ac311",
|
||||
"path": "dictionaries/README.md",
|
||||
"sha256": "3017bf44d3be9d9dfab21bd6778aa52b7947e61acf9ce2bc86b41d6e949ac311",
|
||||
"size": 2265
|
||||
},
|
||||
{
|
||||
"sha256": "80e6b6a27815973535f7facb636c597eb845dfee45cfabfc4e9b3341b9332849",
|
||||
"path": "dictionaries/ru.txt",
|
||||
"sha256": "80e6b6a27815973535f7facb636c597eb845dfee45cfabfc4e9b3341b9332849",
|
||||
"size": 1109134
|
||||
},
|
||||
{
|
||||
"sha256": "98e5b3fe7304e37705c9e5ff48b0b399ccb16e806736d21f09921b99e5f2a408",
|
||||
"path": "dictionaries/sources.json",
|
||||
"sha256": "98e5b3fe7304e37705c9e5ff48b0b399ccb16e806736d21f09921b99e5f2a408",
|
||||
"size": 1280
|
||||
},
|
||||
{
|
||||
"sha256": "d30e990d6ec2983c04f3644a3c61c6c668e8c542323f5931916fdd55b916eebf",
|
||||
"path": "dictionaries/uk.txt",
|
||||
"sha256": "d30e990d6ec2983c04f3644a3c61c6c668e8c542323f5931916fdd55b916eebf",
|
||||
"size": 940799
|
||||
},
|
||||
{
|
||||
"sha256": "a34b5161a8315af037e1ec71d816bfc688f7c364141d4ee2347cf0515ef0c82a",
|
||||
"path": "tools/README.txt",
|
||||
"sha256": "a34b5161a8315af037e1ec71d816bfc688f7c364141d4ee2347cf0515ef0c82a",
|
||||
"size": 993
|
||||
},
|
||||
{
|
||||
"sha256": "b6a36bcdc26fc6bb55083e023e2fafb60236e541e9b1b7e598c66816a3089175",
|
||||
"path": "tools/StayHere.exe",
|
||||
"sha256": "1530796fac99f1542b992e4254fc30c16c24ee7e6c6dc7b6ba41d241e3ea6417",
|
||||
"size": 133120
|
||||
},
|
||||
{
|
||||
"sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413",
|
||||
"path": "tools/StayHere-README.md",
|
||||
"sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413",
|
||||
"size": 2796
|
||||
}
|
||||
]
|
||||
],
|
||||
"version": "0.8.4"
|
||||
}
|
||||
+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,3,0
|
||||
PRODUCTVERSION 0,8,3,0
|
||||
FILEVERSION 0,8,4,0
|
||||
PRODUCTVERSION 0,8,4,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.3"
|
||||
VALUE "FileVersion", "0.8.4"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
+196
-29
@@ -45,26 +45,107 @@ GUITHREADINFO snippetGuiInfo(HWND target)
|
||||
return info;
|
||||
}
|
||||
|
||||
std::optional<RECT> accessibleSnippetCaret(HWND target)
|
||||
using Microsoft::WRL::ComPtr;
|
||||
constexpr std::wstring_view terminalSnippetTicketPrefix = L"dirlume-terminal-snippet-v1:";
|
||||
|
||||
bool snippetElementClass(IUIAutomationElement *element, std::wstring_view name)
|
||||
{
|
||||
BSTR className{};
|
||||
const bool matches = SUCCEEDED(element->get_CurrentClassName(&className)) && className && className == name;
|
||||
SysFreeString(className);
|
||||
return matches;
|
||||
}
|
||||
|
||||
ComPtr<IUIAutomationElement> focusedSnippetElement(IUIAutomation2 *automation, HWND target)
|
||||
{
|
||||
using Microsoft::WRL::ComPtr;
|
||||
ComPtr<IUIAutomation2> automation;
|
||||
if (FAILED(CoCreateInstance(CLSID_CUIAutomation8, nullptr, CLSCTX_INPROC_SERVER,
|
||||
IID_IUIAutomation2, reinterpret_cast<void **>(automation.GetAddressOf()))))
|
||||
return {};
|
||||
automation->put_ConnectionTimeout(150);
|
||||
automation->put_TransactionTimeout(150);
|
||||
ComPtr<IUIAutomationElement> focused;
|
||||
if (FAILED(automation->GetFocusedElement(&focused)) || !focused)
|
||||
return {};
|
||||
DWORD process{};
|
||||
GetWindowThreadProcessId(target, &process);
|
||||
int focusedProcess{};
|
||||
BOOL password = TRUE;
|
||||
if (!process || FAILED(focused->get_CurrentProcessId(&focusedProcess)) ||
|
||||
process != static_cast<DWORD>(focusedProcess) ||
|
||||
FAILED(focused->get_CurrentIsPassword(&password)) || password)
|
||||
if (FAILED(focused->get_CurrentIsPassword(&password)) || password ||
|
||||
!focusedTextBelongsToWindow(automation, focused.Get(), target))
|
||||
return {};
|
||||
return focused;
|
||||
}
|
||||
|
||||
ComPtr<IUIAutomation2> snippetAutomation()
|
||||
{
|
||||
ComPtr<IUIAutomation2> automation;
|
||||
if (FAILED(CoCreateInstance(CLSID_CUIAutomation8, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&automation))))
|
||||
return {};
|
||||
automation->put_ConnectionTimeout(150);
|
||||
automation->put_TransactionTimeout(150);
|
||||
return automation;
|
||||
}
|
||||
|
||||
ComPtr<IUIAutomationValuePattern> terminalSnippetInput(IUIAutomation *automation, IUIAutomationElement *focused)
|
||||
{
|
||||
// The receiver is a sibling of this terminal's focused xterm input.
|
||||
ComPtr<IUIAutomationTreeWalker> walker;
|
||||
ComPtr<IUIAutomationElement> parent, input;
|
||||
ComPtr<IUIAutomationCondition> condition;
|
||||
if (FAILED(automation->get_RawViewWalker(&walker)) || !walker ||
|
||||
FAILED(walker->GetParentElement(focused, &parent)) || !parent)
|
||||
return {};
|
||||
VARIANT className{};
|
||||
className.vt = VT_BSTR;
|
||||
className.bstrVal = SysAllocString(L"dirlume-terminal-snippet-input");
|
||||
const auto result = automation->CreatePropertyCondition(UIA_ClassNamePropertyId, className, &condition);
|
||||
VariantClear(&className);
|
||||
if (FAILED(result) || !condition ||
|
||||
FAILED(parent->FindFirst(TreeScope_Children, condition.Get(), &input)) || !input)
|
||||
return {};
|
||||
ComPtr<IUIAutomationValuePattern> value;
|
||||
input->GetCurrentPatternAs(UIA_ValuePatternId, IID_PPV_ARGS(&value));
|
||||
return value;
|
||||
}
|
||||
|
||||
std::wstring terminalSnippetTicket(IUIAutomationValuePattern *value)
|
||||
{
|
||||
if (!value) return {};
|
||||
BSTR ticket{};
|
||||
const auto result = value->get_CurrentValue(&ticket);
|
||||
const std::wstring_view text(ticket ? ticket : L"", SysStringLen(ticket));
|
||||
auto accepted = SUCCEEDED(result) && text.size() == terminalSnippetTicketPrefix.size() + 36 &&
|
||||
text.starts_with(terminalSnippetTicketPrefix) ? std::wstring(text) : std::wstring();
|
||||
SysFreeString(ticket);
|
||||
return accepted;
|
||||
}
|
||||
|
||||
std::optional<Template> terminalSnippetTemplate(const Snippet &snippet)
|
||||
{
|
||||
auto value = parseTemplate(snippet.text);
|
||||
if (value.text.empty() || value.text.size() > 8192 || !value.actions.empty() ||
|
||||
std::any_of(value.text.begin(), value.text.end(), [](wchar_t c) {
|
||||
return c < 0x20 || (c >= 0x7f && c <= 0x9f) || c == 0x2028 || c == 0x2029;
|
||||
})) return {};
|
||||
return value;
|
||||
}
|
||||
|
||||
std::optional<SnippetAnchor> accessibleSnippetCaret(HWND target)
|
||||
{
|
||||
const auto automation = snippetAutomation();
|
||||
if (!automation) return {};
|
||||
const auto focused = focusedSnippetElement(automation.Get(), target);
|
||||
if (!focused) return {};
|
||||
|
||||
// The xterm.js input follows the terminal cursor for IME. Dirlume
|
||||
// handles replacement in the active shell draft through a separate input.
|
||||
if (snippetElementClass(focused.Get(), L"xterm-helper-textarea"))
|
||||
{
|
||||
RECT cell{};
|
||||
BOOL offscreen = TRUE;
|
||||
if (SUCCEEDED(focused->get_CurrentIsOffscreen(&offscreen)) && !offscreen &&
|
||||
SUCCEEDED(focused->get_CurrentBoundingRectangle(&cell)) && cell.right > cell.left &&
|
||||
cell.bottom > cell.top)
|
||||
{
|
||||
auto ticket = lower(processName(target)) == L"dirlume" ?
|
||||
terminalSnippetTicket(terminalSnippetInput(automation.Get(), focused.Get()).Get()) : std::wstring();
|
||||
return SnippetAnchor{{cell.left, cell.top, cell.left, cell.bottom}, true, std::move(ticket)};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ComPtr<IUIAutomationTextPattern2> pattern;
|
||||
ComPtr<IUIAutomationTextRange> range;
|
||||
BOOL active{};
|
||||
@@ -121,7 +202,7 @@ std::optional<RECT> accessibleSnippetCaret(HWND target)
|
||||
}
|
||||
}
|
||||
SafeArrayDestroy(rectangles);
|
||||
if (anchor && anchor->bottom > anchor->top) return anchor;
|
||||
if (anchor && anchor->bottom > anchor->top) return SnippetAnchor{*anchor};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -1485,6 +1566,12 @@ void App::matchSnippets(HWND fg, bool expandExact)
|
||||
!snippetWordCharacter(layout->at(physicalLayout().code(previous)));
|
||||
}))
|
||||
{
|
||||
if (snippetPopupAnchor.terminal && snippetTarget == fg && snippetPopup &&
|
||||
IsWindowVisible(snippetPopup) && snippetFocus == snippetGuiInfo(fg).hwndFocus)
|
||||
{
|
||||
hideSnippetPopup();
|
||||
return;
|
||||
}
|
||||
queueSnippet(fg, i, sn.trigger.size());
|
||||
return;
|
||||
}
|
||||
@@ -1559,11 +1646,11 @@ void App::showSnippetPopup()
|
||||
if ((info.rcCaret.left || info.rcCaret.top || anchor.bottom - anchor.top >= 4) &&
|
||||
snippetCaretInside(anchor, bounds))
|
||||
{
|
||||
placeSnippetPopup(anchor);
|
||||
placeSnippetPopup({anchor});
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (snippetPopup && IsWindowVisible(snippetPopup) && snippetCaretInside(snippetPopupAnchor, bounds))
|
||||
if (snippetPopup && IsWindowVisible(snippetPopup) && snippetCaretInside(snippetPopupAnchor.bounds, bounds))
|
||||
placeSnippetPopup(snippetPopupAnchor);
|
||||
if (snippetCaretPending) return;
|
||||
snippetCaretPending = true;
|
||||
@@ -1572,6 +1659,14 @@ void App::showSnippetPopup()
|
||||
const auto receiver = window;
|
||||
enqueue([this, version, target, receiver] {
|
||||
auto caret = GetForegroundWindow() == target ? accessibleSnippetCaret(target) : std::nullopt;
|
||||
if (!caret && inputVersion == version && GetForegroundWindow() == target)
|
||||
{
|
||||
// A WebView can expose the old, empty field while the keystroke
|
||||
// that requested suggestions is still reaching its renderer.
|
||||
Sleep(45);
|
||||
if (inputVersion == version && GetForegroundWindow() == target)
|
||||
caret = accessibleSnippetCaret(target);
|
||||
}
|
||||
{
|
||||
std::lock_guard lock(stateMutex);
|
||||
snippetCaret = caret;
|
||||
@@ -1579,9 +1674,22 @@ void App::showSnippetPopup()
|
||||
PostMessageW(receiver, SnippetCaretMessage, static_cast<WPARAM>(version), 0);
|
||||
});
|
||||
}
|
||||
void App::placeSnippetPopup(RECT anchor)
|
||||
void App::placeSnippetPopup(SnippetAnchor placement)
|
||||
{
|
||||
snippetPopupAnchor = anchor;
|
||||
if (placement.terminal && placement.canInsert())
|
||||
{
|
||||
const auto previous = snippetMatches[snippetSelection];
|
||||
std::erase_if(snippetMatches, [&](size_t index) { return !terminalSnippetTemplate(settings.snippets[index]); });
|
||||
if (snippetMatches.empty())
|
||||
{
|
||||
hideSnippetPopup();
|
||||
return;
|
||||
}
|
||||
const auto selected = std::find(snippetMatches.begin(), snippetMatches.end(), previous);
|
||||
snippetSelection = selected == snippetMatches.end() ? 0 : static_cast<size_t>(selected - snippetMatches.begin());
|
||||
}
|
||||
snippetPopupAnchor = std::move(placement);
|
||||
const auto &anchor = snippetPopupAnchor.bounds;
|
||||
if (!snippetPopup)
|
||||
{
|
||||
WNDCLASSW cls{};
|
||||
@@ -1630,24 +1738,83 @@ void App::placeSnippetPopup(RECT anchor)
|
||||
InvalidateRect(snippetPopup, nullptr, FALSE);
|
||||
SetTimer(window, SnippetPopupTimer, 100, nullptr);
|
||||
}
|
||||
void App::selectSnippet(size_t row)
|
||||
bool App::selectSnippet(size_t row)
|
||||
{
|
||||
if (row >= snippetMatches.size() || !snippetPopupCurrent()) return;
|
||||
if (!snippetPopupAnchor.canInsert() || row >= snippetMatches.size() || !snippetPopupCurrent()) return false;
|
||||
const auto index = snippetMatches[row];
|
||||
const auto length = snippetPrefixLength;
|
||||
hideSnippetPopup();
|
||||
std::lock_guard lock(stateMutex);
|
||||
if (snippetPopupVersion == inputVersion && !busy)
|
||||
queueSnippet(snippetTarget, index, length, snippetFocus);
|
||||
if (!snippetPopupCurrent()) return false;
|
||||
if (!snippetPopupAnchor.terminal)
|
||||
{
|
||||
hideSnippetPopup();
|
||||
return queueSnippet(snippetTarget, index, length, snippetFocus);
|
||||
}
|
||||
const auto layout = std::find_if(layouts.begin(), layouts.end(), [&](const auto &item) {
|
||||
return item.handle == run.layout && item.convertible;
|
||||
});
|
||||
if (layout == layouts.end() || run.window != snippetTarget || run.keys.size() < length)
|
||||
return false;
|
||||
const auto replacement = terminalSnippetTemplate(settings.snippets[index]);
|
||||
if (!replacement) return false;
|
||||
std::wstring prefix;
|
||||
for (wchar_t key : std::wstring_view(run.keys).substr(run.keys.size() - length))
|
||||
prefix += layout->at(physicalLayout().code(key));
|
||||
if (prefix.empty() || prefix.find(L'\0') != prefix.npos) return false;
|
||||
|
||||
const auto ticket = snippetPopupAnchor.terminalTicket;
|
||||
const auto target = snippetTarget;
|
||||
const auto editor = snippetFocus;
|
||||
const auto request = wide(DiagnosticJson::array({utf8(ticket), utf8(prefix), utf8(replacement->text),
|
||||
replacement->text.size() - replacement->suffix.size()}).dump(-1, ' ', true, DiagnosticJson::error_handler_t::replace));
|
||||
hideSnippetPopup();
|
||||
run.reset();
|
||||
const auto version = ++inputVersion;
|
||||
typingTarget = target;
|
||||
snippetTyping = true;
|
||||
busy = true;
|
||||
enqueue([this, target, editor, version, ticket, request] {
|
||||
struct Replay
|
||||
{
|
||||
HWND window;
|
||||
~Replay() { PostMessageW(window, ReplayTypingMessage, 0, 0); }
|
||||
} replay{window};
|
||||
const auto current = [&] {
|
||||
return inputVersion == version && GetForegroundWindow() == target && snippetGuiInfo(target).hwndFocus == editor;
|
||||
};
|
||||
if (!current()) return;
|
||||
const auto automation = snippetAutomation();
|
||||
if (!automation) return;
|
||||
const auto focused = focusedSnippetElement(automation.Get(), target);
|
||||
if (!focused || !snippetElementClass(focused.Get(), L"xterm-helper-textarea")) return;
|
||||
const auto input = terminalSnippetInput(automation.Get(), focused.Get());
|
||||
if (terminalSnippetTicket(input.Get()) != ticket || !current()) return;
|
||||
BSTR payload = SysAllocStringLen(request.data(), static_cast<UINT>(request.size()));
|
||||
if (!payload) return;
|
||||
const auto sent = input->SetValue(payload);
|
||||
SysFreeString(payload);
|
||||
if (FAILED(sent)) return;
|
||||
|
||||
// Keep subsequent keystrokes ordered behind the renderer's draft edit.
|
||||
const auto until = GetTickCount64() + 200;
|
||||
while (current() && GetTickCount64() < until)
|
||||
{
|
||||
const auto reply = terminalSnippetTicket(input.Get());
|
||||
if (!reply.empty() && reply != ticket) return;
|
||||
Sleep(10);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
bool App::handleSnippetKey(DWORD vk, UINT mods)
|
||||
{
|
||||
if (!snippetPopupAnchor.canInsert() && vk != VK_ESCAPE) return false;
|
||||
const bool accept = vk == VK_TAB ||
|
||||
(vk == VK_RETURN && (snippetNavigated || snippetMatches.size() == 1));
|
||||
(!snippetPopupAnchor.terminal && vk == VK_RETURN && (snippetNavigated || snippetMatches.size() == 1));
|
||||
if (mods || (!accept && vk != VK_UP && vk != VK_DOWN && vk != VK_ESCAPE) ||
|
||||
!snippetPopup || !IsWindowVisible(snippetPopup) || !snippetPopupCurrent())
|
||||
return false;
|
||||
if (accept) selectSnippet(snippetSelection);
|
||||
if (accept) return selectSnippet(snippetSelection);
|
||||
else if (vk == VK_ESCAPE) hideSnippetPopup();
|
||||
else
|
||||
{
|
||||
@@ -1690,7 +1857,7 @@ LRESULT CALLBACK App::snippetPopupProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
const LONG top = static_cast<LONG>(i - first) * app->snippetRowHeight;
|
||||
RECT row{0, top, bounds.right, top + app->snippetRowHeight};
|
||||
const bool selected = i == app->snippetSelection;
|
||||
const bool selected = app->snippetPopupAnchor.canInsert() && i == app->snippetSelection;
|
||||
if (selected) FillRect(dc, &row, GetSysColorBrush(COLOR_HIGHLIGHT));
|
||||
SetTextColor(dc, GetSysColor(selected ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
|
||||
row.left += MulDiv(8, dpi, 96);
|
||||
@@ -3603,13 +3770,13 @@ LRESULT CALLBACK App::windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
app->showSnippetPopup();
|
||||
return 0;
|
||||
}
|
||||
std::optional<RECT> caret;
|
||||
std::optional<SnippetAnchor> caret;
|
||||
{
|
||||
std::lock_guard lock(app->stateMutex);
|
||||
caret = app->snippetCaret;
|
||||
}
|
||||
RECT bounds{};
|
||||
if (caret && GetWindowRect(app->snippetTarget, &bounds) && snippetCaretInside(*caret, bounds))
|
||||
if (caret && GetWindowRect(app->snippetTarget, &bounds) && snippetCaretInside(caret->bounds, bounds))
|
||||
{
|
||||
app->placeSnippetPopup(*caret);
|
||||
return 0;
|
||||
|
||||
@@ -23,6 +23,13 @@ inline constexpr int Toggle = 1, Case = 2, Translit = 3, Undo = 4, ShowHistory =
|
||||
inline constexpr UINT AutoCorrectMessage = WM_APP + 6;
|
||||
inline constexpr UINT ReplayTypingMessage = WM_APP + 30;
|
||||
inline constexpr UINT CaptureHotkeyMessage = WM_APP + 5;
|
||||
struct SnippetAnchor
|
||||
{
|
||||
RECT bounds{};
|
||||
bool terminal{};
|
||||
std::wstring terminalTicket;
|
||||
bool canInsert() const { return !terminal || !terminalTicket.empty(); }
|
||||
};
|
||||
struct LastTransform
|
||||
{
|
||||
HWND window{};
|
||||
@@ -203,20 +210,20 @@ class App
|
||||
bool snippetNavigated{};
|
||||
int snippetRowHeight{};
|
||||
UINT snippetDpi{96};
|
||||
RECT snippetPopupAnchor{};
|
||||
SnippetAnchor snippetPopupAnchor{};
|
||||
bool snippetCaretPending{};
|
||||
std::optional<RECT> snippetCaret;
|
||||
std::optional<SnippetAnchor> snippetCaret;
|
||||
std::vector<std::pair<std::wstring, std::vector<std::wstring>>> snippetTriggers;
|
||||
std::vector<size_t> snippetMatches;
|
||||
std::array<bool, 256> snippetKeys{};
|
||||
void matchSnippets(HWND, bool expandExact);
|
||||
bool queueSnippet(HWND, size_t index, size_t length, HWND editor = nullptr);
|
||||
void showSnippetPopup();
|
||||
void placeSnippetPopup(RECT);
|
||||
void placeSnippetPopup(SnippetAnchor);
|
||||
void hideSnippetPopup();
|
||||
bool snippetPopupCurrent() const;
|
||||
bool handleSnippetKey(DWORD, UINT);
|
||||
void selectSnippet(size_t);
|
||||
bool selectSnippet(size_t);
|
||||
static LRESULT CALLBACK snippetPopupProc(HWND, UINT, WPARAM, LPARAM);
|
||||
std::vector<INPUT> deferredTyping;
|
||||
bool beginTypingDeferral(HWND, uint64_t, bool snippet = false);
|
||||
|
||||
@@ -48,7 +48,8 @@ Json capabilities(bool write, bool erase, unsigned host)
|
||||
{
|
||||
return {{"protocol", 2}, {"hostRevision", host}, {"write", write && host},
|
||||
{"delete", erase && host}, {"move", write && erase && host},
|
||||
{"revisionRead", host != 0}, {"onHostTransfer", host != 0}, {"localEndpoint", host != 0}};
|
||||
{"revisionRead", host != 0}, {"onHostTransfer", host != 0}, {"localEndpoint", host != 0},
|
||||
{"conflictPrompt", host != 0}};
|
||||
}
|
||||
fs::path itemPath(const Json &value)
|
||||
{
|
||||
@@ -128,6 +129,27 @@ class ClientTransfer
|
||||
if (!result.at("continue").get<bool>()) throw std::system_error(ERROR_CANCELLED, std::system_category());
|
||||
guard();
|
||||
}
|
||||
bool resolveConflict(const fs::path &path, const Json &incoming, const Json &existing)
|
||||
{
|
||||
if (conflict == "skip") return false;
|
||||
const bool replaceable = directory(incoming) == directory(existing) && !reparse(existing);
|
||||
if (conflict == "replace" && replaceable) return true;
|
||||
if (conflict != "ask") throw std::system_error(ERROR_ALREADY_EXISTS, std::system_category());
|
||||
if (replaceable && directory(existing)) return true;
|
||||
|
||||
sendJson(send, {{"type", "conflict"}, {"path", utf8(path.native())},
|
||||
{"incoming", incoming}, {"existing", existing}, {"replaceable", replaceable}});
|
||||
for (;;)
|
||||
{
|
||||
const auto answer = Json::parse(receive(256)).at("decision").get<std::string>();
|
||||
guard();
|
||||
if (answer == "wait") continue;
|
||||
if (answer == "skip") return false;
|
||||
if (answer == "replace" && replaceable) return true;
|
||||
if (answer == "cancel") throw std::system_error(ERROR_CANCELLED, std::system_category());
|
||||
throw std::runtime_error("Invalid transfer conflict decision.");
|
||||
}
|
||||
}
|
||||
bool copy(const fs::path &from, const fs::path &to, unsigned depth)
|
||||
{
|
||||
if (depth > 256) throw std::runtime_error("The file tree is too deep.");
|
||||
@@ -139,9 +161,7 @@ class ClientTransfer
|
||||
if (found)
|
||||
{
|
||||
checkFileReply(existing);
|
||||
if (conflict == "skip") { ++skipped; return false; }
|
||||
if (conflict != "replace" || directory(original) != directory(existing))
|
||||
throw std::system_error(ERROR_ALREADY_EXISTS, std::system_category());
|
||||
if (!resolveConflict(to, original, existing)) { ++skipped; return false; }
|
||||
requireRegular(existing);
|
||||
}
|
||||
|
||||
@@ -199,7 +219,7 @@ public:
|
||||
|
||||
void run(const fs::path &from, const fs::path &to)
|
||||
{
|
||||
if (conflict != "fail" && conflict != "skip" && conflict != "replace")
|
||||
if (conflict != "fail" && conflict != "skip" && conflict != "replace" && conflict != "ask")
|
||||
throw std::runtime_error("Unknown conflict policy.");
|
||||
if (sameHost)
|
||||
{
|
||||
|
||||
+38
-5
@@ -1,9 +1,46 @@
|
||||
#pragma once
|
||||
#include "platform.h"
|
||||
#include <uiautomation.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
namespace ks
|
||||
{
|
||||
inline bool focusedTextBelongsToWindow(IUIAutomation *automation, IUIAutomationElement *focused, HWND target)
|
||||
{
|
||||
using Microsoft::WRL::ComPtr;
|
||||
DWORD process{};
|
||||
GetWindowThreadProcessId(target, &process);
|
||||
int focusedProcess{};
|
||||
if (!process || FAILED(focused->get_CurrentProcessId(&focusedProcess))) return false;
|
||||
if (process == static_cast<DWORD>(focusedProcess)) return true;
|
||||
BOOL hasFocus{}, readOnly = TRUE;
|
||||
ComPtr<IUIAutomationValuePattern> value;
|
||||
if (FAILED(focused->get_CurrentHasKeyboardFocus(&hasFocus)) || !hasFocus ||
|
||||
FAILED(focused->GetCurrentPatternAs(UIA_ValuePatternId, IID_PPV_ARGS(&value))) || !value ||
|
||||
FAILED(value->get_CurrentIsReadOnly(&readOnly)) || readOnly)
|
||||
return false;
|
||||
|
||||
// WebView2 exposes text through a different process. Its accessibility
|
||||
// ancestors lead back to a native child window of the foreground app.
|
||||
ComPtr<IUIAutomationTreeWalker> walker;
|
||||
if (FAILED(automation->get_RawViewWalker(&walker)) || !walker)
|
||||
return false;
|
||||
ComPtr<IUIAutomationElement> element = focused;
|
||||
for (int depth = 0; element && depth < 32; ++depth)
|
||||
{
|
||||
UIA_HWND native{};
|
||||
if (SUCCEEDED(element->get_CurrentNativeWindowHandle(&native)) && native)
|
||||
{
|
||||
const auto hwnd = reinterpret_cast<HWND>(native);
|
||||
return hwnd == target || IsChild(target, hwnd);
|
||||
}
|
||||
ComPtr<IUIAutomationElement> parent;
|
||||
if (FAILED(walker->GetParentElement(element.Get(), &parent))) return false;
|
||||
element = std::move(parent);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read-only UI Automation: never select, move the caret, or touch the clipboard.
|
||||
class PasteProbe
|
||||
{
|
||||
@@ -38,11 +75,7 @@ class PasteProbe
|
||||
return;
|
||||
if (target)
|
||||
{
|
||||
DWORD process{};
|
||||
GetWindowThreadProcessId(target, &process);
|
||||
int focusedProcess{};
|
||||
if (!process || FAILED(element->get_CurrentProcessId(&focusedProcess)) ||
|
||||
process != static_cast<DWORD>(focusedProcess) || GetForegroundWindow() != target)
|
||||
if (GetForegroundWindow() != target || !focusedTextBelongsToWindow(automation, element, target))
|
||||
{
|
||||
status = L"focused-control-changed";
|
||||
return;
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
#include "platform.h"
|
||||
namespace ks
|
||||
{
|
||||
inline constexpr wchar_t AppVersion[] = L"0.8.3";
|
||||
inline constexpr wchar_t AppVersion[] = L"0.8.4";
|
||||
inline constexpr UINT UpdateMessage = WM_APP + 7;
|
||||
inline constexpr UINT UpdateCheckIntervalMs = 6 * 60 * 60 * 1000;
|
||||
inline constexpr UINT UpdateNotificationRetryMs = 5 * 60 * 1000;
|
||||
|
||||
+1
-1
@@ -1138,7 +1138,7 @@ int main(int argc, char **argv) {
|
||||
auto events = GetDlgItem(pane, 733);
|
||||
auto visible = [&](int id) { return (GetWindowLongPtrW(GetDlgItem(pane, id), GWL_STYLE) & WS_VISIBLE) != 0; };
|
||||
auto selectPage = [&](int index) { selectSettingsPage(settings, index); };
|
||||
require(TreeView_GetCount(navigation) == 20, "all Settings sections are listed");
|
||||
require(TreeView_GetCount(navigation) == 21, "all Settings sections are listed");
|
||||
selectPage(3);
|
||||
require(visible(243) && !visible(501), "Clipboard lists excluded apps separately from OCR");
|
||||
require(TreeView_GetParent(navigation, settingsSection(navigation, 19)) == settingsSection(navigation, 3),
|
||||
|
||||
@@ -67,9 +67,10 @@ void chooseInputAction(HWND resident, DWORD pid, const wchar_t *expected)
|
||||
}
|
||||
}
|
||||
require(donationSeparated && donation.hbmpItem, "tray donation item has an icon and both separators");
|
||||
require(help && GetMenuItemCount(help) == 2 && menuTitle(help, 0) == L"&User guide" &&
|
||||
menuTitle(help, 1) == L"&About KSwitcher",
|
||||
"tray Help submenu contains User guide and About KSwitcher");
|
||||
require(help && GetMenuItemCount(help) == 3 && menuTitle(help, 0) == L"&User guide" &&
|
||||
menuTitle(help, 1) == ks::whatsNewTitle(GetThreadUILanguage()) &&
|
||||
menuTitle(help, 2) == L"&About KSwitcher",
|
||||
"tray Help submenu contains User guide, release notes and About KSwitcher");
|
||||
require(PostMessageW(popup, WM_CHAR, L'i', 0), "cannot select input menu item");
|
||||
until([&] { return !IsWindow(popup); }, "tray action did not close menu");
|
||||
query(resident, WM_NULL);
|
||||
|
||||
+123
-2
@@ -1,5 +1,6 @@
|
||||
#include "app.h"
|
||||
#include "diagnostics.h"
|
||||
#include "paste_probe.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
@@ -61,6 +62,11 @@ namespace
|
||||
{
|
||||
ks::App *app{};
|
||||
HWND host{}, field{};
|
||||
HWND externalEditor{};
|
||||
ULONGLONG externalPopupUntil{};
|
||||
bool insertExternalSnippet{};
|
||||
bool insertTerminalSnippet{};
|
||||
constexpr wchar_t externalSnippetText[] = L"snippet test";
|
||||
ks::Clip saved;
|
||||
bool snippetRecoveryOnly = false;
|
||||
LONG unfilteredSnippetWidth{};
|
||||
@@ -278,6 +284,53 @@ void expandMacroSnippet(const wchar_t *replacement)
|
||||
record(L";zmtest");
|
||||
app->transform(0, 0, 0, field);
|
||||
}
|
||||
|
||||
bool terminalShowsTestDraft()
|
||||
{
|
||||
using Microsoft::WRL::ComPtr;
|
||||
ComPtr<IUIAutomation2> automation;
|
||||
if (FAILED(CoCreateInstance(CLSID_CUIAutomation8, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&automation))))
|
||||
return false;
|
||||
automation->put_TransactionTimeout(150);
|
||||
ComPtr<IUIAutomationElement> element;
|
||||
ComPtr<IUIAutomationTreeWalker> walker;
|
||||
if (FAILED(automation->GetFocusedElement(&element)) || !element ||
|
||||
!ks::focusedTextBelongsToWindow(automation.Get(), element.Get(), externalEditor) ||
|
||||
FAILED(automation->get_RawViewWalker(&walker)) || !walker)
|
||||
return false;
|
||||
// The xterm accessibility tree is beside the input's screen element.
|
||||
for (int depth = 0; element && depth < 3; ++depth)
|
||||
{
|
||||
ComPtr<IUIAutomationElement> parent;
|
||||
walker->GetParentElement(element.Get(), &parent);
|
||||
element = std::move(parent);
|
||||
}
|
||||
if (!element) return false;
|
||||
VARIANT className{};
|
||||
className.vt = VT_BSTR;
|
||||
className.bstrVal = SysAllocString(L"xterm-accessibility-tree");
|
||||
ComPtr<IUIAutomationCondition> condition;
|
||||
const auto hr = automation->CreatePropertyCondition(UIA_ClassNamePropertyId, className, &condition);
|
||||
VariantClear(&className);
|
||||
ComPtr<IUIAutomationElement> tree, row;
|
||||
if (FAILED(hr) || !condition || FAILED(element->FindFirst(TreeScope_Descendants, condition.Get(), &tree)) ||
|
||||
!tree || FAILED(walker->GetLastChildElement(tree.Get(), &row))) return false;
|
||||
while (row)
|
||||
{
|
||||
BSTR name{};
|
||||
row->get_CurrentName(&name);
|
||||
std::wstring_view line(name ? name : L"", SysStringLen(name));
|
||||
const auto end = line.find_last_not_of(L" \t\r\n\u00a0");
|
||||
const bool matches = end != line.npos && line.substr(0, end + 1).ends_with(externalSnippetText);
|
||||
SysFreeString(name);
|
||||
if (end != line.npos) return matches;
|
||||
ComPtr<IUIAutomationElement> previous;
|
||||
walker->GetPreviousSiblingElement(row.Get(), &previous);
|
||||
row = std::move(previous);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void finish()
|
||||
{
|
||||
KillTimer(host, 1);
|
||||
@@ -337,6 +390,62 @@ LRESULT CALLBACK procedure(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
}
|
||||
switch (stage++)
|
||||
{
|
||||
case 101:
|
||||
require(GetForegroundWindow() == externalEditor, "external editor retains foreground before typing");
|
||||
app->settings.snippets = {{L";ksw-regression", externalSnippetText}};
|
||||
app->resetInput();
|
||||
externalPopupUntil = GetTickCount64() + 2000;
|
||||
typeKeys({VK_OEM_1});
|
||||
break;
|
||||
case 102:
|
||||
{
|
||||
if (GetForegroundWindow() != externalEditor)
|
||||
throw std::runtime_error("External editor lost foreground while typing");
|
||||
const bool visible = ks::InputRegressionAccess::suggestionsVisible(*app);
|
||||
if (!visible && GetTickCount64() < externalPopupUntil)
|
||||
{
|
||||
stage = 102;
|
||||
break;
|
||||
}
|
||||
if (!visible) typeKeys({VK_BACK});
|
||||
else if (insertExternalSnippet || insertTerminalSnippet)
|
||||
{
|
||||
externalPopupUntil = GetTickCount64() + 3000;
|
||||
typeKeys({VK_TAB});
|
||||
}
|
||||
else typeKeys({VK_ESCAPE, VK_BACK});
|
||||
require(visible, "semicolon shows suggestions in the external editor");
|
||||
break;
|
||||
}
|
||||
case 103:
|
||||
if (insertExternalSnippet)
|
||||
{
|
||||
require(GetForegroundWindow() == externalEditor, "insertion leaves the external editor focused");
|
||||
ks::PasteProbe probe(true, externalEditor);
|
||||
const auto text = probe.read(static_cast<int>(std::size(externalSnippetText) - 1));
|
||||
const bool inserted = text && *text == externalSnippetText;
|
||||
if (inserted)
|
||||
{
|
||||
ks::chord('A', MOD_CONTROL);
|
||||
typeKeys({VK_BACK});
|
||||
}
|
||||
require(inserted, "Tab inserts the selected snippet in the external editor");
|
||||
}
|
||||
else if (insertTerminalSnippet)
|
||||
{
|
||||
const bool inserted = GetForegroundWindow() == externalEditor &&
|
||||
!ks::InputRegressionAccess::suggestionsVisible(*app) && terminalShowsTestDraft();
|
||||
if (!inserted && GetTickCount64() < externalPopupUntil)
|
||||
{
|
||||
stage = 103;
|
||||
break;
|
||||
}
|
||||
require(inserted, "Tab replaces the prefix in the live shell prompt");
|
||||
}
|
||||
else
|
||||
require(!ks::InputRegressionAccess::suggestionsVisible(*app), "Escape dismisses external suggestions");
|
||||
finish();
|
||||
break;
|
||||
case 0:
|
||||
saved = ks::readClipboard(app->window, 64 * 1024 * 1024);
|
||||
captured = true;
|
||||
@@ -1196,6 +1305,15 @@ LRESULT CALLBACK procedure(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
} // namespace
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const bool externalEditorTest = argc > 1 && std::string_view(argv[1]) == "--snippet-external-editor";
|
||||
if (externalEditorTest)
|
||||
{
|
||||
insertExternalSnippet = argc > 2 && std::string_view(argv[2]) == "--insert";
|
||||
insertTerminalSnippet = argc > 2 && std::string_view(argv[2]) == "--terminal-insert";
|
||||
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||
externalEditor = GetForegroundWindow();
|
||||
if (!externalEditor) return 1;
|
||||
}
|
||||
conversionOnly = argc > 1 && std::string(argv[1]) == "--conversion-only";
|
||||
typosOnly = argc > 1 && std::string(argv[1]) == "--typos-only";
|
||||
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
@@ -1362,7 +1480,7 @@ int main(int argc, char **argv)
|
||||
if (language == 0x419)
|
||||
ru = i;
|
||||
}
|
||||
if (en < 0 || ru < 0)
|
||||
if (!externalEditorTest && (en < 0 || ru < 0))
|
||||
throw std::runtime_error(
|
||||
"Integration test requires installed English US and Russian layouts");
|
||||
WNDCLASSW cls{};
|
||||
@@ -1372,7 +1490,8 @@ int main(int argc, char **argv)
|
||||
cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
||||
RegisterClassW(&cls);
|
||||
host = CreateWindowW(cls.lpszClassName, L"KSwitcher — automated test editor",
|
||||
WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 650, 320, nullptr, nullptr,
|
||||
WS_OVERLAPPEDWINDOW | (externalEditorTest ? 0 : WS_VISIBLE),
|
||||
100, 100, 650, 320, nullptr, nullptr,
|
||||
cls.hInstance, nullptr);
|
||||
field =
|
||||
CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_WANTRETURN,
|
||||
@@ -1392,6 +1511,8 @@ int main(int argc, char **argv)
|
||||
stage = 93;
|
||||
if (argc > 1 && std::string(argv[1]) == "--snippet-word-boundaries")
|
||||
stage = 84;
|
||||
if (externalEditorTest)
|
||||
stage = 101;
|
||||
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");
|
||||
|
||||
@@ -228,6 +228,42 @@ void verifyFiles(LanClients &clients, const Json &trusted, const std::wstring &p
|
||||
require(runTransfer(pipe, transfer(endpoint(a, src), endpoint(b, to), false, "replace")).at("type") == "complete" &&
|
||||
read(to / L"content.txt") == content, "replace conflict policy failed");
|
||||
|
||||
const auto ask = [&](const char *decision, bool replaceable) {
|
||||
Pipe client(pipe, transfer(endpoint(a, src), endpoint(b, to), false, "ask"));
|
||||
unsigned prompts = 0;
|
||||
for (;;)
|
||||
{
|
||||
auto result = client.reply();
|
||||
const auto type = result.value("type", "");
|
||||
if (type == "progress") client.sendJson({{"continue", true}});
|
||||
else if (type == "conflict")
|
||||
{
|
||||
++prompts;
|
||||
require(result.at("path") == utf8((to / L"content.txt").native()) &&
|
||||
result.at("replaceable") == replaceable &&
|
||||
result.at("incoming").at("size") == content.size(), "incorrect conflict prompt");
|
||||
client.sendJson({{"decision", "wait"}});
|
||||
client.sendJson({{"decision", decision}});
|
||||
}
|
||||
else
|
||||
{
|
||||
client.ack();
|
||||
require(prompts == 1, "ask did not report the nested collision exactly once");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
};
|
||||
save(to / L"content.txt", "keep me");
|
||||
require(ask("skip", true).at("skipped") == 1 && read(to / L"content.txt") == "keep me",
|
||||
"skipping a prompted collision changed its destination");
|
||||
require(ask("replace", true).at("type") == "complete" && read(to / L"content.txt") == content,
|
||||
"confirming a prompted collision did not replace its destination");
|
||||
fs::remove(to / L"content.txt");
|
||||
fs::create_directory(to / L"content.txt");
|
||||
require(ask("replace", false).contains("error") && fs::is_directory(to / L"content.txt"),
|
||||
"a prompted type mismatch allowed replacement");
|
||||
fs::remove(to / L"content.txt");
|
||||
|
||||
const auto localCopy = root / L"local.txt";
|
||||
const auto fromLocal = transfer(endpoint(nullptr, file), endpoint(b, dst / L"from-local.txt"), false);
|
||||
require(runTransfer(pipe, fromLocal).contains("error"), "identification-only pipe accessed local files");
|
||||
|
||||
Reference in new issue
Block a user