Pause and resume resident input processing from the tray
This commit is contained in:
1 parent
f5fc7d205c
commit
3be628cd8f
11 files changed
+428
-57
No files matched your search
@@ -7,6 +7,7 @@
|
||||
#include <commctrl.h>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include "input_pause.h"
|
||||
static int settingsCloseChoice = IDCANCEL;
|
||||
static int settingsClosePrompts = 0;
|
||||
static void CALLBACK answerSettingsClose(HWND, UINT, UINT_PTR, DWORD)
|
||||
@@ -27,6 +28,44 @@ LRESULT CALLBACK countControlMoves(HWND w, UINT message, WPARAM wp, LPARAM lp, U
|
||||
}
|
||||
namespace ks {
|
||||
struct InputRegressionAccess {
|
||||
static LRESULT CALLBACK probeInput(HWND w, UINT msg, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR context) {
|
||||
auto &app = *reinterpret_cast<App *>(context);
|
||||
static bool queuedSnippet = false;
|
||||
// Queue a real expansion just before TrackPopupMenu returns the pause command.
|
||||
if (msg == WM_EXITMENULOOP && app.inputState == App::InputState::Active)
|
||||
queuedSnippet = app.queueSnippet(w, 0, 2, w);
|
||||
if (msg != ProbeInputState) return DefSubclassProc(w, msg, wp, lp);
|
||||
// Also exercise settings/layout updates that would normally re-register shortcuts.
|
||||
if (wp && app.inputState == App::InputState::Paused) {
|
||||
app.applySettings(app.settings);
|
||||
app.reloadLayouts();
|
||||
app.dispatch(Toggle);
|
||||
app.pasteEntry(L"fixture", false);
|
||||
const auto version = app.inputVersion.load();
|
||||
KBDLLHOOKSTRUCT key{};
|
||||
key.vkCode = 'A';
|
||||
if (app.handleKeyboard(key, true, 0) || app.inputVersion != version) return 0;
|
||||
const std::string status = R"({"action":"status"})";
|
||||
const auto response = app.lanCommand(Bytes(status.begin(), status.end()));
|
||||
if (std::string(response.begin(), response.end()).find("Input processing paused") == std::string::npos)
|
||||
return 0;
|
||||
}
|
||||
const bool bound = app.isHotkey(VK_F22, MOD_CONTROL | MOD_SHIFT);
|
||||
if (app.inputState == App::InputState::Active && app.keyboardHook && app.mouseHook &&
|
||||
app.filesHotkeyId && bound) return 1;
|
||||
if (app.inputState == App::InputState::Paused && !app.keyboardHook && !app.mouseHook &&
|
||||
!app.filesHotkeyId && !bound && !app.busy && app.snippetPending == -1 &&
|
||||
!app.snippetTyping && queuedSnippet && !app.transformAttempt) return 2;
|
||||
return 0;
|
||||
}
|
||||
static void CALLBACK installProbe(HWND, UINT, UINT_PTR timer, DWORD) {
|
||||
auto app = App::current;
|
||||
if (app && app->window && SetWindowSubclass(app->window, probeInput, 1, reinterpret_cast<DWORD_PTR>(app))) {
|
||||
KillTimer(app->window, 5); // Keep the input fixture independent of update checks.
|
||||
SetTimer(app->window, 2, 60000, nullptr);
|
||||
KillTimer(nullptr, timer);
|
||||
}
|
||||
}
|
||||
static int snippetChoice(App &a, const std::vector<Snippet> &snippets) {
|
||||
a.settings.snippets=snippets; a.settings.autoCorrect=false; a.busy=false;
|
||||
a.snippetPending=-1; a.typingTarget=nullptr; a.snippetTyping=false;
|
||||
@@ -169,6 +208,20 @@ struct InputRegressionAccess {
|
||||
};
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
if (argc == 2 && std::string(argv[1]) == "--input-pause") return testInputPause();
|
||||
if (argc == 2 && std::string(argv[1]) == "--input-pause-resident") {
|
||||
// The driver copies this binary alone into a fresh fixture folder.
|
||||
auto folder = std::filesystem::path(ks::executable()).parent_path();
|
||||
if (!folder.filename().wstring().starts_with(L"KSwitcher-input-pause-")) return 1;
|
||||
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
ks::App app(GetModuleHandleW(nullptr), false, folder / L"data");
|
||||
app.settings.toggle = L"Ctrl+Shift+F22";
|
||||
app.settings.filesHotkey = L"Ctrl+Shift+F23";
|
||||
app.settings.snippets = {{L";t", L"fixture"}};
|
||||
app.settings.history = app.settings.autoCorrect = app.settings.autostart = false;
|
||||
SetTimer(nullptr, 0, 10, ks::InputRegressionAccess::installProbe);
|
||||
return app.execute();
|
||||
}
|
||||
if (argc == 2 && std::string(argv[1]) == "--update-check") {
|
||||
try {
|
||||
auto result = ks::runUpdate(false, {});
|
||||
|
||||
Reference in new issue
Block a user