Client: Fix regression; drawing decorations of active windows as inactive

We can't trust QWindow::isActive, because it relies on focusWindow, which may
be updated too late, and there might also be multiple active toplevel windows
at once on Wayland. Even though Qt doesn't support multiple seats, we should
still draw the decorations of active windows correctly.

This implements QPlatformWindow::isActive and uses it in the decorations.

Change-Id: I34d79b354e2d26694533e2319a26f24085212243
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
This commit is contained in:
Johan Klokkhammer Helsing 2018-08-27 09:25:50 +02:00 committed by Johan Helsing
parent 326ab57d25
commit f746be7c7f
5 changed files with 15 additions and 2 deletions

View File

@ -132,6 +132,7 @@ QMargins QWaylandBradientDecoration::margins() const
void QWaylandBradientDecoration::paint(QPaintDevice *device)
{
bool active = window()->handle()->isActive();
QRect surfaceRect(QPoint(), window()->frameGeometry().size());
QRect clips[] =
{
@ -183,7 +184,7 @@ void QWaylandBradientDecoration::paint(QPaintDevice *device)
p.save();
p.setClipRect(titleBar);
p.setPen(window()->isActive() ? m_foregroundColor : m_foregroundInactiveColor);
p.setPen(active ? m_foregroundColor : m_foregroundInactiveColor);
QSizeF size = m_windowTitle.size();
int dx = (top.width() - size.width()) /2;
int dy = (top.height()- size.height()) /2;
@ -199,7 +200,7 @@ void QWaylandBradientDecoration::paint(QPaintDevice *device)
QRectF rect;
// Default pen
QPen pen(window()->isActive() ? m_foregroundColor : m_foregroundInactiveColor);
QPen pen(active ? m_foregroundColor : m_foregroundInactiveColor);
p.setPen(pen);
// Close button

View File

@ -413,6 +413,11 @@ void QWaylandDisplay::setLastInputDevice(QWaylandInputDevice *device, uint32_t s
mLastInputWindow = win;
}
bool QWaylandDisplay::isWindowActivated(const QWaylandWindow *window)
{
return mActiveWindows.contains(const_cast<QWaylandWindow *>(window));
}
void QWaylandDisplay::handleWindowActivated(QWaylandWindow *window)
{
if (mActiveWindows.contains(window))

View File

@ -176,6 +176,7 @@ public:
QWaylandWindow *lastInputWindow() const;
void setLastInputDevice(QWaylandInputDevice *device, uint32_t serial, QWaylandWindow *window);
bool isWindowActivated(const QWaylandWindow *window);
void handleWindowActivated(QWaylandWindow *window);
void handleWindowDeactivated(QWaylandWindow *window);
void handleKeyboardFocusChanged(QWaylandInputDevice *inputDevice);

View File

@ -943,6 +943,11 @@ bool QWaylandWindow::isExposed() const
return QPlatformWindow::isExposed();
}
bool QWaylandWindow::isActive() const
{
return mDisplay->isWindowActivated(this);
}
int QWaylandWindow::scale() const
{
return mScale;

View File

@ -146,6 +146,7 @@ public:
void requestActivateWindow() override;
bool isExposed() const override;
bool isActive() const override;
void unfocus();
QWaylandAbstractDecoration *decoration() const;