From f57100bb36eae3b4d75f3c315973405f705b8de6 Mon Sep 17 00:00:00 2001 From: Jon TURNEY Date: Tue, 23 Feb 2010 13:38:48 +0000 Subject: [PATCH] hw/xwin: Process one Windows message per wakeup, rather than all of them. De-queuing Windows messages and X events happens in the same thread of execution. Draining the windows message queue can lead to the X event queue overflowing if lots of those windows messages cause X events (e.g. if a keyboard macro program has just dumped thousands of keypresses into the Windows message queue). See the mailing list thread [1] for more details. Processing one Windows message per wakeup, rather than all of them gives the X server a chance to do stuff as well after each message. [1] http://cygwin.com/ml/cygwin-xfree/2010-01/msg00056.html Signed-off-by: Jon TURNEY Reviewed-by: Colin Harrison --- hw/xwin/winblock.c | 32 ++++++++++++++++---------------- hw/xwin/winwakeup.c | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/hw/xwin/winblock.c b/hw/xwin/winblock.c index a4ae8669f..c3ef4becd 100644 --- a/hw/xwin/winblock.c +++ b/hw/xwin/winblock.c @@ -42,14 +42,26 @@ winBlockHandler(ScreenPtr pScreen, #if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) winScreenPriv(pScreen); #endif - MSG msg; #ifndef HAS_DEVWINDOWS struct timeval **tvp = pTimeout; if (*tvp != NULL) { + if (GetQueueStatus(QS_ALLINPUT | QS_ALLPOSTMESSAGE) != 0) { + /* If there are still messages to process on the Windows message + queue, make sure select() just polls rather than blocking. + */ + (*tvp)->tv_sec = 0; + (*tvp)->tv_usec = 0; + } + else { + /* Otherwise, lacking /dev/windows, we must wake up again in + a reasonable time to check the Windows message queue. without + noticeable delay. + */ (*tvp)->tv_sec = 0; (*tvp)->tv_usec = 100; + } } #endif @@ -68,25 +80,13 @@ winBlockHandler(ScreenPtr pScreen, if (iReturn != 0) { ErrorF("winBlockHandler - pthread_mutex_unlock () failed: %d\n", iReturn); - goto winBlockHandler_ProcessMessages; } - - winDebug("winBlockHandler - pthread_mutex_unlock () returned\n"); + else { + winDebug("winBlockHandler - pthread_mutex_unlock () returned\n"); + } } - - winBlockHandler_ProcessMessages: #endif - /* Process all messages on our queue */ - while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - if ((g_hDlgDepthChange == 0 - || !IsDialogMessage(g_hDlgDepthChange, &msg)) - && (g_hDlgExit == 0 || !IsDialogMessage(g_hDlgExit, &msg)) - && (g_hDlgAbout == 0 || !IsDialogMessage(g_hDlgAbout, &msg))) { - DispatchMessage(&msg); - } - } - /* At least one X client has asked to suspend the screensaver, so reset Windows' display idle timer diff --git a/hw/xwin/winwakeup.c b/hw/xwin/winwakeup.c index 77c160533..795221a1a 100644 --- a/hw/xwin/winwakeup.c +++ b/hw/xwin/winwakeup.c @@ -43,8 +43,8 @@ winWakeupHandler(ScreenPtr pScreen, { MSG msg; - /* Process all messages on our queue */ - while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + /* Process one message from our queue */ + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if ((g_hDlgDepthChange == 0 || !IsDialogMessage(g_hDlgDepthChange, &msg)) && (g_hDlgExit == 0 || !IsDialogMessage(g_hDlgExit, &msg))