Compare commits

...
13 changed files with 344 additions and 56 deletions

No files matched your search

+2 -1
View File
@@ -81,7 +81,8 @@ set_property(SOURCE resources/help.rc APPEND PROPERTY OBJECT_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/resources/help-guide.md"
"${CMAKE_CURRENT_SOURCE_DIR}/README.md"
"${CMAKE_CURRENT_SOURCE_DIR}/FILES-UI.md"
"${CMAKE_CURRENT_SOURCE_DIR}/LAN-PREVIEW.md")
"${CMAKE_CURRENT_SOURCE_DIR}/LAN-PREVIEW.md"
"${CMAKE_CURRENT_SOURCE_DIR}/Release/README.md")
add_executable(KSwitcher WIN32 src/main.cpp src/app.cpp src/screenshot_notifications.cpp src/screenshot_launcher.cpp src/screenshot_activation.cpp src/configuration.cpp src/ui.cpp resources/app.rc resources/help.rc)
target_compile_definitions(KSwitcher PRIVATE KS_RESIDENT_APP)
target_link_libraries(KSwitcher PRIVATE kscore)
+2
View File
@@ -58,6 +58,8 @@ Choose Files from the tray. Use the two file panels to browse, move and copy fil
Use the tray menu to pause or resume input processing, keep the display awake, pause clipboard history, open the data folder, check for updates or exit. Tools lists supported portable utilities placed in the tools folder.
After a successful update, What's new shows the installed release notes once. Open Help → What's new from the tray to read current and earlier releases offline or open the full release page in Gitea.
If a shortcut stops working, check whether input processing is paused and whether another application owns the binding. If a paired PC is missing, check discovery and access on both computers. Settings → Diagnostics and View log in the tray provide logs. Settings → MCP displays management integration settings.
Donate via Monobank opens the project's donation jar in the browser. Choose Help → About KSwitcher to see the running version.
+1
View File
@@ -4,3 +4,4 @@ IDR_HELP_GUIDE RCDATA "help-guide.md"
IDR_HELP_MANUAL RCDATA "../README.md"
IDR_HELP_FILES RCDATA "../FILES-UI.md"
IDR_HELP_COMPUTERS RCDATA "../LAN-PREVIEW.md"
IDR_HELP_RELEASES RCDATA "../Release/README.md"
+1
View File
@@ -14,3 +14,4 @@
#define IDR_HELP_MANUAL 601
#define IDR_HELP_FILES 602
#define IDR_HELP_COMPUTERS 603
#define IDR_HELP_RELEASES 604
+33 -14
View File
@@ -144,7 +144,7 @@ ULONG_PTR snippetReplayMarker()
return reinterpret_cast<ULONG_PTR>(&marker);
}
constexpr int OpenFiles = 25, FilesHotkeyFirst = 0x4B10, FilesHotkeySecond = 0x4B11;
constexpr int ToggleInputProcessing = 26, DonateViaMonobank = 27, OpenHelp = 28, OpenAbout = 16;
constexpr int ToggleInputProcessing = 26, DonateViaMonobank = 27, OpenHelp = 28, OpenWhatsNew = 29, OpenAbout = 16;
constexpr wchar_t MonobankDonationUrl[] = L"https://send.monobank.ua/jar/88h2TddKfS";
constexpr int ShortcutProbeId = FilesHotkeySecond + 1;
constexpr UINT_PTR PauseDrainTimer = 23;
@@ -660,21 +660,18 @@ class Transaction
}
auto text = select(count) ? copy() : std::wstring{};
diagnosticEvent(L"Selection initial match=" + std::to_wstring(matches(text)) + L" copied=" + diagnosticText(text));
// Chromium editors can apply only part of a burst of Shift+Left events.
// Extend only a verified suffix; never replace a partial or unrelated range.
// The editor may finish applying queued Shift+Left events after copying
// the suffix. Collapse to its right edge before trying the full range again.
if (valid() && !matches(text) && !text.empty() &&
(suffixMatches ? suffixMatches(text) : newlines(wordCandidate).ends_with(newlines(text))) &&
caretSteps(text) < count)
{
const auto missing = count - caretSteps(text);
diagnosticEvent(L"Selection: extending verified suffix by " + std::to_wstring(missing));
for (size_t i = 0; i < missing; ++i)
{
if (!valid() || !chord(VK_LEFT, MOD_SHIFT))
return {};
diagnosticEvent(L"Selection recovery Shift+Left sent=" + std::to_wstring(i + 1) + L" total=" + std::to_wstring(missing));
Sleep(25);
}
diagnosticEvent(L"Selection: reselecting full range after verified suffix");
if (!finishSelection(false))
return {};
Sleep(25);
if (!selectPrevious(count, [&] { return valid(); }, true))
return {};
text = copy();
diagnosticEvent(L"Selection: suffix recovery match=" + std::to_wstring(matches(text)) + L" copied=" + diagnosticText(text));
}
@@ -3269,6 +3266,7 @@ void App::trayMenu()
AppendMenuW(menu, MF_SEPARATOR, 0, nullptr);
HMENU help = CreatePopupMenu();
AppendMenuW(help, MF_STRING, OpenHelp, L"&User guide");
AppendMenuW(help, MF_STRING, OpenWhatsNew, whatsNewTitle(GetThreadUILanguage()));
AppendMenuW(help, MF_STRING, OpenAbout, L"&About KSwitcher");
AppendMenuW(menu, MF_POPUP, reinterpret_cast<UINT_PTR>(help), L"H&elp");
AppendMenuW(menu, MF_STRING, 17, L"E&xit");
@@ -3333,6 +3331,9 @@ void App::trayMenu()
case OpenHelp:
showHelp(*this);
break;
case OpenWhatsNew:
showWhatsNew(*this, GetThreadUILanguage());
break;
case DonateViaMonobank:
if (reinterpret_cast<INT_PTR>(ShellExecuteW(window, L"open", MonobankDonationUrl, nullptr, nullptr, SW_SHOWNORMAL)) <= 32)
throw std::runtime_error("Could not open the Monobank donation page.");
@@ -3372,6 +3373,25 @@ void App::trayMenu()
report(wide(e.what()));
}
}
void App::showWhatsNewAfterUpdate()
{
if (!confirmUpdatedStartup(updateStartupEvent)) return;
log(std::wstring(L"Update completed; running version ") + AppVersion);
try
{
const auto seen = data / L"whats-new-seen.txt";
const auto version = utf8(AppVersion);
if (std::filesystem::exists(seen) && readFile(seen, 64) == Bytes(version.begin(), version.end()))
return;
showWhatsNew(*this, GetThreadUILanguage());
atomicWrite(seen, Bytes(version.begin(), version.end()));
}
catch (const std::exception &error)
{
log(L"Could not show release notes: " + wide(error.what()));
}
}
void App::checkUpdate(bool interactive, bool install, const std::wstring &version)
{
if (updateRunning) return;
@@ -3876,8 +3896,6 @@ int App::execute()
SetTimer(window, 2, 10000, nullptr);
else
SetTimer(window, 5, 5000, nullptr);
if (keyboardHook && mouseHook && confirmUpdatedStartup(updateStartupEvent))
log(std::wstring(L"Update completed; running version ") + AppVersion);
if (startCommand)
PostMessageW(window, WM_HOTKEY, startCommand, 0);
if (!smoke && !isLocalBuild() && settings.autostart)
@@ -3885,6 +3903,7 @@ int App::execute()
try { notificationRegistration = startScreenshotNotificationRegistration(); }
catch(const std::exception &e) { log(L"Screenshot notification registration: "+wide(e.what())); }
auto screenshotActivation=startScreenshotActivationListener();
if (keyboardHook && mouseHook) showWhatsNewAfterUpdate();
MSG msg;
while (GetMessageW(&msg, nullptr, 0, 0) > 0)
{
+3
View File
@@ -78,6 +78,7 @@ class App
void enqueue(std::function<void()>);
void enqueueHistorySearch(std::function<void()>);
void report(const std::wstring &);
void showWhatsNewAfterUpdate();
void trayMenu();
void addTray();
bool registerHotkeys(const Settings &, bool rollback = false);
@@ -234,5 +235,7 @@ void showLogs(App &);
void showSnippets(App &);
void showShortcuts(App &);
void showHelp(App &);
const wchar_t *whatsNewTitle(LANGID language);
void showWhatsNew(App &, LANGID language);
void showEntry(App &, const std::wstring &);
} // namespace ks
+50 -11
View File
@@ -10,6 +10,42 @@ class PasteProbe
IUIAutomation2 *automation{};
IUIAutomationElement *element{};
IUIAutomationTextPattern *pattern{};
HWND targetWindow{};
bool focusBelongsToTarget() const
{
DWORD process{};
GetWindowThreadProcessId(targetWindow, &process);
int focusedProcess{};
if (process && SUCCEEDED(element->get_CurrentProcessId(&focusedProcess)) &&
process == static_cast<DWORD>(focusedProcess))
return true;
// WebView2 can report a renderer process for the focused element.
// Require a native window in its UIA ancestry rooted in the target.
auto release = [](auto *value) { if (value) value->Release(); };
IUIAutomationTreeWalker *rawWalker{};
const auto walkerResult = automation->get_RawViewWalker(&rawWalker);
std::unique_ptr<IUIAutomationTreeWalker, decltype(release)> walker(rawWalker, release);
if (FAILED(walkerResult) || !walker) return false;
element->AddRef();
std::unique_ptr<IUIAutomationElement, decltype(release)> current(element, release);
for (int depth = 0; depth < 32 && current; ++depth)
{
UIA_HWND native{};
if (SUCCEEDED(current->get_CurrentNativeWindowHandle(&native)) && native)
{
const auto window = reinterpret_cast<HWND>(native);
return window == targetWindow || IsChild(targetWindow, window);
}
IUIAutomationElement *parent{};
const auto parentResult = walker->GetParentElement(current.get(), &parent);
current.reset(parent);
if (FAILED(parentResult)) break;
}
return false;
}
static std::optional<std::wstring> rangeText(IUIAutomationTextRange *range)
{
@@ -24,7 +60,7 @@ class PasteProbe
public:
std::wstring status = L"not-requested";
std::optional<std::wstring> precedingCharacter;
PasteProbe(bool enabled, HWND target)
PasteProbe(bool enabled, HWND target) : targetWindow(target)
{
if (!enabled)
return;
@@ -36,17 +72,15 @@ class PasteProbe
automation->put_TransactionTimeout(200);
if (FAILED(automation->GetFocusedElement(&element)) || !element)
return;
if (target)
if (target && GetForegroundWindow() != 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;
}
status = L"focused-window-changed";
return;
}
if (target && !focusBelongsToTarget())
{
status = L"focused-control-outside-target";
return;
}
BOOL password = TRUE;
if (FAILED(element->get_CurrentIsPassword(&password)) || password)
@@ -95,6 +129,11 @@ class PasteProbe
{
if (!pattern)
return {};
if (targetWindow && GetForegroundWindow() != targetWindow)
{
status = L"focused-window-changed";
return {};
}
if (characters <= 0 || characters > 4096)
{
status = L"readback-size-limit";
+6 -4
View File
@@ -676,9 +676,10 @@ bool needsSelectionDelay(HWND target)
{
const auto name = lower(processName(target));
return name == L"ms-teams" || name == L"msedgewebview2" ||
name == L"chrome" || name == L"msedge" || name == L"chatgpt" || name == L"codex";
name == L"chrome" || name == L"msedge" || name == L"chatgpt" ||
name == L"codex" || name == L"claude";
}
bool selectPrevious(size_t count, const std::function<bool()> &valid)
bool selectPrevious(size_t count, const std::function<bool()> &valid, bool forcePacing)
{
if (count > 100000)
return false;
@@ -686,9 +687,10 @@ bool selectPrevious(size_t count, const std::function<bool()> &valid)
// Shift+Left events can all use the same caret position and select only one
// character. Give each change time to settle before sending the next one.
const auto target = GetForegroundWindow();
const bool paced = forcePacing || needsSelectionDelay(target);
diagnosticEvent(L"SelectPrevious requested=" + std::to_wstring(count) +
L" mode=" + (needsSelectionDelay(target) ? std::wstring(L"paced-25ms") : std::wstring(L"batch")));
if (needsSelectionDelay(target))
(paced ? L" mode=paced-25ms" : L" mode=batch"));
if (paced)
{
for (size_t i = 0; i < count; ++i)
{
+1 -1
View File
@@ -75,7 +75,7 @@ ULONG_PTR inputMarker();
bool ownKeyboardInput(const KBDLLHOOKSTRUCT &);
INPUT keyboardInput(WORD key, DWORD flags = 0);
bool needsSelectionDelay(HWND);
bool selectPrevious(size_t count, const std::function<bool()> &valid);
bool selectPrevious(size_t count, const std::function<bool()> &valid, bool forcePacing = false);
bool modifiersReleased();
void releaseModifiers();
std::filesystem::path dataDirectory();
+1
View File
@@ -10,6 +10,7 @@
#include "ui_geometry.h"
#include "diagnostics.h"
#include "google_drive.h"
#include "update.h"
#include <algorithm>
#include <array>
#include <atomic>
+141 -25
View File
@@ -1,13 +1,16 @@
namespace
{
constexpr int HelpSearch = 810, HelpTopics = 811, HelpTitle = 812, HelpBody = 813;
constexpr int HelpSearch = 810, HelpTopics = 811, HelpTitle = 812, HelpBody = 813, HelpReleaseLink = 814;
constexpr int HelpRail = 268, HelpFooter = 56, HelpHeader = 66;
constexpr int ShortcutTopic = 0, GuideRoot = 1, GettingStarted = 2;
enum class HelpPage { shortcuts, guide, releases };
struct HelpTopic
{
std::wstring title, text;
int parent = -1;
std::wstring releaseVersion;
};
struct HelpView
@@ -19,6 +22,8 @@ struct HelpView
UINT dpi{};
int selected{};
bool rebuilding{};
bool releases{};
bool ukrainian{};
};
std::wstring helpShortcuts(const App &app)
@@ -65,16 +70,19 @@ std::wstring helpText(std::wstring line)
return line;
}
std::wstring helpResourceText(HINSTANCE instance, int resource)
{
HRSRC found = FindResourceW(instance, MAKEINTRESOURCEW(resource), RT_RCDATA);
HGLOBAL loaded = found ? LoadResource(instance, found) : nullptr;
const auto *bytes = loaded ? static_cast<const char *>(LockResource(loaded)) : nullptr;
return bytes ? wide(std::string(bytes, SizeofResource(instance, found))) : std::wstring{};
}
void addHelpDocument(HelpView &view, int resource, std::wstring title, std::wstring introduction)
{
const int root = static_cast<int>(view.topics.size());
view.topics.push_back({std::move(title), std::move(introduction)});
const auto instance = view.app->instance;
HRSRC found = FindResourceW(instance, MAKEINTRESOURCEW(resource), RT_RCDATA);
HGLOBAL loaded = found ? LoadResource(instance, found) : nullptr;
const auto *bytes = loaded ? static_cast<const char *>(LockResource(loaded)) : nullptr;
if (!bytes) return;
std::wistringstream input(wide(std::string(bytes, SizeofResource(instance, found))));
std::wistringstream input(helpResourceText(view.app->instance, resource));
std::array<int, 7> ancestors;
ancestors.fill(root);
int topic = root;
@@ -106,12 +114,74 @@ void addHelpDocument(HelpView &view, int resource, std::wstring title, std::wstr
}
}
int addReleaseTopics(HelpView &view, LANGID language)
{
view.topics.push_back({whatsNewTitle(language), view.ukrainian
? L"Виберіть версію, щоб переглянути зміни."
: L"Select a version to read its release notes."});
std::wistringstream input(helpResourceText(view.app->instance, IDR_HELP_RELEASES));
constexpr std::wstring_view ukrainianMarker = L"**Українською.**";
std::wstring version, english, ukrainian;
bool translated = false, withdrawn = false;
int installed = 0;
const auto add = [&]
{
if (version.empty()) return;
auto &text = view.ukrainian && !ukrainian.empty() ? ukrainian : english;
const auto end = text.find_last_not_of(L" \r\n\t");
if (end == std::wstring::npos) return;
text.resize(end + 1);
if (version == AppVersion) installed = static_cast<int>(view.topics.size());
auto title = L"v" + version;
if (withdrawn) title += view.ukrainian ? L" (відкликано)" : L" (withdrawn)";
view.topics.push_back({std::move(title), std::move(text), 0, withdrawn ? std::wstring{} : version});
};
for (std::wstring line; std::getline(input, line);)
{
if (line.ends_with(L'\r')) line.pop_back();
if (line.starts_with(L"## v"))
{
add();
const auto end = line.find(L' ', 4);
version = line.substr(4, end == line.npos ? line.npos : end - 4);
if (version.empty() || version.find_first_not_of(L"0123456789.") != version.npos)
version.clear();
english.clear();
ukrainian.clear();
translated = false;
withdrawn = line.find(L"(withdrawn") != line.npos;
continue;
}
if (version.empty()) continue;
if (line.starts_with(ukrainianMarker))
{
translated = true;
const auto start = line.find_first_not_of(L" \t", ukrainianMarker.size());
line = start == line.npos ? std::wstring{} : line.substr(start);
}
auto &text = translated ? ukrainian : english;
if (text.empty() && line.empty()) continue;
if (line.starts_with(L"- ")) line.replace(0, 1, L"•");
text += helpText(std::move(line)) + L"\r\n";
}
add();
if (!installed)
{
installed = static_cast<int>(view.topics.size());
view.topics.push_back({std::wstring(L"v") + AppVersion, view.ukrainian
? L"Нотатки для цієї збірки ще недоступні. Попередні випуски можна переглянути у списку."
: L"Notes for this build are unavailable. Earlier releases are in the list.", 0});
}
return installed;
}
void showHelpTopic(HWND w, HelpView &view, int index)
{
view.selected = index;
const auto &topic = view.topics[index];
value(w, HelpTitle, topic.title);
value(w, HelpBody, index == ShortcutTopic ? helpShortcuts(*view.app) : topic.text);
value(w, HelpBody, !view.releases && index == ShortcutTopic ? helpShortcuts(*view.app) : topic.text);
ShowWindow(GetDlgItem(w, HelpReleaseLink), topic.releaseVersion.empty() ? SW_HIDE : SW_SHOWNA);
SendDlgItemMessageW(w, HelpBody, EM_SETSEL, 0, 0);
SendDlgItemMessageW(w, HelpBody, EM_SCROLLCARET, 0, 0);
}
@@ -122,6 +192,7 @@ void fillHelpTopics(HWND w, HelpView &view)
const auto query = lower(value(w, HelpSearch));
std::vector<HTREEITEM> nodes(view.topics.size());
HTREEITEM selected{};
int selectedIndex{};
view.rebuilding = true;
SendMessageW(tree, WM_SETREDRAW, FALSE, 0);
TreeView_DeleteAllItems(tree);
@@ -137,17 +208,27 @@ void fillHelpTopics(HWND w, HelpView &view)
node.item.pszText = const_cast<wchar_t *>(topic.title.c_str());
node.item.lParam = static_cast<LPARAM>(i);
nodes[i] = TreeView_InsertItem(tree, &node);
if (!selected || static_cast<int>(i) == view.selected) selected = nodes[i];
if (nodes[i] && (!selected || static_cast<int>(i) == view.selected))
{
selected = nodes[i];
selectedIndex = static_cast<int>(i);
}
}
if (query.empty()) TreeView_Expand(tree, nodes[GuideRoot], TVE_EXPAND);
if (query.empty()) TreeView_Expand(tree, nodes[view.releases ? 0 : GuideRoot], TVE_EXPAND);
SendMessageW(tree, WM_SETREDRAW, TRUE, 0);
view.rebuilding = false;
if (selected) TreeView_SelectItem(tree, selected);
if (selected)
{
TreeView_SelectItem(tree, selected);
showHelpTopic(w, view, selectedIndex);
}
else
{
value(w, HelpTitle, L"No matching topics");
value(w, HelpBody, L"Try another word or clear the search to see all topics.");
value(w, HelpTitle, view.ukrainian ? L"Нічого не знайдено" : L"No matching topics");
value(w, HelpBody, view.ukrainian ? L"Спробуйте інше слово або очистьте пошук." :
L"Try another word or clear the search to see all topics.");
ShowWindow(GetDlgItem(w, HelpReleaseLink), SW_HIDE);
}
view.rebuilding = false;
InvalidateRect(tree, nullptr, TRUE);
}
@@ -169,6 +250,7 @@ void layoutHelp(HWND w, HelpView &view)
place(HelpTitle, content, scale(w, 13), r.right - pad, scale(w, 55));
place(HelpBody, content, header + pad, r.right - pad, footer - scale(w, 10));
place(IDCANCEL, r.right - pad - scale(w, 100), footer + scale(w, 14), r.right - pad, r.bottom - scale(w, 14));
place(HelpReleaseLink, content, footer + scale(w, 14), content + scale(w, 170), r.bottom - scale(w, 14));
const auto dpi = GetDpiForWindow(w);
if (view.dpi != dpi || !view.heading)
{
@@ -252,6 +334,18 @@ LRESULT CALLBACK helpProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
}
case WM_COMMAND:
if (LOWORD(wp) == HelpSearch && HIWORD(wp) == EN_CHANGE) fillHelpTopics(w, *view);
if (LOWORD(wp) == HelpReleaseLink && IsWindowVisible(GetDlgItem(w, HelpReleaseLink)))
{
const auto &version = view->topics[view->selected].releaseVersion;
constexpr auto repository = L"https://gitea.hrynco.com/hrynco/hrynco-kswitcher";
// Older release pages can be superseded while the tagged notes remain available.
const auto path = version == AppVersion ? L"/releases/tag/release-v" + version
: L"/src/tag/release-v" + version + L"/Release/README.md";
const auto address = repository + path;
if (reinterpret_cast<INT_PTR>(ShellExecuteW(w, L"open", address.c_str(), nullptr, nullptr, SW_SHOWNORMAL)) <= 32)
MessageBoxW(w, view->ukrainian ? L"Не вдалося відкрити сторінку випуску." :
L"Could not open the release page.", view->ukrainian ? L"Що нового" : L"What's new", MB_OK | MB_ICONWARNING);
}
if (LOWORD(wp) == IDCANCEL) DestroyWindow(w);
return 0;
case WM_NCDESTROY:
@@ -265,7 +359,7 @@ LRESULT CALLBACK helpProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
return DefWindowProcW(w, msg, wp, lp);
}
void openHelp(App &app, int topic)
void openHelp(App &app, HelpPage page, LANGID language = LANG_ENGLISH)
{
if (!app.helpWindow)
{
@@ -273,15 +367,8 @@ void openHelp(App &app, int topic)
app.helpWindow = w;
setWindowTaskbarIdentity(w, IDI_KSWITCHER_HELP, L"HrynCo.KSwitcher.Help");
auto &view = *reinterpret_cast<HelpView *>(GetWindowLongPtrW(w, GWLP_USERDATA));
view.topics = {{L"Keyboard shortcuts", L"Current shortcut bindings and keyboard controls"}};
addHelpDocument(view, IDR_HELP_GUIDE, L"Using KSwitcher", L"Choose an area to learn how to use it.\r\n");
addHelpDocument(view, IDR_HELP_MANUAL, L"KSwitcher manual", L"Detailed documentation for the main application.\r\n");
addHelpDocument(view, IDR_HELP_FILES, L"Files manual (Українська)", L"Докладний посібник з KSwitcher Files.\r\n");
addHelpDocument(view, IDR_HELP_COMPUTERS, L"Paired computers manual", L"Detailed documentation for discovery, pairing and LAN features.\r\n");
auto search = edit(w, HelpSearch, 0, 0, 0);
SendMessageW(search, EM_SETLIMITTEXT, 120, 0);
SendMessageW(search, EM_SETCUEBANNER, TRUE, reinterpret_cast<LPARAM>(L"Search help"));
INITCOMMONCONTROLSEX classes{sizeof(classes), ICC_TREEVIEW_CLASSES};
InitCommonControlsEx(&classes);
control(w, WC_TREEVIEWW, L"Help topics", WS_TABSTOP | TVS_HASBUTTONS | TVS_LINESATROOT |
@@ -289,13 +376,37 @@ void openHelp(App &app, int topic)
control(w, L"STATIC", L"", SS_CENTERIMAGE | SS_ENDELLIPSIS, HelpTitle, 0, 0, 0, 0);
auto body = edit(w, HelpBody, 0, 0, 0, 0, ES_MULTILINE | ES_READONLY | ES_AUTOVSCROLL | WS_VSCROLL);
SendMessageW(body, EM_SETLIMITTEXT, 1024 * 1024, 0);
button(w, L"Open in Gitea", HelpReleaseLink, 0, 0);
button(w, L"&Close", IDCANCEL, 0, 0);
SendMessageW(w, WM_SYSCOLORCHANGE, 0, 0);
layoutHelp(w, view);
}
const auto w = app.helpWindow;
auto &view = *reinterpret_cast<HelpView *>(GetWindowLongPtrW(w, GWLP_USERDATA));
view.selected = topic < static_cast<int>(view.topics.size()) ? topic : GuideRoot;
const bool releases = page == HelpPage::releases;
const bool ukrainian = releases && PRIMARYLANGID(language) == LANG_UKRAINIAN;
int topic = page == HelpPage::shortcuts ? ShortcutTopic : GettingStarted;
if (releases || view.topics.empty() || view.releases)
{
view.topics.clear();
view.releases = releases;
view.ukrainian = ukrainian;
if (releases) topic = addReleaseTopics(view, language);
else
{
view.topics = {{L"Keyboard shortcuts", L"Current shortcut bindings and keyboard controls"}};
addHelpDocument(view, IDR_HELP_GUIDE, L"Using KSwitcher", L"Choose an area to learn how to use it.\r\n");
addHelpDocument(view, IDR_HELP_MANUAL, L"KSwitcher manual", L"Detailed documentation for the main application.\r\n");
addHelpDocument(view, IDR_HELP_FILES, L"Files manual (Українська)", L"Докладний посібник з KSwitcher Files.\r\n");
addHelpDocument(view, IDR_HELP_COMPUTERS, L"Paired computers manual", L"Detailed documentation for discovery, pairing and LAN features.\r\n");
}
}
SetWindowTextW(w, releases ? whatsNewTitle(language) : L"KSwitcher Help");
value(w, IDCANCEL, ukrainian ? L"&Закрити" : L"&Close");
value(w, HelpReleaseLink, ukrainian ? L"Відкрити в Gitea" : L"Open in Gitea");
const auto *searchHint = ukrainian ? L"Пошук випусків" : releases ? L"Search releases" : L"Search help";
SendDlgItemMessageW(w, HelpSearch, EM_SETCUEBANNER, TRUE, reinterpret_cast<LPARAM>(searchHint));
view.selected = topic;
if (value(w, HelpSearch).empty()) fillHelpTopics(w, view);
else value(w, HelpSearch, L"");
if (IsIconic(w)) ShowWindow(w, SW_RESTORE);
@@ -305,5 +416,10 @@ void openHelp(App &app, int topic)
}
} // namespace
void showHelp(App &app) { openHelp(app, GettingStarted); }
void showShortcuts(App &app) { openHelp(app, ShortcutTopic); }
void showHelp(App &app) { openHelp(app, HelpPage::guide); }
void showShortcuts(App &app) { openHelp(app, HelpPage::shortcuts); }
const wchar_t *whatsNewTitle(LANGID language)
{
return PRIMARYLANGID(language) == LANG_UKRAINIAN ? L"Що нового" : L"What's new";
}
void showWhatsNew(App &app, LANGID language) { openHelp(app, HelpPage::releases, language); }
+68
View File
@@ -426,6 +426,74 @@ int main(int argc, char **argv) {
ks::encodePng(ks::decodeImage(preview)));
SendMessageW(window, WM_COMMAND, IDCANCEL, 0);
require(!app.helpWindow && !IsWindow(window), "Close releases the help window");
const auto seen = temp / L"whats-new-seen.txt";
app.showWhatsNewAfterUpdate();
require(!app.helpWindow && !std::filesystem::exists(seen), "ordinary startup does not open release notes");
app.updateStartupEvent = L"Local\\KSwitcher.Update.Started." + ks::newSnippetId();
app.showWhatsNewAfterUpdate();
require(!app.helpWindow && !std::filesystem::exists(seen), "an unconfirmed update does not open release notes");
const auto ready = CreateEventW(nullptr, TRUE, FALSE, app.updateStartupEvent.c_str());
require(ready != nullptr, "update test creates a startup handshake");
app.showWhatsNewAfterUpdate();
const auto signaled = WaitForSingleObject(ready, 0);
CloseHandle(ready);
require(signaled == WAIT_OBJECT_0 && IsWindowVisible(app.helpWindow) && std::filesystem::exists(seen),
"successful update signals startup and opens the installed notes once");
DestroyWindow(app.helpWindow);
const auto secondReady = CreateEventW(nullptr, TRUE, FALSE, app.updateStartupEvent.c_str());
require(secondReady != nullptr, "repeat startup can complete its updater handshake");
app.showWhatsNewAfterUpdate();
const auto secondSignal = WaitForSingleObject(secondReady, 0);
CloseHandle(secondReady);
require(secondSignal == WAIT_OBJECT_0 && !app.helpWindow,
"the same version acknowledges the updater without reopening the notes");
const auto language = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
ks::showWhatsNew(app, language);
const auto releases = app.helpWindow;
const auto releaseText = [&](int id) {
wchar_t buffer[32768]{};
GetDlgItemTextW(releases, id, buffer, std::size(buffer));
return std::wstring(buffer);
};
require(std::wstring(ks::whatsNewTitle(language)) == L"What's new" &&
releaseText(812) == std::wstring(L"v") + ks::AppVersion &&
!releaseText(813).empty() && IsWindowVisible(GetDlgItem(releases, 814)),
"manual Help command opens embedded notes for the installed release with a Gitea link");
const auto versions = GetDlgItem(releases, 811);
require(TreeView_GetCount(versions) > 2, "prior releases are available offline");
SetDlgItemTextW(releases, 810, L"v0.6.126");
require(releaseText(812) == L"v0.6.126 (withdrawn)" && !IsWindowVisible(GetDlgItem(releases, 814)),
"withdrawn releases show their archived notes without a dead Gitea release link");
SetDlgItemTextW(releases, 810, L"v0.8.0");
require(releaseText(812) == L"v0.8.0" && releaseText(813).find(L"Find files recursively") != std::wstring::npos,
"release history searches and shows English notes");
const auto ukrainian = MAKELANGID(LANG_UKRAINIAN, SUBLANG_DEFAULT);
ks::showWhatsNew(app, ukrainian);
require(releases == app.helpWindow && std::wstring(ks::whatsNewTitle(ukrainian)) == L"Що нового" &&
releaseText(814) == L"Відкрити в Gitea",
"the same window can display Ukrainian release history");
SetDlgItemTextW(releases, 810, L"v0.8.0");
require(releaseText(812) == L"v0.8.0" && releaseText(813).find(L"Рекурсивний пошук") != std::wstring::npos &&
releaseText(813).find(L"Find files recursively") == std::wstring::npos,
"Ukrainian notes render without the adjacent English section");
SetDlgItemTextW(releases, 810, L"");
require(TreeView_GetCount(versions) > 2 && releaseText(812) == L"v0.8.0",
"clearing the search retains the selected release in the full history");
RECT releaseClient{};
GetClientRect(releases, &releaseClient);
RedrawWindow(releases, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);
const auto releaseDc = GetDC(releases);
const auto releasePreview = ks::screenshotClip(releaseDc, releaseClient.right, releaseClient.bottom, {});
ReleaseDC(releases, releaseDc);
ks::atomicWrite(std::filesystem::path(ks::executable()).parent_path() / L"whats-new.png",
ks::encodePng(ks::decodeImage(releasePreview)));
ks::showHelp(app);
require(releases == app.helpWindow && releaseText(812) == L"Getting started" &&
!IsWindowVisible(GetDlgItem(releases, 814)),
"returning to the guide restores its topics and actions");
}
std::filesystem::remove_all(temp);
std::cout << "Passed " << checks << " offline help checks\n";
+35
View File
@@ -79,6 +79,7 @@ bool typeDuringMacros = false;
ULONGLONG macroStart{}, macroEnd{};
int copyFailuresRemaining = 0, copyRequests = 0;
int droppedSelectionKeys = 0;
int delayedSelectionKeys = 0;
bool trimCopiedSpaces = false;
int trimmedCopies = 0;
bool temporaryClipboardExcluded = true;
@@ -152,6 +153,16 @@ LRESULT CALLBACK observeEnter(HWND w, UINT message, WPARAM wp, LPARAM lp, UINT_P
--copyFailuresRemaining;
return 0;
}
if (delayedSelectionKeys)
{
DWORD start{}, end{};
SendMessageW(w, EM_GETSEL, reinterpret_cast<WPARAM>(&start), reinterpret_cast<LPARAM>(&end));
auto result = DefSubclassProc(w, message, wp, lp);
// Apply the remaining Shift+Left moves after publishing the partial selection.
SendMessageW(w, EM_SETSEL, end, start - std::min<DWORD>(start, delayedSelectionKeys));
delayedSelectionKeys = 0;
return result;
}
if (trimCopiedSpaces)
{
auto result = DefSubclassProc(w, message, wp, lp);
@@ -338,6 +349,8 @@ LRESULT CALLBACK procedure(HWND w, UINT msg, WPARAM wp, LPARAM lp)
switch (stage++)
{
case 0:
app->settings.writeLog = true;
ks::setLoggingEnabled(true);
saved = ks::readClipboard(app->window, 64 * 1024 * 1024);
captured = true;
app->ownSequence = ks::writeClipboard(app->window, ks::textClip(sentinel));
@@ -685,6 +698,26 @@ LRESULT CALLBACK procedure(HWND w, UINT msg, WPARAM wp, LPARAM lp)
case 59:
require(text() == L"OLDghbdtn NEXT", "hotkey without selection reconverts only the previous middle range");
require(ks::readClipboard(app->window).text() == sentinel, "selected and repeated conversions restore clipboard");
[[fallthrough]];
case 95:
if (!captured)
{
saved = ks::readClipboard(app->window, 64 * 1024 * 1024);
captured = true;
app->ownSequence = ks::writeClipboard(app->window, ks::textClip(sentinel));
}
prepare(L" nen NEXT", false);
SendMessageW(field, EM_SETSEL, 6, 6);
record(L"nen ");
droppedSelectionKeys = delayedSelectionKeys = 2;
app->transform(ks::Direct + ru);
stage = 96;
break;
case 96:
require(text() == L" " + ks::convertTo(L"nen ", app->layouts, ru, en) + L"NEXT",
"delayed selection preserves the older prefix and text after the caret");
require(!droppedSelectionKeys && !delayedSelectionKeys, "fixture applied the delayed selection moves");
require(ks::readClipboard(app->window).text() == sentinel, "delayed selection restores clipboard");
finish();
break;
case 66:
@@ -1392,6 +1425,8 @@ int main(int argc, char **argv)
stage = 93;
if (argc > 1 && std::string(argv[1]) == "--snippet-word-boundaries")
stage = 84;
if (argc > 1 && std::string(argv[1]) == "--delayed-selection-only")
stage = 95;
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");