Fix X11 fd polling initialization in glib main loop

This resolves Bug 1358
pull/2/head
Timothy Pearson 12 years ago
parent a7865cf691
commit 72eba91414

@ -86,6 +86,10 @@ class QEventLoopPrivate
public:
QEventLoopPrivate()
{
#if defined(Q_WS_X11)
xfd = -1;
x_gPollFD.fd = -1;
#endif // Q_WS_X11
reset();
}
@ -106,9 +110,7 @@ public:
#if defined(Q_WS_X11)
int xfd;
GPollFD x_gPollFD;
#endif // Q_WS_X11
int thread_pipe[2];

@ -82,15 +82,32 @@ static GSourceFuncs qt_gsource_funcs = {
static gboolean qt_gsource_prepare ( GSource *source,
gint *timeout )
{
QtGSource * qtGSource;
qtGSource = (QtGSource*) source;
return qtGSource->qeventLoop->gsourcePrepare(source, timeout);
QtGSource * qtGSource = (QtGSource*) source;
QEventLoop* candidateEventLoop = qtGSource->qeventLoop;
QEventLoop* activeThreadEventLoop = QApplication::eventLoop();
if (candidateEventLoop == activeThreadEventLoop) {
return candidateEventLoop->gsourcePrepare(source, timeout);
}
else {
// Prepare failed
return FALSE;
}
}
static gboolean qt_gsource_check ( GSource *source )
{
QtGSource * qtGSource = (QtGSource*) source;
return qtGSource->qeventLoop->gsourceCheck(source);
QEventLoop* candidateEventLoop = qtGSource->qeventLoop;
QEventLoop* activeThreadEventLoop = QApplication::eventLoop();
if (candidateEventLoop == activeThreadEventLoop) {
return candidateEventLoop->gsourceCheck(source);
}
else {
// Check failed
return FALSE;
}
}
static gboolean qt_gsource_dispatch ( GSource *source,
@ -205,7 +222,6 @@ void QEventLoop::init()
qtGSource->qeventLoop = this;
// init main loop and attach gsource
#ifdef DEBUG_QT_GLIBMAINLOOP
printf("inside init(1)\n");
#endif
@ -217,13 +233,13 @@ void QEventLoop::init()
// poll for X11 events
if ( qt_is_gui_used && QApplication::isGuiThread() ) {
d->x_gPollFD.fd = d->xfd;
d->x_gPollFD.events = G_IO_IN | G_IO_HUP;
d->x_gPollFD.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
g_source_add_poll(d->gSource, &d->x_gPollFD);
}
// poll thread-pipe
d->threadPipe_gPollFD.fd = d->thread_pipe[0];
d->threadPipe_gPollFD.events = G_IO_IN | G_IO_HUP;
d->threadPipe_gPollFD.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
g_source_add_poll(d->gSource, &d->threadPipe_gPollFD);
@ -336,12 +352,13 @@ bool QEventLoop::processX11Events()
}
nevents++;
if ( qApp->x11ProcessEvent( &event ) == 1 )
if ( qApp->x11ProcessEvent( &event ) == 1 ) {
return TRUE;
}
}
}
}
}
if ( d->shortcut ) {
return FALSE;
@ -463,14 +480,9 @@ bool QEventLoop::gsourceCheck(GSource *gs) {
printf("inside gsourceCheck(1)\n");
#endif
// Socketnotifier events?
QPtrList<QSockNotGPollFD> *list = &d->sn_list;
//if ( list ) {
QSockNotGPollFD *sn = list->first();
while ( sn ) {
if ( sn->gPollFD.revents )
@ -500,10 +512,9 @@ bool QEventLoop::gsourceCheck(GSource *gs) {
return TRUE; // we got more X11 events!
}
// check if we have timers to activate?
// check if we have timers to activate?
timeval * tm =qt_wait_timer();
if (tm && (tm->tv_sec == 0 && tm->tv_usec == 0 )) {
#ifdef DEBUG_QT_GLIBMAINLOOP
printf("inside gsourceCheck(2) qtwaittimer!\n");
@ -513,7 +524,6 @@ bool QEventLoop::gsourceCheck(GSource *gs) {
}
// nothing to dispatch
#ifdef DEBUG_QT_GLIBMAINLOOP
printf("inside gsourceCheck(2) nothing to dispatch!\n");
#endif
@ -534,7 +544,6 @@ bool QEventLoop::gsourceDispatch(GSource *gs) {
#endif
int nevents=0;
ProcessEventsFlags flags = d->pev_flags;
#ifdef DEBUG_QT_GLIBMAINLOOP
@ -588,12 +597,10 @@ bool QEventLoop::gsourceDispatch(GSource *gs) {
//return (nevents > 0);
// now process x11 events!
#ifdef DEBUG_QT_GLIBMAINLOOP
printf("inside gsourceDispatch(2) hasPendingEvents=%d\n", hasPendingEvents());
#endif
if (hasPendingEvents()) {
// color approx. optimization - only on X11
qt_reset_color_avail();
@ -627,6 +634,11 @@ void QEventLoop::appStartingUp()
{
if ( qt_is_gui_used ) {
d->xfd = XConnectionNumber( QPaintDevice::x11AppDisplay() );
if ( (d->x_gPollFD.fd == -1) && QApplication::isGuiThread() ) {
d->x_gPollFD.fd = d->xfd;
d->x_gPollFD.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
g_source_add_poll(d->gSource, &d->x_gPollFD);
}
}
}

Loading…
Cancel
Save