1 qt-bugs@ issue : 15222 (part of)
3 author: Lubos Lunak <l.lunak@kde.org>
5 This patch should fix KDE bug #61412 and its numerous duplicates (applies
6 to both Qt-3.2.x and Qt-3.3.x). I'm not opposed to trying using
7 the event loop if done properly, but right now it simply fails way too
8 often, and what's worse, qFatal() does exit(1), so there's usually
12 --- src/kernel/qclipboard_x11.cpp.sav 2004-01-06 19:24:40.000000000 +0100
13 +++ src/kernel/qclipboard_x11.cpp 2004-01-22 19:48:32.000000000 +0100
14 @@ -112,10 +112,6 @@ static bool pending_selection_changed =
16 // event capture mechanism for qt_xclb_wait_for_event
17 static bool waiting_for_data = FALSE;
18 -static bool has_captured_event = FALSE;
19 -static Window capture_event_win = None;
20 -static int capture_event_type = -1;
21 -static XEvent captured_event;
23 class QClipboardWatcher; // forward decl
24 static QClipboardWatcher *selection_watcher = 0;
25 @@ -432,69 +428,36 @@ bool QClipboard::selectionModeEnabled()
26 { return inSelectionMode_obsolete; }
29 -// event filter function... captures interesting events while
30 -// qt_xclb_wait_for_event is running the event loop
31 -static int qt_xclb_event_filter(XEvent *event)
33 - if (event->xany.type == capture_event_type &&
34 - event->xany.window == capture_event_win) {
35 - VDEBUG( "QClipboard: event_filter(): caught event type %d", event->type );
36 - has_captured_event = TRUE;
37 - captured_event = *event;
44 bool qt_xclb_wait_for_event( Display *dpy, Window win, int type, XEvent *event,
47 - if ( waiting_for_data )
48 - qFatal( "QClipboard: internal error, qt_xclb_wait_for_event recursed" );
50 - waiting_for_data = TRUE;
52 QTime started = QTime::currentTime();
55 - has_captured_event = FALSE;
56 - capture_event_win = win;
57 - capture_event_type = type;
59 - QX11EventFilter old_event_filter = qt_set_x11_event_filter(qt_xclb_event_filter);
60 + bool flushed = FALSE;
63 - if ( XCheckTypedWindowEvent(dpy,win,type,event) ) {
64 - waiting_for_data = FALSE;
65 - qt_set_x11_event_filter(old_event_filter);
66 + if ( XCheckTypedWindowEvent(dpy,win,type,event) )
70 now = QTime::currentTime();
71 if ( started > now ) // crossed midnight
74 - // 0x08 == ExcludeTimers for X11 only
75 - qApp->eventLoop()->processEvents( QEventLoop::ExcludeUserInput |
76 - QEventLoop::ExcludeSocketNotifiers |
77 - QEventLoop::WaitForMore | 0x08 );
79 - if ( has_captured_event ) {
80 - waiting_for_data = FALSE;
81 - *event = captured_event;
82 - qt_set_x11_event_filter(old_event_filter);
88 - } while ( started.msecsTo(now) < timeout );
90 - waiting_for_data = FALSE;
91 - qt_set_x11_event_filter(old_event_filter);
92 + // sleep 50ms, so we don't use up CPU cycles all the time.
93 + struct timeval usleep_tv;
94 + usleep_tv.tv_sec = 0;
95 + usleep_tv.tv_usec = 50000;
96 + select(0, 0, 0, 0, &usleep_tv);
97 + } while ( started.msecsTo(now) < timeout );
103 static inline int maxSelectionIncr( Display *dpy )
104 { return XMaxRequestSize(dpy) > 65536 ? 65536*4 : XMaxRequestSize(dpy)*4 - 100; }