Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwaylandwlshellsurface.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 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
// Qt-Security score:significant reason:default
4
5
#
include
"qwaylandwlshellsurface_p.h"
6
7
#
include
<
QtWaylandClient
/
private
/
qwaylanddisplay_p
.
h
>
8
#
include
<
QtWaylandClient
/
private
/
qwaylandwindow_p
.
h
>
9
#
include
<
QtWaylandClient
/
private
/
qwaylandinputdevice_p
.
h
>
10
#
include
<
QtWaylandClient
/
private
/
qwaylandabstractdecoration_p
.
h
>
11
#
include
<
QtWaylandClient
/
private
/
qwaylandscreen_p
.
h
>
12
13
#
include
<
QtCore
/
QDebug
>
14
15
QT_BEGIN_NAMESPACE
16
17
namespace
QtWaylandClient
{
18
19
QWaylandWlShellSurface
::
QWaylandWlShellSurface
(
struct
::wl_shell_surface *
shell_surface
,
QWaylandWindow
*
window
)
20
:
QWaylandShellSurface
(
window
)
21
,
QtWayland
::
wl_shell_surface
(
shell_surface
)
22
,
m_window
(
window
)
23
{
24
Qt
::
WindowType
type
=
window
->
window
()->
type
();
25
auto
*
transientParent
=
window
->
transientParent
();
26
if
(
type
==
Qt
::
Popup
&&
transientParent
&&
transientParent
->
wlSurface
())
27
setPopup
(
transientParent
,
m_window
->
display
()->
lastInputDevice
(),
m_window
->
display
()->
lastInputSerial
());
28
else
if
(
transientParent
&&
transientParent
->
wlSurface
())
29
updateTransientParent
(
transientParent
->
window
());
30
else
31
setTopLevel
();
32
}
33
34
QWaylandWlShellSurface
::~
QWaylandWlShellSurface
()
35
{
36
wl_shell_surface_destroy
(
object
());
37
}
38
39
bool
QWaylandWlShellSurface
::
resize
(
QWaylandInputDevice
*
inputDevice
,
Qt
::
Edges
edges
)
40
{
41
enum
resize
resizeEdges
=
convertToResizeEdges
(
edges
);
42
resize
(
inputDevice
->
wl_seat
(),
inputDevice
->
serial
(),
resizeEdges
);
43
return
true
;
44
}
45
46
bool
QWaylandWlShellSurface
::
move
(
QWaylandInputDevice
*
inputDevice
)
47
{
48
move
(
inputDevice
->
wl_seat
(),
49
inputDevice
->
serial
());
50
return
true
;
51
}
52
53
void
QWaylandWlShellSurface
::
setTitle
(
const
QString
&
title
)
54
{
55
return
QtWayland
::
wl_shell_surface
::
set_title
(
title
);
56
}
57
58
void
QWaylandWlShellSurface
::
setAppId
(
const
QString
&
appId
)
59
{
60
return
QtWayland
::
wl_shell_surface
::
set_class
(
appId
);
61
}
62
63
void
QWaylandWlShellSurface
::
applyConfigure
()
64
{
65
if
((
m_pending
.
states
& (
Qt
::
WindowMaximized
|
Qt
::
WindowFullScreen
))
66
&& !(
m_applied
.
states
& (
Qt
::
WindowMaximized
|
Qt
::
WindowFullScreen
))) {
67
m_normalSize
=
m_window
->
windowFrameGeometry
().
size
();
68
}
69
70
if
(
m_pending
.
states
!=
m_applied
.
states
)
71
m_window
->
handleWindowStatesChanged
(
m_pending
.
states
);
72
73
if
(!
m_pending
.
size
.
isEmpty
()) {
74
int
x
= 0;
75
int
y
= 0;
76
if
(
m_pending
.
edges
&
resize_left
)
77
x
=
m_applied
.
size
.
width
() -
m_pending
.
size
.
width
();
78
if
(
m_pending
.
edges
&
resize_top
)
79
y
=
m_applied
.
size
.
height
() -
m_pending
.
size
.
height
();
80
QPoint
offset
(
x
,
y
);
81
m_window
->
resizeFromApplyConfigure
(
m_pending
.
size
,
offset
);
82
}
else
if
(
m_pending
.
size
.
isValid
() && !
m_normalSize
.
isEmpty
()) {
83
m_window
->
resizeFromApplyConfigure
(
m_normalSize
);
84
}
85
86
m_applied
=
m_pending
;
87
}
88
89
bool
QWaylandWlShellSurface
::
wantsDecorations
()
const
90
{
91
return
!(
m_pending
.
states
&
Qt
::
WindowFullScreen
);
92
}
93
94
void
QWaylandWlShellSurface
::
requestWindowStates
(
Qt
::
WindowStates
states
)
95
{
96
// On wl-shell the client is in charge of states, so diff from the pending state
97
Qt
::
WindowStates
changedStates
=
m_pending
.
states
^
states
;
98
Qt
::
WindowStates
addedStates
=
changedStates
&
states
;
99
100
if
(
addedStates
&
Qt
::
WindowMinimized
)
101
qCWarning
(
lcQpaWayland
) <<
"Minimizing is not supported on wl-shell. Consider using xdg-shell instead."
;
102
103
if
(
addedStates
&
Qt
::
WindowMaximized
) {
104
set_maximized
(
nullptr
);
105
m_window
->
applyConfigureWhenPossible
();
106
}
107
108
if
(
addedStates
&
Qt
::
WindowFullScreen
) {
109
set_fullscreen
(
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT
, 0,
nullptr
);
110
m_window
->
applyConfigureWhenPossible
();
111
}
112
113
bool
isNormal
= !(
states
&
Qt
::
WindowMaximized
) && !(
states
&
Qt
::
WindowFullScreen
);
114
if
(
isNormal
&& (
changedStates
& (
Qt
::
WindowMaximized
|
Qt
::
WindowFullScreen
))) {
115
setTopLevel
();
// set normal window
116
// There's usually no configure event after this, so just clear the rest of the pending
117
// configure here and queue the applyConfigure call
118
m_pending
.
size
= {0, 0};
119
m_pending
.
edges
=
resize_none
;
120
m_window
->
applyConfigureWhenPossible
();
121
}
122
123
m_pending
.
states
=
states
& ~
Qt
::
WindowMinimized
;
124
}
125
126
enum
QWaylandWlShellSurface::
resize
QWaylandWlShellSurface
::
convertToResizeEdges
(
Qt
::
Edges
edges
)
127
{
128
return
static_cast
<
enum
resize
>(
129
((
edges
&
Qt
::
TopEdge
) ?
resize_top
: 0)
130
| ((
edges
&
Qt
::
BottomEdge
) ?
resize_bottom
: 0)
131
| ((
edges
&
Qt
::
LeftEdge
) ?
resize_left
: 0)
132
| ((
edges
&
Qt
::
RightEdge
) ?
resize_right
: 0));
133
}
134
135
void
QWaylandWlShellSurface
::
setTopLevel
()
136
{
137
set_toplevel
();
138
}
139
140
static
inline
bool
testShowWithoutActivating
(
const
QWindow *window)
141
{
142
// QWidget-attribute Qt::WA_ShowWithoutActivating.
143
const
QVariant showWithoutActivating = window->property(
"_q_showWithoutActivating"
);
144
return
showWithoutActivating.isValid() && showWithoutActivating.toBool();
145
}
146
147
void
QWaylandWlShellSurface
::
updateTransientParent
(
QWindow
*
parent
)
148
{
149
QWaylandWindow
*
parent_wayland_window
=
static_cast
<
QWaylandWindow
*>(
parent
->
handle
());
150
if
(!
parent_wayland_window
)
151
return
;
152
153
// set_transient expects a position relative to the parent
154
QPoint
transientPos
=
m_window
->
geometry
().
topLeft
();
// this is absolute
155
transientPos
-=
parent
->
geometry
().
topLeft
();
156
if
(
parent_wayland_window
->
decoration
()) {
157
transientPos
.
setX
(
transientPos
.
x
() +
parent_wayland_window
->
decoration
()->
margins
().
left
());
158
transientPos
.
setY
(
transientPos
.
y
() +
parent_wayland_window
->
decoration
()->
margins
().
top
());
159
}
160
161
uint32_t
flags
= 0;
162
Qt
::
WindowFlags
wf
=
m_window
->
window
()->
flags
();
163
if
(
wf
.
testFlag
(
Qt
::
ToolTip
)
164
||
wf
.
testFlag
(
Qt
::
WindowTransparentForInput
)
165
||
testShowWithoutActivating
(
m_window
->
window
()))
166
flags
|=
WL_SHELL_SURFACE_TRANSIENT_INACTIVE
;
167
168
auto
*
parentSurface
=
parent_wayland_window
->
wlSurface
();
169
Q_ASSERT
(
parentSurface
);
170
set_transient
(
parentSurface
,
transientPos
.
x
(),
transientPos
.
y
(),
flags
);
171
}
172
173
void
QWaylandWlShellSurface
::
setPopup
(
QWaylandWindow
*
parent
,
QWaylandInputDevice
*
device
,
uint
serial
)
174
{
175
QWaylandWindow
*
parent_wayland_window
=
parent
;
176
if
(!
parent_wayland_window
) {
177
qCWarning
(
lcQpaWayland
) <<
"setPopup called without a parent window"
;
178
return
;
179
}
180
if
(!
device
) {
181
qCWarning
(
lcQpaWayland
) <<
"setPopup called without an input device"
;
182
return
;
183
}
184
185
// set_popup expects a position relative to the parent
186
QPoint
transientPos
=
m_window
->
geometry
().
topLeft
();
// this is absolute
187
transientPos
-=
parent_wayland_window
->
geometry
().
topLeft
();
188
if
(
parent_wayland_window
->
decoration
()) {
189
transientPos
.
setX
(
transientPos
.
x
() +
parent_wayland_window
->
decoration
()->
margins
().
left
());
190
transientPos
.
setY
(
transientPos
.
y
() +
parent_wayland_window
->
decoration
()->
margins
().
top
());
191
}
192
193
auto
*
parentSurface
=
parent_wayland_window
->
wlSurface
();
194
Q_ASSERT
(
parentSurface
);
195
uint
flags
= 0;
196
set_popup
(
device
->
wl_seat
(),
serial
,
parentSurface
,
transientPos
.
x
(),
transientPos
.
y
(),
flags
);
197
}
198
199
void
QWaylandWlShellSurface
::
shell_surface_ping
(
uint32_t
serial
)
200
{
201
pong
(
serial
);
202
}
203
204
void
QWaylandWlShellSurface
::
shell_surface_configure
(
uint32_t
edges
,
int32_t
width
,
int32_t
height
)
205
{
206
m_pending
.
size
=
QSize
(
width
,
height
);
207
m_pending
.
edges
=
static_cast
<
enum
resize
>(
edges
);
208
if
(
m_pending
.
edges
&& !
m_pending
.
size
.
isEmpty
())
209
m_normalSize
=
m_pending
.
size
;
210
m_window
->
applyConfigureWhenPossible
();
211
}
212
213
void
QWaylandWlShellSurface
::
shell_surface_popup_done
()
214
{
215
QCoreApplication
::
postEvent
(
m_window
->
window
(),
new
QCloseEvent
());
216
}
217
218
}
219
220
QT_END_NAMESPACE
221
222
#
include
"moc_qwaylandwlshellsurface_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qrandomaccessasyncfile_darwin.mm:17
QtWaylandClient
Definition
qwaylandclientextension.h:16
QtWaylandClient::testShowWithoutActivating
static bool testShowWithoutActivating(const QWindow *window)
Definition
qwaylandwlshellsurface.cpp:140
qtbase
src
plugins
platforms
wayland
plugins
shellintegration
wl-shell
qwaylandwlshellsurface.cpp
Generated on
for Qt by
1.16.1