1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qvncintegration.h"
41#include "qvncscreen.h"
42#include "qvnc_p.h"
43
44#include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h>
45#include <QtServiceSupport/private/qgenericunixservices_p.h>
46#include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h>
47
48#include <QtFbSupport/private/qfbbackingstore_p.h>
49#include <QtFbSupport/private/qfbwindow_p.h>
50#include <QtFbSupport/private/qfbcursor_p.h>
51
52#include <QtGui/private/qguiapplication_p.h>
53#include <qpa/qplatforminputcontextfactory_p.h>
54#include <private/qinputdevicemanager_p_p.h>
55#include <qpa/qwindowsysteminterface.h>
56
57#include <QtCore/QRegularExpression>
58
59QT_BEGIN_NAMESPACE
60
61QVncIntegration::QVncIntegration(const QStringList &paramList)
62 : m_fontDb(new QGenericUnixFontDatabase),
63 m_services(new QGenericUnixServices)
64{
65 QRegularExpression portRx(QLatin1String("port=(\\d+)"));
66 quint16 port = 5900;
67 for (const QString &arg : paramList) {
68 QRegularExpressionMatch match;
69 if (arg.contains(re: portRx, rmatch: &match))
70 port = match.captured(nth: 1).toInt();
71 }
72
73 m_primaryScreen = new QVncScreen(paramList);
74 m_server = new QVncServer(m_primaryScreen, port);
75 m_primaryScreen->vncServer = m_server;
76}
77
78QVncIntegration::~QVncIntegration()
79{
80 delete m_server;
81 QWindowSystemInterface::handleScreenRemoved(screen: m_primaryScreen);
82}
83
84void QVncIntegration::initialize()
85{
86 if (m_primaryScreen->initialize())
87 QWindowSystemInterface::handleScreenAdded(screen: m_primaryScreen);
88 else
89 qWarning(msg: "vnc: Failed to initialize screen");
90
91 m_inputContext = QPlatformInputContextFactory::create();
92
93 m_nativeInterface.reset(other: new QPlatformNativeInterface);
94
95 // we always have exactly one mouse and keyboard
96 QInputDeviceManagerPrivate::get(mgr: QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
97 type: QInputDeviceManager::DeviceTypePointer, count: 1);
98 QInputDeviceManagerPrivate::get(mgr: QGuiApplicationPrivate::inputDeviceManager())->setDeviceCount(
99 type: QInputDeviceManager::DeviceTypeKeyboard, count: 1);
100
101}
102
103bool QVncIntegration::hasCapability(QPlatformIntegration::Capability cap) const
104{
105 switch (cap) {
106 case ThreadedPixmaps: return true;
107 case WindowManagement: return false;
108 default: return QPlatformIntegration::hasCapability(cap);
109 }
110}
111
112QPlatformBackingStore *QVncIntegration::createPlatformBackingStore(QWindow *window) const
113{
114 return new QFbBackingStore(window);
115}
116
117QPlatformWindow *QVncIntegration::createPlatformWindow(QWindow *window) const
118{
119 return new QFbWindow(window);
120}
121
122QAbstractEventDispatcher *QVncIntegration::createEventDispatcher() const
123{
124 return createUnixEventDispatcher();
125}
126
127QList<QPlatformScreen *> QVncIntegration::screens() const
128{
129 QList<QPlatformScreen *> list;
130 list.append(t: m_primaryScreen);
131 return list;
132}
133
134QPlatformFontDatabase *QVncIntegration::fontDatabase() const
135{
136 return m_fontDb.data();
137}
138
139QPlatformServices *QVncIntegration::services() const
140{
141 return m_services.data();
142}
143
144QPlatformNativeInterface *QVncIntegration::nativeInterface() const
145{
146 return m_nativeInterface.data();
147}
148
149QT_END_NAMESPACE
150

source code of qtbase/src/plugins/platforms/vnc/qvncintegration.cpp