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