Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qwaylandquickoutput.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
2
// Copyright (C) 2017 The Qt Company Ltd.
3
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4
// Qt-Security score:significant reason:default
5
6
#
include
"qwaylandquickoutput.h"
7
#
include
"qwaylandquickcompositor.h"
8
#
include
"qwaylandquickitem_p.h"
9
10
QT_BEGIN_NAMESPACE
11
12
QWaylandQuickOutput::QWaylandQuickOutput()
13
{
14
}
15
16
QWaylandQuickOutput::QWaylandQuickOutput(QWaylandCompositor *compositor, QWindow *window)
17
: QWaylandOutput(compositor, window)
18
{
19
}
20
21
void
QWaylandQuickOutput::initialize()
22
{
23
QWindow *win = window();
24
if
(win !=
nullptr
) {
25
QWaylandOutputMode mode(win->size() * win->devicePixelRatio(),
26
qFloor(win->screen()->refreshRate() * 1000));
27
if
(mode.isValid()) {
28
addMode(mode,
true
);
29
setCurrentMode(mode);
30
}
31
}
32
33
QWaylandOutput::initialize();
34
35
QQuickWindow *quickWindow = qobject_cast<QQuickWindow *>(win);
36
if
(!quickWindow) {
37
qWarning(
"Initialization error: Could not locate QQuickWindow on initializing QWaylandQuickOutput %p.\n"
,
this
);
38
return
;
39
}
40
connect(quickWindow, &QQuickWindow::beforeSynchronizing,
41
this
, &QWaylandQuickOutput::updateStarted,
42
Qt::DirectConnection);
43
44
connect(quickWindow, &QQuickWindow::afterRendering,
45
this
, &QWaylandQuickOutput::doFrameCallbacks);
46
}
47
48
void
QWaylandQuickOutput::classBegin()
49
{
50
}
51
52
void
QWaylandQuickOutput::componentComplete()
53
{
54
if
(!compositor()) {
55
for
(QObject *p = parent(); p !=
nullptr
; p = p->parent()) {
56
if
(
auto
c = qobject_cast<QWaylandCompositor *>(p)) {
57
setCompositor(c);
58
break
;
59
}
60
}
61
}
62
}
63
64
void
QWaylandQuickOutput::update()
65
{
66
if
(!m_updateScheduled) {
67
//don't qobject_cast since we have verified the type in initialize
68
static_cast
<QQuickWindow *>(window())->update();
69
m_updateScheduled =
true
;
70
}
71
}
72
73
/*!
74
* \qmlproperty bool QtWayland.Compositor::WaylandOutput::automaticFrameCallback
75
* \default true
76
*
77
* This property holds whether the WaylandOutput automatically sends frame
78
* callbacks when rendering.
79
*/
80
81
/*!
82
* \property QWaylandQuickOutput::automaticFrameCallback
83
*
84
* This property holds whether the QWaylandQuickOutput automatically sends frame
85
* callbacks when rendering.
86
*
87
* When \c true, frame callbacks are sent automatically after each frame is
88
* rendered; when \c false, frame callbacks must be sent manually.
89
*
90
* The default is \c true.
91
*/
92
bool
QWaylandQuickOutput::automaticFrameCallback()
const
93
{
94
return
m_automaticFrameCallback;
95
}
96
97
void
QWaylandQuickOutput::setAutomaticFrameCallback(
bool
automatic)
98
{
99
if
(m_automaticFrameCallback == automatic)
100
return
;
101
102
m_automaticFrameCallback = automatic;
103
automaticFrameCallbackChanged();
104
}
105
106
static
QQuickItem
*
clickableItemAtPosition
(QQuickItem *rootItem,
const
QPointF &position)
107
{
108
if
(!rootItem->isEnabled() || !rootItem->isVisible())
109
return
nullptr
;
110
111
QList<QQuickItem *> paintOrderItems = QQuickItemPrivate::get(rootItem)->paintOrderChildItems();
112
auto
negativeZStart = paintOrderItems.crend();
113
for
(
auto
it = paintOrderItems.crbegin(); it != paintOrderItems.crend(); ++it) {
114
if
((*it)->z() < 0) {
115
negativeZStart = it;
116
break
;
117
}
118
QQuickItem *item = clickableItemAtPosition(*it, rootItem->mapToItem(*it, position));
119
if
(item)
120
return
item;
121
}
122
123
if
(rootItem->contains(position) && rootItem->acceptedMouseButtons() != Qt::NoButton)
124
return
rootItem;
125
126
for
(
auto
it = negativeZStart; it != paintOrderItems.crend(); ++it) {
127
QQuickItem *item = clickableItemAtPosition(*it, rootItem->mapToItem(*it, position));
128
if
(item)
129
return
item;
130
}
131
132
return
nullptr
;
133
}
134
135
QQuickItem *QWaylandQuickOutput::pickClickableItem(
const
QPointF &position)
136
{
137
QQuickWindow *quickWindow = qobject_cast<QQuickWindow *>(window());
138
if
(!quickWindow)
139
return
nullptr
;
140
141
return
clickableItemAtPosition(quickWindow->contentItem(), position);
142
}
143
144
/*!
145
* \internal
146
*/
147
void
QWaylandQuickOutput::updateStarted()
148
{
149
m_updateScheduled =
false
;
150
151
if
(!compositor())
152
return
;
153
154
frameStarted();
155
}
156
157
void
QWaylandQuickOutput::doFrameCallbacks()
158
{
159
if
(m_automaticFrameCallback)
160
sendFrameCallbacks();
161
}
162
QT_END_NAMESPACE
163
164
#
include
"moc_qwaylandquickoutput.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
clickableItemAtPosition
static QQuickItem * clickableItemAtPosition(QQuickItem *rootItem, const QPointF &position)
Definition
qwaylandquickoutput.cpp:106
qtwayland
src
compositor
compositor_api
qwaylandquickoutput.cpp
Generated on
for Qt by
1.18.0