Compare commits

..
1 Commits
5 changed files with 39 additions and 377 deletions

No files matched your search

-10
View File
@@ -1044,16 +1044,6 @@ 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:
+28 -195
View File
@@ -45,107 +45,26 @@ GUITHREADINFO snippetGuiInfo(HWND target)
return info;
}
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)
{
ComPtr<IUIAutomationElement> focused;
if (FAILED(automation->GetFocusedElement(&focused)) || !focused)
return {};
BOOL password = TRUE;
if (FAILED(focused->get_CurrentIsPassword(&password)) || password ||
!focusedTextBelongsToWindow(automation, focused.Get(), target))
return {};
return focused;
}
ComPtr<IUIAutomation2> snippetAutomation()
std::optional<RECT> accessibleSnippetCaret(HWND target)
{
using Microsoft::WRL::ComPtr;
ComPtr<IUIAutomation2> automation;
if (FAILED(CoCreateInstance(CLSID_CUIAutomation8, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&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);
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)
ComPtr<IUIAutomationElement> focused;
if (FAILED(automation->GetFocusedElement(&focused)) || !focused)
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)
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)
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{};
@@ -202,7 +121,7 @@ std::optional<SnippetAnchor> accessibleSnippetCaret(HWND target)
}
}
SafeArrayDestroy(rectangles);
if (anchor && anchor->bottom > anchor->top) return SnippetAnchor{*anchor};
if (anchor && anchor->bottom > anchor->top) return anchor;
}
return {};
}
@@ -1566,12 +1485,6 @@ 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;
}
@@ -1646,11 +1559,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, bounds))
if (snippetPopup && IsWindowVisible(snippetPopup) && snippetCaretInside(snippetPopupAnchor, bounds))
placeSnippetPopup(snippetPopupAnchor);
if (snippetCaretPending) return;
snippetCaretPending = true;
@@ -1659,14 +1572,6 @@ 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;
@@ -1674,22 +1579,9 @@ void App::showSnippetPopup()
PostMessageW(receiver, SnippetCaretMessage, static_cast<WPARAM>(version), 0);
});
}
void App::placeSnippetPopup(SnippetAnchor placement)
void App::placeSnippetPopup(RECT 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;
snippetPopupAnchor = anchor;
if (!snippetPopup)
{
WNDCLASSW cls{};
@@ -1738,83 +1630,24 @@ void App::placeSnippetPopup(SnippetAnchor placement)
InvalidateRect(snippetPopup, nullptr, FALSE);
SetTimer(window, SnippetPopupTimer, 100, nullptr);
}
bool App::selectSnippet(size_t row)
void App::selectSnippet(size_t row)
{
if (!snippetPopupAnchor.canInsert() || row >= snippetMatches.size() || !snippetPopupCurrent()) return false;
if (row >= snippetMatches.size() || !snippetPopupCurrent()) return;
const auto index = snippetMatches[row];
const auto length = snippetPrefixLength;
std::lock_guard lock(stateMutex);
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;
std::lock_guard lock(stateMutex);
if (snippetPopupVersion == inputVersion && !busy)
queueSnippet(snippetTarget, index, length, snippetFocus);
}
bool App::handleSnippetKey(DWORD vk, UINT mods)
{
if (!snippetPopupAnchor.canInsert() && vk != VK_ESCAPE) return false;
const bool accept = vk == VK_TAB ||
(!snippetPopupAnchor.terminal && vk == VK_RETURN && (snippetNavigated || snippetMatches.size() == 1));
(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) return selectSnippet(snippetSelection);
if (accept) selectSnippet(snippetSelection);
else if (vk == VK_ESCAPE) hideSnippetPopup();
else
{
@@ -1857,7 +1690,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 = app->snippetPopupAnchor.canInsert() && i == app->snippetSelection;
const bool selected = 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);
@@ -3770,13 +3603,13 @@ LRESULT CALLBACK App::windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
app->showSnippetPopup();
return 0;
}
std::optional<SnippetAnchor> caret;
std::optional<RECT> caret;
{
std::lock_guard lock(app->stateMutex);
caret = app->snippetCaret;
}
RECT bounds{};
if (caret && GetWindowRect(app->snippetTarget, &bounds) && snippetCaretInside(caret->bounds, bounds))
if (caret && GetWindowRect(app->snippetTarget, &bounds) && snippetCaretInside(*caret, bounds))
{
app->placeSnippetPopup(*caret);
return 0;
+4 -11
View File
@@ -23,13 +23,6 @@ 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{};
@@ -210,20 +203,20 @@ class App
bool snippetNavigated{};
int snippetRowHeight{};
UINT snippetDpi{96};
SnippetAnchor snippetPopupAnchor{};
RECT snippetPopupAnchor{};
bool snippetCaretPending{};
std::optional<SnippetAnchor> snippetCaret;
std::optional<RECT> 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(SnippetAnchor);
void placeSnippetPopup(RECT);
void hideSnippetPopup();
bool snippetPopupCurrent() const;
bool handleSnippetKey(DWORD, UINT);
bool selectSnippet(size_t);
void selectSnippet(size_t);
static LRESULT CALLBACK snippetPopupProc(HWND, UINT, WPARAM, LPARAM);
std::vector<INPUT> deferredTyping;
bool beginTypingDeferral(HWND, uint64_t, bool snippet = false);
+5 -38
View File
@@ -1,46 +1,9 @@
#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
{
@@ -75,7 +38,11 @@ class PasteProbe
return;
if (target)
{
if (GetForegroundWindow() != target || !focusedTextBelongsToWindow(automation, element, target))
DWORD process{};
GetWindowThreadProcessId(target, &process);
int focusedProcess{};
if (!process || FAILED(element->get_CurrentProcessId(&focusedProcess)) ||
process != static_cast<DWORD>(focusedProcess) || GetForegroundWindow() != target)
{
status = L"focused-control-changed";
return;
+2 -123
View File
@@ -1,6 +1,5 @@
#include "app.h"
#include "diagnostics.h"
#include "paste_probe.h"
#include <algorithm>
#include <iostream>
#include <fstream>
@@ -62,11 +61,6 @@ 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{};
@@ -284,53 +278,6 @@ 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);
@@ -390,62 +337,6 @@ 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;
@@ -1305,15 +1196,6 @@ 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);
@@ -1480,7 +1362,7 @@ int main(int argc, char **argv)
if (language == 0x419)
ru = i;
}
if (!externalEditorTest && (en < 0 || ru < 0))
if (en < 0 || ru < 0)
throw std::runtime_error(
"Integration test requires installed English US and Russian layouts");
WNDCLASSW cls{};
@@ -1490,8 +1372,7 @@ 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 | (externalEditorTest ? 0 : WS_VISIBLE),
100, 100, 650, 320, nullptr, nullptr,
WS_OVERLAPPEDWINDOW | 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,
@@ -1511,8 +1392,6 @@ 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");