Move default implementation of update requests to QPlatformWindow

Change-Id: I4cbb8d2023068288e298ab21f5cd8bc258825c77
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Tor Arne Vestbø 2018-03-22 14:54:43 +01:00
parent 2d1ac61d95
commit 4d15f393a7
12 changed files with 51 additions and 47 deletions

View File

@ -1754,8 +1754,11 @@ int QGuiApplication::exec()
*/
bool QGuiApplication::notify(QObject *object, QEvent *event)
{
if (object->isWindowType())
QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(static_cast<QWindow *>(object), event);
if (object->isWindowType()) {
if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(static_cast<QWindow *>(object), event))
return true; // Platform plugin ate the event
}
return QCoreApplication::notify(object, event);
}
@ -1777,18 +1780,18 @@ bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEvent
return QCoreApplication::compressEvent(event, receiver, postedEvents);
}
void QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
bool QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
{
if (!window)
return;
return false;
QPlatformWindow *platformWindow = window->handle();
if (!platformWindow)
return;
return false;
// spontaneous events come from the platform integration already, we don't need to send the events back
if (event->spontaneous())
return;
return false;
// let the platform window do any handling it needs to as well
platformWindow->windowEvent(event);
return platformWindow->windowEvent(event);
}
bool QGuiApplicationPrivate::processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result)

View File

@ -173,7 +173,7 @@ public:
static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result);
static void sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
static inline Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
{

View File

@ -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) {
bool ok = false;
timeout = qEnvironmentVariableIntValue("QT_QPA_UPDATE_IDLE_TIME", &ok);
if (!ok)
timeout = 5;
}
Q_D(QPlatformWindow);
QWindow *w = window();
QWindowPrivate *wp = qt_window_private(w);
Q_ASSERT(wp->updateTimer == 0);
wp->updateTimer = w->startTimer(timeout, Qt::PreciseTimer);
static int updateInterval = []() {
bool ok = false;
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());
}
/*!

View File

@ -127,7 +127,7 @@ public:
virtual bool setWindowModified(bool modified);
virtual void windowEvent(QEvent *event);
virtual bool windowEvent(QEvent *event);
virtual bool startSystemResize(const QPoint &pos, Qt::Corner corner);
virtual bool startSystemMove(const QPoint &pos);

View File

@ -52,6 +52,7 @@
//
#include <QtGui/private/qtguiglobal_p.h>
#include <QtCore/qbasictimer.h>
#include <QtCore/qrect.h>
QT_BEGIN_NAMESPACE
@ -60,6 +61,7 @@ class QPlatformWindowPrivate
{
public:
QRect rect;
QBasicTimer updateTimer;
};
QT_END_NAMESPACE

View File

@ -2328,19 +2328,6 @@ bool QWindow::event(QEvent *ev)
break;
#endif
case QEvent::Timer: {
Q_D(QWindow);
if (static_cast<QTimerEvent *>(ev)->timerId() == d->updateTimer) {
killTimer(d->updateTimer);
d->updateTimer = 0;
if (d->platformWindow)
d->platformWindow->deliverUpdateRequest();
} else {
QObject::event(ev);
}
break;
}
case QEvent::PlatformSurface: {
if ((static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
#ifndef QT_NO_OPENGL

View File

@ -97,7 +97,6 @@ public:
, modality(Qt::NonModal)
, blockedByModalWindow(false)
, updateRequestPending(false)
, updateTimer(0)
, transientParent(0)
, topLevelScreen(0)
#ifndef QT_NO_CURSOR
@ -192,7 +191,6 @@ public:
bool blockedByModalWindow;
bool updateRequestPending;
int updateTimer;
QPointer<QWindow> transientParent;
QPointer<QScreen> topLevelScreen;

View File

@ -2048,7 +2048,7 @@ void QWindowsWindow::setExStyle(unsigned s) const
SetWindowLongPtr(m_data.hwnd, GWL_EXSTYLE, s);
}
void QWindowsWindow::windowEvent(QEvent *event)
bool QWindowsWindow::windowEvent(QEvent *event)
{
switch (event->type()) {
case QEvent::WindowBlocked: // Blocked by another modal window.
@ -2064,6 +2064,8 @@ void QWindowsWindow::windowEvent(QEvent *event)
default:
break;
}
return QPlatformWindow::windowEvent(event);
}
void QWindowsWindow::propagateSizeHints()

View File

@ -252,7 +252,7 @@ public:
void raise() override { raise_sys(); }
void lower() override { lower_sys(); }
void windowEvent(QEvent *event) override;
bool windowEvent(QEvent *event) override;
void propagateSizeHints() override;
static bool handleGeometryChangingMessage(MSG *message, const QWindow *qWindow, const QMargins &marginsDp);

View File

@ -2587,7 +2587,7 @@ bool QXcbWindow::setMouseGrabEnabled(bool grab)
return result;
}
void QXcbWindow::windowEvent(QEvent *event)
bool QXcbWindow::windowEvent(QEvent *event)
{
switch (event->type()) {
case QEvent::FocusIn:
@ -2613,7 +2613,7 @@ void QXcbWindow::windowEvent(QEvent *event)
default:
break;
}
QPlatformWindow::windowEvent(event);
return QPlatformWindow::windowEvent(event);
}
bool QXcbWindow::startSystemResize(const QPoint &pos, Qt::Corner corner)

View File

@ -105,7 +105,7 @@ public:
QSurfaceFormat format() const override;
void windowEvent(QEvent *event) override;
bool windowEvent(QEvent *event) override;
bool startSystemResize(const QPoint &pos, Qt::Corner corner) override;
bool startSystemMove(const QPoint &pos) override;

View File

@ -2952,8 +2952,10 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
d->checkReceiverThread(receiver);
#endif
if (receiver->isWindowType())
QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(static_cast<QWindow *>(receiver), e);
if (receiver->isWindowType()) {
if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(static_cast<QWindow *>(receiver), e))
return true; // Platform plugin ate the event
}
if(e->spontaneous()) {
// Capture the current mouse and keyboard states. Doing so here is