Commit 94d433c8 authored by Jon Turney's avatar Jon Turney

hw/xwin: Fix clipboard thread restart

It seems that the clipboard thread restart mechanism has been broken for a
while, which can be demonstrated using XDMCP with KDM (e.g. to a Kubutunu 12.04

KDM kills all attached clients, including the clipboard integration client,
which restarts, but then exits on WM_QUIT.

Using PostQuitMessage() in WM_DESTROY is unhelpful, as we may not actually be
quitting the thread, if we just destroyed the window because the clipboard
thread is about to retry, because he WM_QUIT message sticks around, and is
noticed the next time we look at the window message queue and confuses us into
thinking we need to quit.

Sending a WM_DESTROY is apparently never correct anyhow, see [1]


1/ Use DestroyWindow() to destroy the clipboard messaging window when cleaning
up for retry or exit in winClipboardProc (the clipboard thread main proc)

2/ Send a special WM_WM_QUIT message in winClipboardWindowDestroy() from the X
server thread when the X server is resetting.

3/ When processing that WM_WM_QUIT message in the clipboard thread, cause the
clipboard window to PostQuitMessage(), which causes the clipboard thread to

[1] Jon Turney's avatarJon TURNEY <>
Reviewed-by: default avatarColin Harrison <>
parent b4a08e64
......@@ -44,6 +44,7 @@
#define WM_WM_REINIT (WM_USER + 1)
#define WM_WM_QUIT (WM_USER + 2)
* References to external symbols
......@@ -351,7 +351,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
/* Close our Windows window */
if (g_hwndClipboard) {
/* Close our X window */
......@@ -491,7 +491,7 @@ void
if (g_hwndClipboard) {
SendMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
SendMessage(g_hwndClipboard, WM_WM_QUIT, 0, 0);
......@@ -154,6 +154,12 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
ChangeClipboardChain(hwnd, s_hwndNextViewer);
s_hwndNextViewer = NULL;
return 0;
case WM_WM_QUIT:
winDebug("winClipboardWindowProc - WM_WM_QUIT\n");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment