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
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
8
10
11QWaylandQuickOutput::QWaylandQuickOutput()
12{
13}
14
15QWaylandQuickOutput::QWaylandQuickOutput(QWaylandCompositor *compositor, QWindow *window)
16 : QWaylandOutput(compositor, window)
17{
18}
19
20void QWaylandQuickOutput::initialize()
21{
22 QWindow *win = window();
23 if (win != nullptr) {
24 QWaylandOutputMode mode(win->size() * win->devicePixelRatio(),
25 qFloor(win->screen()->refreshRate() * 1000));
26 if (mode.isValid()) {
27 addMode(mode, true);
28 setCurrentMode(mode);
29 }
30 }
31
32 QWaylandOutput::initialize();
33
34 QQuickWindow *quickWindow = qobject_cast<QQuickWindow *>(win);
35 if (!quickWindow) {
36 qWarning("Initialization error: Could not locate QQuickWindow on initializing QWaylandQuickOutput %p.\n", this);
37 return;
38 }
39 connect(quickWindow, &QQuickWindow::beforeSynchronizing,
40 this, &QWaylandQuickOutput::updateStarted,
41 Qt::DirectConnection);
42
43 connect(quickWindow, &QQuickWindow::afterRendering,
44 this, &QWaylandQuickOutput::doFrameCallbacks);
45}
46
47void QWaylandQuickOutput::classBegin()
48{
49}
50
51void QWaylandQuickOutput::componentComplete()
52{
53 if (!compositor()) {
54 for (QObject *p = parent(); p != nullptr; p = p->parent()) {
55 if (auto c = qobject_cast<QWaylandCompositor *>(p)) {
56 setCompositor(c);
57 break;
58 }
59 }
60 }
61}
62
63void QWaylandQuickOutput::update()
64{
65 if (!m_updateScheduled) {
66 //don't qobject_cast since we have verified the type in initialize
67 static_cast<QQuickWindow *>(window())->update();
68 m_updateScheduled = true;
69 }
70}
71
72/*!
73 * \qmlproperty bool QtWayland.Compositor::WaylandOutput::automaticFrameCallback
74 *
75 * This property holds whether the WaylandOutput automatically sends frame
76 * callbacks when rendering.
77 *
78 * The default is true.
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 */
92bool QWaylandQuickOutput::automaticFrameCallback() const
93{
94 return m_automaticFrameCallback;
95}
96
97void QWaylandQuickOutput::setAutomaticFrameCallback(bool automatic)
98{
99 if (m_automaticFrameCallback == automatic)
100 return;
101
102 m_automaticFrameCallback = automatic;
103 automaticFrameCallbackChanged();
104}
105
106static 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
135QQuickItem *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 */
147void QWaylandQuickOutput::updateStarted()
148{
149 m_updateScheduled = false;
150
151 if (!compositor())
152 return;
153
154 frameStarted();
155}
156
157void QWaylandQuickOutput::doFrameCallbacks()
158{
159 if (m_automaticFrameCallback)
160 sendFrameCallbacks();
161}
162QT_END_NAMESPACE
163
164#include "moc_qwaylandquickoutput.cpp"
Combined button and popup list for selecting options.
static QQuickItem * clickableItemAtPosition(QQuickItem *rootItem, const QPointF &position)