diff options
Diffstat (limited to 'src/gui/kernel/qplatformwindow.cpp')
-rw-r--r-- | src/gui/kernel/qplatformwindow.cpp | 84 |
1 files changed, 68 insertions, 16 deletions
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index a66420c364..50f05721f7 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -140,7 +140,7 @@ void QPlatformWindow::setGeometry(const QRect &rect) } /*! - Returnes the current geometry of a window + Returns the current geometry of a window */ QRect QPlatformWindow::geometry() const { @@ -340,6 +340,20 @@ void QPlatformWindow::setWindowFilePath(const QString &filePath) { Q_UNUSED(file void QPlatformWindow::setWindowIcon(const QIcon &icon) { Q_UNUSED(icon); } /*! + Reimplement to let the platform handle non-spontaneous window close. + + When reimplementing make sure to call the base class implementation + or QWindowSystemInterface::handleCloseEvent(), which will prompt the + user to accept the window close (if needed) and then close the QWindow. +*/ +bool QPlatformWindow::close() +{ + bool accepted = false; + QWindowSystemInterface::handleCloseEvent<QWindowSystemInterface::SynchronousDelivery>(window(), &accepted); + return accepted; +} + +/*! Reimplement to be able to let Qt raise windows to the top of the desktop */ void QPlatformWindow::raise() { qWarning("This plugin does not support raise()"); } @@ -447,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; } /*! @@ -710,7 +736,7 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w, QPlatformWindow subclasses can re-implement this function to provide display refresh synchronized updates. The event - should be delivered using QWindowPrivate::deliverUpdateRequest() + should be delivered using QPlatformWindow::deliverUpdateRequest() to not get out of sync with the the internal state of QWindow. The default implementation posts an UpdateRequest event to the @@ -720,18 +746,44 @@ 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; + }(); + + Q_ASSERT(!d->updateTimer.isActive()); + d->updateTimer.start(updateInterval, Qt::PreciseTimer, window()); +} + +/*! + Returns true if the window has a pending update request. + + \sa requestUpdate(), deliverUpdateRequest() +*/ +bool QPlatformWindow::hasPendingUpdateRequest() const +{ + return qt_window_private(window())->updateRequestPending; +} + +/*! + Delivers an QEvent::UpdateRequest event to the window. + + QPlatformWindow subclasses can re-implement this function to + provide e.g. logging or tracing of the delivery, but should + always call the base class function. +*/ +void QPlatformWindow::deliverUpdateRequest() +{ + Q_ASSERT(hasPendingUpdateRequest()); QWindow *w = window(); - QWindowPrivate *wp = (QWindowPrivate *) QObjectPrivate::get(w); - Q_ASSERT(wp->updateTimer == 0); - wp->updateTimer = w->startTimer(timeout, Qt::PreciseTimer); + QWindowPrivate *wp = qt_window_private(w); + wp->updateRequestPending = false; + QEvent request(QEvent::UpdateRequest); + QCoreApplication::sendEvent(w, &request); } /*! |