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
qwaylandqtsurface.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <qpa/qwindowsysteminterface.h>
6#include <qpa/qplatformwindow.h>
7
9
10namespace QtWaylandClient {
11
12QWaylandQtSurface::QWaylandQtSurface(struct ::zqt_shell_surface_v1 *shell_surface, QWaylandWindow *window)
14 , QtWayland::zqt_shell_surface_v1(shell_surface)
15{
16 sendSizeHints();
17}
18
20{
21 zqt_shell_surface_v1::destroy();
22}
23
24void QWaylandQtSurface::resetConfiguration()
25{
26 m_pendingPosition = QPoint(-1, -1);
27 m_pendingSize = QSize();
28 m_pendingPositionValid = false;
29 m_pendingStates = m_currentStates;
30}
31
33{
34 if (m_pendingSize.isValid() && m_pendingPositionValid)
35 setGeometryFromApplyConfigure(m_pendingPosition, m_pendingSize);
36 else if (m_pendingSize.isValid())
37 resizeFromApplyConfigure(m_pendingSize);
38 else if (m_pendingPositionValid)
39 repositionFromApplyConfigure(m_pendingPosition);
40
41 if (m_pendingStates != m_currentStates) {
43 m_currentStates = m_pendingStates;
44 }
45
46 ack_configure(m_currentConfigureSerial);
47
48 resetConfiguration();
49 m_currentConfigureSerial = UINT32_MAX;
50}
51
53{
54 set_window_title(title);
55}
56
58{
59 m_capabilities = capabilities;
60}
61
62void QWaylandQtSurface::zqt_shell_surface_v1_set_position(uint32_t serial, int32_t x, int32_t y)
63{
64 if (serial < m_currentConfigureSerial && m_currentConfigureSerial != UINT32_MAX)
65 return;
66
67 if (serial != m_currentConfigureSerial) {
68 m_currentConfigureSerial = serial;
69 resetConfiguration();
70 }
71
72 m_pendingPosition = QPoint(x, y);
73 m_pendingPositionValid = true;
74}
75
76void QWaylandQtSurface::zqt_shell_surface_v1_resize(uint32_t serial, int32_t width, int32_t height)
77{
78 if (serial < m_currentConfigureSerial && m_currentConfigureSerial != UINT32_MAX)
79 return;
80
81 if (serial != m_currentConfigureSerial) {
82 m_currentConfigureSerial = serial;
83 resetConfiguration();
84 }
85
86 m_pendingSize = QSize(width, height);
87}
88
90{
91 if (serial < m_currentConfigureSerial)
92 return;
93
94 if (serial > m_currentConfigureSerial) {
95 m_currentConfigureSerial = serial;
96 resetConfiguration();
97 }
98
100}
101
106
108 uint32_t top, uint32_t bottom)
109{
111 m_frameMargins = QMargins(left, top, right, bottom);
112 m_pendingPosition = win->geometry().topLeft();
113 m_pendingPositionValid = true;
114 m_pendingSize = win->geometry().size();
116}
117
119{
120 request_activate();
121 return true;
122}
123
125{
126 sendSizeHints();
127}
128
129void QWaylandQtSurface::sendSizeHints()
130{
132 if (win) {
133 const int minWidth = qMax(0, win->windowMinimumSize().width());
134 const int minHeight = qMax(0, win->windowMinimumSize().height());
135 set_minimum_size(minWidth, minHeight);
136
137 int maxWidth = qMax(0, win->windowMaximumSize().width());
138 if (maxWidth == QWINDOWSIZE_MAX)
139 maxWidth = -1;
140 int maxHeight = qMax(0, win->windowMaximumSize().height());
141 if (maxHeight == QWINDOWSIZE_MAX)
142 maxHeight = -1;
143 set_maximum_size(maxWidth, maxHeight);
144 }
145}
146
148{
149 if (serial < m_currentConfigureSerial && m_currentConfigureSerial != UINT32_MAX)
150 return;
151
152 if (serial != m_currentConfigureSerial) {
153 m_currentConfigureSerial = serial;
154 resetConfiguration();
155 }
156 m_pendingStates = Qt::WindowStates(state);
157}
158
160{
161 set_size(rect.width(), rect.height());
162}
163
165{
166 reposition(position.x(), position.y());
167}
168
170{
171 set_window_flags(flags);
172}
173
175{
176 change_window_state(states & ~Qt::WindowActive);
177}
178
179bool QWaylandQtSurface::resize(QWaylandInputDevice *inputDevice, Qt::Edges edge)
180{
181 if (m_capabilities & ZQT_SHELL_SURFACE_V1_CAPABILITIES_INTERACTIVE_RESIZE) {
182 start_system_resize(getSerial(inputDevice), uint(edge));
183 return true;
184 }
185
186 return false;
187}
188
190{
191 if (m_capabilities & ZQT_SHELL_SURFACE_V1_CAPABILITIES_INTERACTIVE_RESIZE) {
192 start_system_move(getSerial(inputDevice));
193 return true;
194 }
195
196 return false;
197}
198
200{
201 return m_frameMargins;
202}
203
205{
206 QtWayland::zqt_shell_surface_v1::raise();
207}
208
210{
211 QtWayland::zqt_shell_surface_v1::lower();
212}
213
214}
215
\inmodule QtCore
Definition qmargins.h:24
The QPlatformWindow class provides an abstraction for top-level windows.
QWindow * window() const
Returns the window which belongs to the QPlatformWindow.
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
\inmodule QtCore
Definition qsize.h:25
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
Definition qsize.h:127
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition qwidget.h:106
int width
the width of the widget excluding any window frame
Definition qwidget.h:114
int height
the height of the widget excluding any window frame
Definition qwidget.h:115
static void handleWindowStateChanged(QWindow *window, Qt::WindowStates newState, int oldState=-1)
bool close()
Close the window.
Definition qwindow.cpp:2354
void requestWindowStates(Qt::WindowStates states) override
QWaylandQtSurface(struct ::zqt_shell_surface_v1 *shell_surface, QWaylandWindow *window)
void setTitle(const QString &title) override
void zqt_shell_surface_v1_set_capabilities(uint32_t capabilities) override
bool resize(QWaylandInputDevice *, Qt::Edges) override
void zqt_shell_surface_v1_configure(uint32_t serial) override
bool move(QWaylandInputDevice *) override
void setWindowGeometry(const QRect &rect) override
void setWindowPosition(const QPoint &position) override
void zqt_shell_surface_v1_resize(uint32_t serial, int32_t width, int32_t height) override
void zqt_shell_surface_v1_set_position(uint32_t serial, int32_t x, int32_t y) override
void setWindowFlags(Qt::WindowFlags flags) override
QMargins serverSideFrameMargins() const override
void zqt_shell_surface_v1_set_window_state(uint32_t serial, uint32_t state) override
void zqt_shell_surface_v1_set_frame_margins(uint32_t left, uint32_t right, uint32_t top, uint32_t bottom) override
void resizeFromApplyConfigure(const QSize &sizeWithMargins, const QPoint &offset={0, 0})
void repositionFromApplyConfigure(const QPoint &position)
static uint32_t getSerial(QWaylandInputDevice *inputDevice)
void setGeometryFromApplyConfigure(const QPoint &globalPosition, const QSize &sizeWithMargins)
rect
[4]
else opt state
[0]
Combined button and popup list for selecting options.
@ WindowActive
Definition qnamespace.h:256
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLint GLsizei width
GLint left
GLint GLint bottom
GLbitfield flags
GLint y
GLuint * states
#define QWINDOWSIZE_MAX
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
unsigned int uint
Definition qtypes.h:34
QWidget * win
Definition settings.cpp:6
QString title
[35]
aWidget window() -> setWindowTitle("New Window Title")
[2]