diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2018-03-22 14:54:43 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2018-05-07 10:43:16 +0000 |
commit | 4d15f393a76cfcc4d54f311884fedac5bf0f72ee (patch) | |
tree | ca22af989c7bedc11336bb6910ff54c0ca825c6e /src/gui/kernel/qplatformwindow.cpp | |
parent | 2d1ac61d950d96b968e08cb001497afaf3a4aeca (diff) |
Move default implementation of update requests to QPlatformWindow
Change-Id: I4cbb8d2023068288e298ab21f5cd8bc258825c77
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/gui/kernel/qplatformwindow.cpp')
-rw-r--r-- | src/gui/kernel/qplatformwindow.cpp | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index 9fe68bd564..e83f76fb06 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -461,14 +461,26 @@ bool QPlatformWindow::setWindowModified(bool modified) /*! Reimplement this method to be able to do any platform specific event - handling. All events for window() are passed to this function before being - sent to QWindow::event(). + handling. All non-synthetic events for window() are passed to this + function before being sent to QWindow::event(). - The default implementation is empty and does nothing with \a event. + Return true if the event should not be passed on to the QWindow. + + Subclasses should always call the base class implementation. */ -void QPlatformWindow::windowEvent(QEvent *event) +bool QPlatformWindow::windowEvent(QEvent *event) { - Q_UNUSED(event); + Q_D(QPlatformWindow); + + if (event->type() == QEvent::Timer) { + if (static_cast<QTimerEvent *>(event)->timerId() == d->updateTimer.timerId()) { + d->updateTimer.stop(); + deliverUpdateRequest(); + return true; + } + } + + return false; } /*! @@ -734,18 +746,16 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w, */ void QPlatformWindow::requestUpdate() { - static int timeout = -1; - if (timeout == -1) { + Q_D(QPlatformWindow); + + static int updateInterval = []() { bool ok = false; - timeout = qEnvironmentVariableIntValue("QT_QPA_UPDATE_IDLE_TIME", &ok); - if (!ok) - timeout = 5; - } + int customUpdateInterval = qEnvironmentVariableIntValue("QT_QPA_UPDATE_IDLE_TIME", &ok); + return ok ? customUpdateInterval : 5; + }(); - QWindow *w = window(); - QWindowPrivate *wp = qt_window_private(w); - Q_ASSERT(wp->updateTimer == 0); - wp->updateTimer = w->startTimer(timeout, Qt::PreciseTimer); + Q_ASSERT(!d->updateTimer.isActive()); + d->updateTimer.start(updateInterval, Qt::PreciseTimer, window()); } /*! |