Exemple #1
0
void Waiter::stop(bool retValue)
{
	timer_.stop();
	QAbstractEventDispatcher * eventDispatcher = QAbstractEventDispatcher::instance();
	if (eventDispatcher) {
		while (eventDispatcher->processEvents(QEventLoop::AllEvents));
	}
	eventLoop_.exit(retValue ? 0 : 1);
}
Exemple #2
0
bool
nsAppShell::ProcessNextNativeEvent(bool mayWait)
{
    QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents;

    if (mayWait)
        flags |= QEventLoop::WaitForMoreEvents;

    QAbstractEventDispatcher *dispatcher =  QAbstractEventDispatcher::instance(qApp->thread());
    if (!dispatcher)
        return PR_FALSE;

    return dispatcher->processEvents(flags) ? PR_TRUE : PR_FALSE;
}
Exemple #3
0
bool QX11Data::clipboardWaitForEvent(Window win, int type, XEvent *event, int timeout)
{
    QElapsedTimer started;
    started.start();
    QElapsedTimer now = started;

    if (QAbstractEventDispatcher::instance()->inherits("QtMotif")
        || QApplication::clipboard()->property("useEventLoopWhenWaiting").toBool()) {
        if (waiting_for_data) {
            Q_ASSERT(!"QClipboard: internal error, qt_xclb_wait_for_event recursed");
            return false;
        }
        waiting_for_data = true;


        has_captured_event = false;
        capture_event_win = win;
        capture_event_type = type;

        QApplication::EventFilter old_event_filter =
            qApp->setEventFilter(qt_x11_clipboard_event_filter);

        do {
            if (XCheckTypedWindowEvent(display, win, type, event)) {
                waiting_for_data = false;
                qApp->setEventFilter(old_event_filter);
                return true;
            }

            XSync(X11->display, false);
            usleep(50000);

            now.start();

            QEventLoop::ProcessEventsFlags flags(QEventLoop::ExcludeUserInputEvents
                                                 | QEventLoop::ExcludeSocketNotifiers
                                                 | QEventLoop::WaitForMoreEvents
                                                 | QEventLoop::X11ExcludeTimers);
            QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
            eventDispatcher->processEvents(flags);

            if (has_captured_event) {
                waiting_for_data = false;
                *event = captured_event;
                qApp->setEventFilter(old_event_filter);
                return true;
            }
        } while (started.msecsTo(now) < timeout);

        waiting_for_data = false;
        qApp->setEventFilter(old_event_filter);
    } else {
        do {
            if (XCheckTypedWindowEvent(X11->display,win,type,event))
                return true;

            // process other clipboard events, since someone is probably requesting data from us
            XEvent e;
            if (XCheckIfEvent(X11->display, &e, checkForClipboardEvents, 0))
                qApp->x11ProcessEvent(&e);

            now.start();

            XFlush(X11->display);

            // sleep 50 ms, so we don't use up CPU cycles all the time.
            struct timeval usleep_tv;
            usleep_tv.tv_sec = 0;
            usleep_tv.tv_usec = 50000;
            select(0, 0, 0, 0, &usleep_tv);
        } while (started.msecsTo(now) < timeout);
    }
    return false;
}