Commit d8d02147 authored by Eskil Abrahamsen-Blomfeldt's avatar Eskil Abrahamsen-Blomfeldt
Browse files

Add remotedesktop example and polish docs

Copy the compositor manual test into an example.
parent 53a63b85
qt_internal_add_example(vncchat)
if(TARGET Qt::Wayland)
qt_internal_add_example(remotedesktop)
endif()
cmake_minimum_required(VERSION 3.16)
project(remotedesktop LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/vncserver/remotedesktop")
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml)
qt_add_executable(remotedesktop
main.cpp
)
set_target_properties(remotedesktop PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(remotedesktop PUBLIC
Qt::Core
Qt::Gui
Qt::Qml
)
# Resources:
set(remotedesktop_resource_files
"main.qml"
)
qt6_add_resources(remotedesktop "remotedesktop"
PREFIX
"/"
FILES
${remotedesktop_resource_files}
)
install(TARGETS remotedesktop
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\example remotedesktop
\ingroup vncserver-examples
\title Qt VNC Server - Remote Desktop Example
\brief Demonstrates how to make a remote desktop using Qt VNC Server and Qt Wayland Compositor.
\image remotedesktop-example.png
\e {Remote Desktop} demonstrates the use of the \l{Qt VNC Server} module and the
\l{Qt Wayland Compositor} module to make a Wayland compositor with remote desktop capabilities.
The example follows the same setup as in the
\l{Qt Wayland Compositor Examples - Minimal QML}{Minimal QML} example from
\e{Qt Wayland Compositor}.
The main modification is that the Remote Desktop example wraps the top level item of the
WaylandOutput inside a VncItem:
\snippet remotedesktop/main.qml vncitem
This will automatically create a server which shares the whole desktop on the default port of
5900.
When any remote user connects, this is indicated by the presence of a red circle in the top-left
corner of the desktop, as shown in the screenshot. This is a simple \l{Rectangle} item which
has its visibility bound to the \l{VncItem.connectionActive}{connectionActive} property of the
VncItem:
\snippet remotedesktop/main.qml indicator
*/
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtCore/QUrl>
#include <QtCore/QDebug>
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
int main(int argc, char *argv[])
{
// ShareOpenGLContexts is needed for using the threaded renderer
// on Nvidia EGLStreams
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
QGuiApplication app(argc, argv);
QQmlApplicationEngine appEngine(QUrl("qrc:///main.qml"));
return app.exec();
}
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick
import QtWayland.Compositor
import QtWayland.Compositor.XdgShell
import QtWayland.Compositor.WlShell
import QtWayland.Compositor.IviApplication
import QtQuickVnc
WaylandCompositor {
WaylandOutput {
sizeFollowsWindow: true
window: Window {
width: 1024
height: 768
visible: true
//! [vncitem]
VncItem {
id: vncItem
anchors.fill: parent
//! [vncitem]
Rectangle {
id: sourceRect
anchors.fill: parent
color: "steelblue"
Repeater {
model: shellSurfaces
ShellSurfaceItem {
shellSurface: modelData
onSurfaceDestroyed: shellSurfaces.remove(index)
}
}
//! [indicator]
Rectangle {
id: connectedIndicator
visible: vncItem.connectionActive
x: 10
y: 10
width: 30
height: 30
radius: 15
color: "red"
}
//! [indicator]
}
}
}
}
WlShell {
onWlShellSurfaceCreated:
shellSurfaces.append({shellSurface: shellSurface});
}
XdgShell {
onToplevelCreated:
shellSurfaces.append({shellSurface: xdgSurface});
}
IviApplication {
onIviSurfaceCreated: {
shellSurfaces.append({shellSurface: iviSurface});
}
}
ListModel { id: shellSurfaces }
}
......@@ -30,9 +30,27 @@
\ingroup vncserver-examples
\title Qt VNC Server - VncChat Example
\brief Demonstrates how to make a simple application that uses Qt VNC Server.
\image vncchat-example.png
\e {VncChat} demonstrates the use of the \l{Qt VNC Server} module. The example
is a simple, disorganized chat application where a text editor component is
exposed to VNC®-compatible clients and anyone connecting can edit it together.
\e {VncChat} demonstrates the use of the \l{Qt VNC Server} module.
The example is a very basic and disorganized chat application, which consists of a text editor
that is exposed to VNC®-compatible clients and can be edited by anyone at any time.
The text editor and its frame is wrapped by a VncItem which causes it to automatically be
shared over the connection:
\snippet vncchat/main.qml vncitem
Only the contents of the VncItem will be shared, so the colored frame around it and application
title will only be visible locally.
Default values are used for all properties, which means the server will be listening to port
5900. For convenience, this information is provided in a label at the top:
\snippet vncchat/main.qml vncport
Finally, the locally running application has a frame around the VncItem which changes color
depending on whether a client is connected or not. In the screenshot, this is dark sea green,
indicating that a client has connected. When no client is connected, it will be the color
'salmon':
\snippet vncchat/main.qml indicator
*/
......@@ -67,16 +67,21 @@ Window {
width: parent.width * 0.75
height: parent.height * 0.75
radius: parent.width * 0.1
//! [indicator]
color: grabber.connectionActive ? "darkseagreen" : "salmon"
//! [indicator]
Label {
id: titleLabel
anchors.top: activeRect.top
anchors.topMargin: parent.width * 0.015
anchors.horizontalCenter: activeRect.horizontalCenter
text: "Qt Vnc Chat"
font.pixelSize: window.height * 0.03
}
//! [vncport]
Label {
id: portLabel
anchors.top: titleLabel.bottom
......@@ -84,12 +89,15 @@ Window {
text: "(Port " + grabber.vncPort + " is open for business)"
font.pixelSize: window.height * 0.015
}
//! [vncport]
//! [vncitem]
VncItem {
id: grabber
anchors.fill: parent
Rectangle {
id: editorFrame
anchors.fill: parent
anchors.margins: window.width * 0.1
radius: window.width * 0.1
......@@ -105,5 +113,6 @@ Window {
}
}
}
//! [vncitem]
}
}
......@@ -49,13 +49,15 @@ solution.
\section2 C++ API
\section1
\include {module-use.qdocinc} {using the c++ api}
\section1 Examples
The best way to see what Qt VNC Server can do is to check out the examples:
\list
\li \l{Qt VNC Server - VncChat Example}{Vnc Chat}
\li \l{Qt VNC Server - Remote Desktop Example}{Remote Desktop}
\endlist
\section1 Supported features
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment