1 | // Copyright (C) 2017 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 "qvncintegration.h" |
5 | #include "qvncscreen.h" |
6 | #include "qvnc_p.h" |
7 | |
8 | #include <QtGui/private/qgenericunixfontdatabase_p.h> |
9 | #include <QtGui/private/qgenericunixservices_p.h> |
10 | #include <QtGui/private/qgenericunixeventdispatcher_p.h> |
11 | |
12 | #include <QtFbSupport/private/qfbbackingstore_p.h> |
13 | #include <QtFbSupport/private/qfbwindow_p.h> |
14 | #include <QtFbSupport/private/qfbcursor_p.h> |
15 | |
16 | #include <QtGui/private/qguiapplication_p.h> |
17 | #include <qpa/qplatforminputcontextfactory_p.h> |
18 | #include <private/qinputdevicemanager_p_p.h> |
19 | #include <qpa/qwindowsysteminterface.h> |
20 | |
21 | #include <QtCore/QRegularExpression> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | using namespace Qt::StringLiterals; |
26 | |
27 | QVncIntegration::QVncIntegration(const QStringList ¶mList) |
28 | : m_fontDb(new QGenericUnixFontDatabase) |
29 | { |
30 | QRegularExpression portRx("port=(\\d+)"_L1); |
31 | quint16 port = 5900; |
32 | for (const QString &arg : paramList) { |
33 | QRegularExpressionMatch match; |
34 | if (arg.contains(re: portRx, rmatch: &match)) |
35 | port = match.captured(nth: 1).toInt(); |
36 | } |
37 | |
38 | m_primaryScreen = new QVncScreen(paramList); |
39 | m_server = new QVncServer(m_primaryScreen, port); |
40 | m_primaryScreen->vncServer = m_server; |
41 | } |
42 | |
43 | QVncIntegration::~QVncIntegration() |
44 | { |
45 | delete m_server; |
46 | QWindowSystemInterface::handleScreenRemoved(screen: m_primaryScreen); |
47 | } |
48 | |
49 | void QVncIntegration::initialize() |
50 | { |
51 | if (m_primaryScreen->initialize()) |
52 | QWindowSystemInterface::handleScreenAdded(screen: m_primaryScreen); |
53 | else |
54 | qWarning(msg: "vnc: Failed to initialize screen"); |
55 | |
56 | m_inputContext = QPlatformInputContextFactory::create(); |
57 | |
58 | m_nativeInterface.reset(other: new QPlatformNativeInterface); |
59 | |
60 | // we always have exactly one mouse and keyboard |
61 | QInputDeviceManagerPrivate::get(mgr: QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( |
62 | type: QInputDeviceManager::DeviceTypePointer, count: 1); |
63 | QInputDeviceManagerPrivate::get(mgr: QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( |
64 | type: QInputDeviceManager::DeviceTypeKeyboard, count: 1); |
65 | |
66 | } |
67 | |
68 | bool QVncIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
69 | { |
70 | switch (cap) { |
71 | case ThreadedPixmaps: return true; |
72 | case WindowManagement: return false; |
73 | case RhiBasedRendering: return false; |
74 | default: return QPlatformIntegration::hasCapability(cap); |
75 | } |
76 | } |
77 | |
78 | QPlatformBackingStore *QVncIntegration::createPlatformBackingStore(QWindow *window) const |
79 | { |
80 | return new QFbBackingStore(window); |
81 | } |
82 | |
83 | QPlatformWindow *QVncIntegration::createPlatformWindow(QWindow *window) const |
84 | { |
85 | return new QFbWindow(window); |
86 | } |
87 | |
88 | QAbstractEventDispatcher *QVncIntegration::createEventDispatcher() const |
89 | { |
90 | return createUnixEventDispatcher(); |
91 | } |
92 | |
93 | QList<QPlatformScreen *> QVncIntegration::screens() const |
94 | { |
95 | QList<QPlatformScreen *> list; |
96 | list.append(t: m_primaryScreen); |
97 | return list; |
98 | } |
99 | |
100 | QPlatformFontDatabase *QVncIntegration::fontDatabase() const |
101 | { |
102 | return m_fontDb.data(); |
103 | } |
104 | |
105 | QPlatformServices *QVncIntegration::services() const |
106 | { |
107 | if (m_services.isNull()) |
108 | m_services.reset(other: new QGenericUnixServices); |
109 | |
110 | return m_services.data(); |
111 | } |
112 | |
113 | QPlatformNativeInterface *QVncIntegration::nativeInterface() const |
114 | { |
115 | return m_nativeInterface.data(); |
116 | } |
117 | |
118 | QT_END_NAMESPACE |
119 |