From 50eb00e57e8fb931b8311291d2669dddd67256a0 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Mon, 22 Jan 2024 21:32:25 +0800 Subject: [PATCH] support for CF_HDROP clipboard format --- src/plugin.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/plugin.c b/src/plugin.c index 100b2ba..bdb8c0b 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -40,6 +40,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static char *get_clipboard(void *talloc_ctx) { if (!OpenClipboard(ctx->hwnd)) return NULL; + // try to get unicode text first HANDLE hData = GetClipboardData(CF_UNICODETEXT); char *ret = NULL; if (hData != NULL) { @@ -48,7 +49,33 @@ static char *get_clipboard(void *talloc_ctx) { ret = mp_to_utf8(talloc_ctx, data); GlobalUnlock(hData); } + goto done; } + + // try to get file drop list + hData = GetClipboardData(CF_HDROP); + if (hData != NULL) { + HDROP hDrop = (HDROP)GlobalLock(hData); + if (hDrop != NULL) { + int count = DragQueryFileW(hDrop, 0xFFFFFFFF, NULL, 0); + if (count > 0) { + void *tmp = talloc_new(NULL); + ret = talloc_strdup(talloc_ctx, ""); + for (int i = 0; i < count; i++) { + int len = DragQueryFileW(hDrop, i, NULL, 0); + wchar_t *path_w = talloc_array(tmp, wchar_t, len + 1); + if (DragQueryFileW(hDrop, i, path_w, len + 1)) { + char *path = mp_to_utf8(tmp, path_w); + ret = talloc_asprintf_append(ret, "%s\n", path); + } + } + talloc_free(tmp); + } + GlobalUnlock(hData); + } + } + +done: CloseClipboard(); return ret;