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
qwaylandivishellintegration.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 ITAGE Corporation, author: <yusuke.binsaki@itage.co.jp>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtCore/qsize.h>
7#include <QtCore/qdebug.h>
8
9#include <QtWaylandClient/private/qwaylanddisplay_p.h>
10#include <QtWaylandClient/private/qwaylandwindow_p.h>
11#include <QtWaylandClient/private/qwaylandabstractdecoration_p.h>
12
14
15#include <mutex>
16
17#include <unistd.h>
18
20
21namespace QtWaylandClient {
22
23class QWaylandIviController : public QWaylandClientExtensionTemplate<QWaylandIviController>,
24 public QtWayland::ivi_controller
25{
26public:
29};
30
35
42
43/* get unique id
44 * pattern1:
45 * When set QT_IVI_SURFACE_ID, We use it as ID.
46 * Next ID is increment.
47 * pattern2:
48 * When not set QT_IVI_SURFACE_ID, We use process ID and unused bit.
49 * process ID maximum is 2^22. Unused bit is 23 to 32 bit.
50 * Therefor, We use 23 to 32 bit. This do not overlap with other clients.
51 * Next ID is increment of 23 to 32 bit.
52 * +------------+---------------------------+
53 * |31 23|22 0|
54 * +------------+---------------------------+
55 * |0000 0000 00|00 0000 0000 0000 0000 0000|
56 * |<- ID ->|<- process ID ->|
57 * +------------+---------------------------+
58 */
59uint32_t QWaylandIviShellIntegration::getNextUniqueSurfaceId()
60{
61 const uint32_t PID_MAX_EXPONENTIATION = 22; // 22 bit shift operation
62 const uint32_t ID_LIMIT = 1 << (32 - PID_MAX_EXPONENTIATION); // 10 bit is unique id
63 const std::lock_guard<QRecursiveMutex> locker(m_mutex);
64
65 if (m_lastSurfaceId == 0) {
66 QByteArray env = qgetenv("QT_IVI_SURFACE_ID");
67 bool ok;
68 m_lastSurfaceId = env.toUInt(&ok, 10);
69 if (ok)
70 m_useEnvSurfaceId = true;
71 else
72 m_lastSurfaceId = getpid();
73
74 return m_lastSurfaceId;
75 }
76
77 if (m_useEnvSurfaceId) {
78 m_lastSurfaceId++;
79 } else {
80 m_surfaceNumber++;
81 if (m_surfaceNumber >= ID_LIMIT) {
82 qWarning("IVI surface id counter overflow\n");
83 return 0;
84 }
85 m_lastSurfaceId += (m_surfaceNumber << PID_MAX_EXPONENTIATION);
86 }
87
88 return m_lastSurfaceId;
89}
90
92{
93 if (!isActive())
94 return nullptr;
95
96 uint32_t surfaceId = getNextUniqueSurfaceId();
97 if (surfaceId == 0)
98 return nullptr;
99
100 struct ivi_surface *surface = surface_create(surfaceId, window->wlSurface());
101 if (!m_iviController->isActive())
102 return new QWaylandIviSurface(surface, window);
103
104 struct ::ivi_controller_surface *controller = m_iviController->ivi_controller::surface_create(surfaceId);
105 QWaylandIviSurface *iviSurface = new QWaylandIviSurface(surface, window, controller);
106
107 if (window->window()->type() == Qt::Popup) {
108 QPoint transientPos = window->geometry().topLeft(); // this is absolute
109 QWaylandWindow *parent = window->transientParent();
110 if (parent && parent->decoration()) {
111 transientPos -= parent->geometry().topLeft();
112 transientPos.setX(transientPos.x() + parent->decoration()->margins().left());
113 transientPos.setY(transientPos.y() + parent->decoration()->margins().top());
114 }
115 QSize size = window->windowGeometry().size();
116 iviSurface->ivi_controller_surface::set_destination_rectangle(transientPos.x(),
117 transientPos.y(),
118 size.width(),
119 size.height());
120 }
121
122 return iviSurface;
123}
124
125}
126
\inmodule QtCore
Definition qbytearray.h:57
uint toUInt(bool *ok=nullptr, int base=10) const
Returns the byte array converted to an {unsigned int} using base base, which is ten by default.
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore
Definition qsize.h:25
QWaylandShellSurface * createShellSurface(QWaylandWindow *window) override
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
@ Popup
Definition qnamespace.h:211
#define qWarning
Definition qlogging.h:166
GLenum GLuint GLintptr GLsizeiptr size
[1]
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
aWidget window() -> setWindowTitle("New Window Title")
[2]