Code optimization and bug fixes.

This commit is contained in:
ak47 committed 2026-10-14 20:55:28 -04:00
1 parent 4c47cc5fc4
commit b16c6968ae
11 files changed
+124 -28

No files matched your search

+32 -2
View File
@@ -22,6 +22,29 @@ static HWND editor, password, history;
static int step;
static int history_position;
static DWORD WINAPI update_history_from_worker(void *window) {
SendMessageW((HWND)window, WM_SETTEXT, 0, (LPARAM)L"unrelated worker update");
return 0;
}
static void unrelated_history_update(void) {
HANDLE thread = CreateThread(NULL, 0, update_history_from_worker, history, 0, NULL);
if (!thread) ExitProcess(2);
// Dispatch sent messages without removing a queued message, as GetMessage
// does while waiting for input. Do not rely on worker/timer scheduling.
for (;;) {
DWORD result = MsgWaitForMultipleObjects(1, &thread, FALSE, 2000, QS_SENDMESSAGE);
if (result == WAIT_OBJECT_0) break;
if (result != WAIT_OBJECT_0 + 1) ExitProcess(2);
MSG message;
PeekMessageW(&message, NULL, 0, 0, PM_NOREMOVE);
}
CloseHandle(thread);
WCHAR text[64];
GetWindowTextW(history, text, 64);
if (lstrcmpW(text, L"unrelated worker update")) ExitProcess(2);
}
// Model MUSHclient's PreTranslateMessage: consume queued arrows before the
// Edit procedure, then use SetWindowText and SetSel to recall a command.
static BOOL history_input(const MSG *message) {
@@ -29,7 +52,10 @@ static BOOL history_input(const MSG *message) {
(message->wParam != VK_UP && message->wParam != VK_DOWN)) return FALSE;
if (message->wParam == VK_UP && history_position < 2) ++history_position;
else if (message->wParam == VK_DOWN && history_position > 0) --history_position;
else return TRUE;
else {
if (step == 49) unrelated_history_update();
return TRUE;
}
const WCHAR *commands[] = {L"", L"history north", L"history south"};
SetWindowTextW(history, commands[history_position]);
int length = GetWindowTextLengthW(history);
@@ -239,10 +265,14 @@ static LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wp, LPARAM
PostMessageW(history, WM_KEYDOWN, VK_DOWN, 1); // no history change
break;
case 50:
// The silent worker update must still refresh the navigation snapshot.
PostMessageW(history, WM_KEYDOWN, VK_RIGHT, 1);
break;
case 51:
SendMessageW(history, EM_SETPASSWORDCHAR, L'*', 0);
PostMessageW(history, WM_KEYDOWN, VK_UP, 1);
break;
case 51:
case 52:
SetFocus(password);
SendMessageW(history, EM_SETPASSWORDCHAR, 0, 0);
PostMessageW(history, WM_KEYDOWN, VK_UP, 1); // background recall