Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwaylandabstractdecoration.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 Robin Burchell <robin.burchell@viroteck.net>
2// Copyright (C) 2016 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
6
7#include <private/qobject_p.h>
8#include "qwaylandwindow_p.h"
11#include "qwaylandscreen_p.h"
12
13#include <QtGui/QImage>
14
16
17namespace QtWaylandClient {
18
35
40
44
49
53
54// we do this as a setter to get around plugin factory creates not really
55// being a great way to pass arguments
57{
59
60 // double initialization is probably not great
61 Q_ASSERT(!d->m_window && !d->m_wayland_window);
62
63 d->m_window = window->window();
64 d->m_wayland_window = window;
65}
66
67// Creates regions like this on the outside of a rectangle with inner size \a size
68// -----
69// | |
70// -----
71// I.e. the top and bottom extends into the corners
72static QRegion marginsRegion(const QSize &size, const QMargins &margins)
73{
74 QRegion r;
75
76 r += QRect(0, 0, size.width(), margins.top()); // top
77 r += QRect(0, size.height()-margins.bottom(), size.width(), margins.bottom()); //bottom
78 r += QRect(0, margins.top(), margins.left(), size.height()); //left
79 r += QRect(size.width()-margins.left(), margins.top(), margins.right(), size.height()-margins.top()); // right
80 return r;
81}
82
84{
86 if (d->m_isDirty) {
87 // Update the decoration backingstore
88
89 const qreal bufferScale = waylandWindow()->scale();
90 const QSize imageSize = waylandWindow()->surfaceSize() * bufferScale;
91 d->m_decorationContentImage = QImage(imageSize, QImage::Format_ARGB32_Premultiplied);
92 // Only scale by buffer scale, not QT_SCALE_FACTOR etc.
93 d->m_decorationContentImage.setDevicePixelRatio(bufferScale);
94 d->m_decorationContentImage.fill(Qt::transparent);
95 this->paint(&d->m_decorationContentImage);
96
97 QRegion damage = marginsRegion(waylandWindow()->surfaceSize(), waylandWindow()->frameMargins());
98 for (QRect r : damage)
100
101 d->m_isDirty = false;
102 }
103
104 return d->m_decorationContentImage;
105}
106
108{
110 d->m_isDirty = true;
111}
112
114{
116 d->m_mouseButtons = mb;
117}
118
119void QWaylandAbstractDecoration::startResize(QWaylandInputDevice *inputDevice, Qt::Edges edges, Qt::MouseButtons buttons)
120{
122 if (isLeftClicked(buttons) && d->m_wayland_window->shellSurface()) {
123 d->m_wayland_window->shellSurface()->resize(inputDevice, edges);
124 inputDevice->removeMouseButtonFromState(Qt::LeftButton);
125 }
126}
127
128void QWaylandAbstractDecoration::startMove(QWaylandInputDevice *inputDevice, Qt::MouseButtons buttons)
129{
131 if (isLeftClicked(buttons) && d->m_wayland_window->shellSurface()) {
132 d->m_wayland_window->shellSurface()->move(inputDevice);
133 inputDevice->removeMouseButtonFromState(Qt::LeftButton);
134 }
135}
136
138{
140 if (auto *s = d->m_wayland_window->shellSurface())
141 s->showWindowMenu(inputDevice);
142}
143
144bool QWaylandAbstractDecoration::isLeftClicked(Qt::MouseButtons newMouseButtonState)
145{
147 return !(d->m_mouseButtons & Qt::LeftButton) && (newMouseButtonState & Qt::LeftButton);
148}
149
150bool QWaylandAbstractDecoration::isRightClicked(Qt::MouseButtons newMouseButtonState)
151{
153 return !(d->m_mouseButtons & Qt::RightButton) && (newMouseButtonState & Qt::RightButton);
154}
155
156bool QWaylandAbstractDecoration::isLeftReleased(Qt::MouseButtons newMouseButtonState)
157{
159 return (d->m_mouseButtons & Qt::LeftButton) && !(newMouseButtonState & Qt::LeftButton);
160}
161
163{
165 return d->m_isDirty;
166}
167
169{
171 return d->m_window;
172}
173
175{
177 return d->m_wayland_window;
178}
179
180}
181
183
184#include "moc_qwaylandabstractdecoration_p.cpp"
\inmodule QtGui
Definition qimage.h:37
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
\inmodule QtCore
Definition qmargins.h:24
constexpr int bottom() const noexcept
Returns the bottom margin.
Definition qmargins.h:115
constexpr int left() const noexcept
Returns the left margin.
Definition qmargins.h:106
constexpr int right() const noexcept
Returns the right margin.
Definition qmargins.h:112
constexpr int top() const noexcept
Returns the top margin.
Definition qmargins.h:109
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore
Definition qsize.h:25
\inmodule QtGui
Definition qwindow.h:63
bool isRightClicked(Qt::MouseButtons newMouseButtonState)
void startResize(QWaylandInputDevice *inputDevice, Qt::Edges edges, Qt::MouseButtons buttons)
bool isLeftClicked(Qt::MouseButtons newMouseButtonState)
void showWindowMenu(QWaylandInputDevice *inputDevice)
bool isLeftReleased(Qt::MouseButtons newMouseButtonState)
void startMove(QWaylandInputDevice *inputDevice, Qt::MouseButtons buttons)
QSize surfaceSize() const
Size, with decorations (including including eventual shadows) in wl_surface coordinates.
void damage(const QRect &rect)
QPainter paint
Combined button and popup list for selecting options.
static QRegion marginsRegion(const QSize &size, const QMargins &margins)
@ LeftButton
Definition qnamespace.h:58
@ RightButton
Definition qnamespace.h:59
@ NoButton
Definition qnamespace.h:57
@ transparent
Definition qnamespace.h:47
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei imageSize
GLdouble s
[6]
Definition qopenglext.h:235
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
double qreal
Definition qtypes.h:187
QObject::connect nullptr
aWidget window() -> setWindowTitle("New Window Title")
[2]