From 307e909b51d15428e1db02227e7d37cd4c25f5db Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 12 Sep 2022 11:27:34 +0100 Subject: [PATCH] Windows: rethink API of write_aclip(). That clipboard-writing function is called just once, from the Event Log dialog procedure, for when the user deliberately copies to the clipboard. That call always passes must_deselect = true, which means the conditional WM_IGNORE_CLIP messages are not sent. So it's simpler to remove that parameter completely, and the conditional calls which are never used. Also, the clipboard data copied from the Event Log dialog is being put in the clipboard associated with the main PuTTY terminal window. But anything else we copy from a dialog box using Windows's built-in copy-paste mechanisms would surely be associated with the _dialog_, not its parent window. So we should do the same thing here. Therefore, I've added a HWND parameter to write_aclip() and used that in place of wgs.term_hwnd, so that we can pass in the HWND of the dialog itself. --- windows/dialog.c | 2 +- windows/platform.h | 2 +- windows/window.c | 10 ++-------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/windows/dialog.c b/windows/dialog.c index 5e49cca9..c34703f6 100644 --- a/windows/dialog.c +++ b/windows/dialog.c @@ -326,7 +326,7 @@ static INT_PTR CALLBACK LogProc(HWND hwnd, UINT msg, memcpy(p, sel_nl, sizeof(sel_nl)); p += sizeof(sel_nl); } - write_aclip(CLIP_SYSTEM, clipdata, size, true); + write_aclip(hwnd, CLIP_SYSTEM, clipdata, size); sfree(clipdata); } sfree(selitems); diff --git a/windows/platform.h b/windows/platform.h index 959a207c..92dba117 100644 --- a/windows/platform.h +++ b/windows/platform.h @@ -249,7 +249,7 @@ const SeatDialogPromptDescriptions *win_seat_prompt_descriptions(Seat *seat); * which takes the data string in the system code page instead of * Unicode. */ -void write_aclip(int clipboard, char *, int, bool); +void write_aclip(HWND hwnd, int clipboard, char *, int); #define WM_NETEVENT (WM_APP + 5) diff --git a/windows/window.c b/windows/window.c index 4a920492..fb27f596 100644 --- a/windows/window.c +++ b/windows/window.c @@ -4942,7 +4942,7 @@ static void wintw_palette_set(TermWin *win, unsigned start, } } -void write_aclip(int clipboard, char *data, int len, bool must_deselect) +void write_aclip(HWND hwnd, int clipboard, char *data, int len) { HGLOBAL clipdata; void *lock; @@ -4960,18 +4960,12 @@ void write_aclip(int clipboard, char *data, int len, bool must_deselect) ((unsigned char *) lock)[len] = 0; GlobalUnlock(clipdata); - if (!must_deselect) - SendMessage(wgs.term_hwnd, WM_IGNORE_CLIP, true, 0); - - if (OpenClipboard(wgs.term_hwnd)) { + if (OpenClipboard(hwnd)) { EmptyClipboard(); SetClipboardData(CF_TEXT, clipdata); CloseClipboard(); } else GlobalFree(clipdata); - - if (!must_deselect) - SendMessage(wgs.term_hwnd, WM_IGNORE_CLIP, false, 0); } typedef struct _rgbindex {