From 31f2adf0a2075032845a05bc01b4e01f32ee9598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Mon, 24 May 2004 13:15:30 +0000 Subject: [PATCH] Better way of checking the events queue in updateXTime(). svn path=/trunk/kdebase/kwin/; revision=314133 --- utils.cpp | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/utils.cpp b/utils.cpp index 5edec173b6..0fae3dc801 100644 --- a/utils.cpp +++ b/utils.cpp @@ -249,36 +249,34 @@ static Bool update_x_time_predicate( Display*, XEvent* event, XPointer ) return False; } -static Time nextXTime() - { - next_x_time = CurrentTime; - XEvent dummy; - XCheckIfEvent( qt_xdisplay(), &dummy, update_x_time_predicate, NULL ); - return next_x_time; - } - /* Updates qt_x_time. This used to simply fetch current timestamp from the server, but that can cause qt_x_time to be newer than timestamp of events that are still in our events queue, thus e.g. making XSetInputFocus() caused by such - event to be ignored. Therefore first events queue is searched for first - event with timestamp. + event to be ignored. Therefore events queue is searched for first + event with timestamp, and extra PropertyNotify is generated in order to make + sure such event is found. */ void updateXTime() { - qt_x_time = nextXTime(); - if( qt_x_time == CurrentTime ) + static QWidget* w = 0; + if ( !w ) + w = new QWidget; + long data = 1; + XChangeProperty(qt_xdisplay(), w->winId(), atoms->kwin_running, atoms->kwin_running, 32, + PropModeAppend, (unsigned char*) &data, 1); + next_x_time = CurrentTime; + XEvent dummy; + XCheckIfEvent( qt_xdisplay(), &dummy, update_x_time_predicate, NULL ); + if( next_x_time == CurrentTime ) { - static QWidget* w = 0; - if ( !w ) - w = new QWidget; - long data = 1; - XChangeProperty(qt_xdisplay(), w->winId(), atoms->kwin_running, atoms->kwin_running, 32, - PropModeAppend, (unsigned char*) &data, 1); - XEvent ev; - XWindowEvent( qt_xdisplay(), w->winId(), PropertyChangeMask, &ev ); - qt_x_time = ev.xproperty.time; + XSync( qt_xdisplay(), False ); + XCheckIfEvent( qt_xdisplay(), &dummy, update_x_time_predicate, NULL ); } + assert( next_x_time != CurrentTime ); + qt_x_time = next_x_time; + XEvent ev; // remove the PropertyNotify event from the events queue + XWindowEvent( qt_xdisplay(), w->winId(), PropertyChangeMask, &ev ); } static int server_grab_count = 0;