Skip to content

Commit

Permalink
handle unicode text for clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Jan 22, 2024
1 parent 614f176 commit c9f5077
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,18 @@ static char *get_clipboard(void *talloc_ctx) {
return ret;
}

static void set_clipboard(char *text) {
static void set_clipboard(const char *text) {
if (!OpenClipboard(ctx->hwnd)) return;
EmptyClipboard();

HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, strlen(text) + 1);
int len = MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, len * sizeof(WCHAR));
if (hData != NULL) {
char *data = (char *)GlobalLock(hData);
WCHAR *data = (WCHAR *)GlobalLock(hData);
if (data != NULL) {
strcpy(data, text);
MultiByteToWideChar(CP_UTF8, 0, text, -1, data, len);
GlobalUnlock(hData);
SetClipboardData(CF_TEXT, hData);
SetClipboardData(CF_UNICODETEXT, hData);
}
}
CloseClipboard();
Expand Down

0 comments on commit c9f5077

Please sign in to comment.