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 | m_services(new QGenericUnixServices) |
30 | { |
31 | QRegularExpression portRx("port=(\\d+)"_L1); |
32 | quint16 port = 5900; |
33 | for (const QString &arg : paramList) { |
34 | QRegularExpressionMatch match; |
35 | if (arg.contains(re: portRx, rmatch: &match)) |
36 | port = match.captured(nth: 1).toInt(); |
37 | } |
38 | |
39 | m_primaryScreen = new QVncScreen(paramList); |
40 | m_server = new QVncServer(m_primaryScreen, port); |
41 | m_primaryScreen->vncServer = m_server; |
42 | } |
43 | |
44 | QVncIntegration::~QVncIntegration() |
45 | { |
46 | delete m_server; |
47 | QWindowSystemInterface::handleScreenRemoved(screen: m_primaryScreen); |
48 | } |
49 | |
50 | void QVncIntegration::initialize() |
51 | { |
52 | if (m_primaryScreen->initialize()) |
53 | QWindowSystemInterface::handleScreenAdded(screen: m_primaryScreen); |
54 | else |
55 | qWarning(msg: "vnc: Failed to initialize screen"); |
56 | |
57 | m_inputContext = QPlatformInputContextFactory::create(); |
58 | |
59 | m_nativeInterface.reset(other: new QPlatformNativeInterface); |
60 | |
61 | // we always have exactly one mouse and keyboard |
62 | QInputDeviceManagerPrivate::get(mgr: QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( |
63 | type: QInputDeviceManager::DeviceTypePointer, count: 1); |
64 | QInputDeviceManagerPrivate::get(mgr: QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount( |
65 | type: QInputDeviceManager::DeviceTypeKeyboard, count: 1); |
66 | |
67 | } |
68 | |
69 | bool QVncIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
70 | { |
71 | switch (cap) { |
72 | case ThreadedPixmaps: return true; |
73 | case WindowManagement: return false; |
74 | case RhiBasedRendering: return false; |
75 | default: return QPlatformIntegration::hasCapability(cap); |
76 | } |
77 | } |
78 | |
79 | QPlatformBackingStore *QVncIntegration::createPlatformBackingStore(QWindow *window) const |
80 | { |
81 | return new QFbBackingStore(window); |
82 | } |
83 | |
84 | QPlatformWindow *QVncIntegration::createPlatformWindow(QWindow *window) const |
85 | { |
86 | return new QFbWindow(window); |
87 | } |
88 | |
89 | QAbstractEventDispatcher *QVncIntegration::createEventDispatcher() const |
90 | { |
91 | return createUnixEventDispatcher(); |
92 | } |
93 | |
94 | QList<QPlatformScreen *> QVncIntegration::screens() const |
95 | { |
96 | QList<QPlatformScreen *> list; |
97 | list.append(t: m_primaryScreen); |
98 | return list; |
99 | } |
100 | |
101 | QPlatformFontDatabase *QVncIntegration::fontDatabase() const |
102 | { |
103 | return m_fontDb.data(); |
104 | } |
105 | |
106 | QPlatformServices *QVncIntegration::services() const |
107 | { |
108 | return m_services.data(); |
109 | } |
110 | |
111 | QPlatformNativeInterface *QVncIntegration::nativeInterface() const |
112 | { |
113 | return m_nativeInterface.data(); |
114 | } |
115 | |
116 | QT_END_NAMESPACE |
117 |