diff --git a/CMakeLists.txt b/CMakeLists.txt index 94d4baa..ed3acbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,29 +1,31 @@ cmake_minimum_required(VERSION 3.16) -set(KF5_MIN_VERSION "5.54") project(xdg-desktop-portal-dde - VERSION 1.0.0 + VERSION 1.0.0 ) set(CMAKE_CXX_STANDARD 17) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - set(CMAKE_INSTALL_PREFIX /usr) + set(CMAKE_INSTALL_PREFIX /usr) endif () + include(GNUInstallDirs) add_subdirectory(src) configure_file( - misc/xdg-desktop-portal-dde.service.in - xdg-desktop-portal-dde.service - @ONLY) + misc/xdg-desktop-portal-dde.service.in + xdg-desktop-portal-dde.service + @ONLY) configure_file( - misc/org.freedesktop.impl.portal.desktop.dde.service.in - org.freedesktop.impl.portal.desktop.dde.service - @ONLY) + misc/org.freedesktop.impl.portal.desktop.dde.service.in + org.freedesktop.impl.portal.desktop.dde.service + @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xdg-desktop-portal-dde.service DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/systemd/user/") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.impl.portal.desktop.dde.service DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/dbus-1/services") diff --git a/archlinux/PKGBUILD b/archlinux/PKGBUILD index bf68b2e..1b53933 100644 --- a/archlinux/PKGBUILD +++ b/archlinux/PKGBUILD @@ -8,8 +8,8 @@ pkgdesc='xdg-desktop-portal backend for deepin' arch=('x86_64' 'aarch64') url='https://github.com/linuxdeepin/xdg-desktop-portal-dde' license=('LGPL3') -depends=('qt5-base' 'qt5-wayland' 'wayland' 'ki18n5' 'dwayland-git' 'knotifications5') -makedepends=('git' 'ninja' 'cmake' 'qt5-tools' 'wayland-protocols' 'extra-cmake-modules') +depends=('qt6-base' 'qt6-wayland' 'wayland') +makedepends=('git' 'ninja' 'cmake' 'qt6-tools' 'wayland-protocols') provides=('xdg-desktop-portal-impl') groups=('deepin-git') source=("${sourcetars[@]}") diff --git a/debian/control b/debian/control index 465748a..1c5a1b5 100644 --- a/debian/control +++ b/debian/control @@ -6,22 +6,12 @@ Build-Depends: cmake (>= 3.0~), dbus-x11, debhelper (>= 11~), - extra-cmake-modules (>= 5.50.0~), - qtwayland5-dev-tools, - libkf5coreaddons-dev (>= 5.50.0~), - libkf5i18n-dev (>= 5.50.0~), - libkf5notifications-dev (>= 5.50.0~), - libkf5widgetsaddons-dev (>= 5.50.0~), - libkf5windowsystem-dev (>= 5.50.0~), - pkg-kde-tools (>= 0.15.18~), - qtbase5-dev (>= 5.11.0~), - qtbase5-private-dev, + qt6-base-dev, + qt6-wayland, + qt6-wayland-dev, + qt6-wayland-dev-tools, libpipewire-0.3-dev, - libgbm-dev, - libepoxy-dev, - libkf5declarative-dev, libwayland-dev, - libdwayland-dev Standards-Version: 4.5.0 Package: xdg-desktop-portal-dde diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 49f6f71..65f8d5f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,27 +1,11 @@ -find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core) find_package( - Qt${QT_VERSION_MAJOR} CONFIG REQUIRED COMPONENTS - Core - Concurrent - DBus - Widgets) -find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) - -set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) - -find_package(QtWaylandScanner REQUIRED) - -find_package(KF5 ${KF5_MIN_VERSION} REQUIRED - I18n - Notifications -) - -find_package(DWayland REQUIRED) -find_package(KF5I18n CONFIG REQUIRED) -find_package(Wayland 1.15 REQUIRED COMPONENTS Client) -find_package(PkgConfig) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) + Qt6 CONFIG REQUIRED COMPONENTS + Core + Concurrent + DBus + Widgets + WaylandClient) +find_package(Qt6WaylandScannerTools REQUIRED) set_source_files_properties( ${CMAKE_SOURCE_DIR}/misc/org.freedesktop.Notifications.xml @@ -31,90 +15,65 @@ set_source_files_properties( NO_NAMESPACE OFF ) -qt5_add_dbus_interface(NotificationInterface + +qt6_add_dbus_interface(NotificationInterface ${CMAKE_SOURCE_DIR}/misc/org.freedesktop.Notifications.xml notification_interface ) set(SRC - ${NotificationInterface} - xdg-desktop-portal-dde.cpp - ddesktopportal.h - ddesktopportal.cpp - screenshot.h - screenshot.cpp - background.h - background.cpp - filechooser.h - filechooser.cpp - wallpaper.h - wallpaper.cpp - notification.h - notification.cpp - settings.h - settings.cpp - inhibit.h - inhibit.cpp - appchooser.h - appchooser.cpp - appchooserdialog.h - appchooserdialog.cpp - appchooserdelegate.h - appchooserdelegate.cpp - appchoosermodel.h - appchoosermodel.cpp - iteminfo.h - iteminfo.cpp - account.h - account.cpp - session.h - session.cpp - globalshortcut.h - globalshortcut.cpp - lockdown.h - lockdown.cpp - secret.h - secret.cpp - request.h - request.cpp - dbushelpers.h - utils.h - utils.cpp - screencast.cpp - screencasting.cpp - screencastwidget.cpp - screenchooserdialog.cpp - remotedesktop.cpp - remotedesktopdialog.cpp - waylandintegration.cpp -) - -QT5_WRAP_UI(SRC - screenchooserdialog.ui - remotedesktopdialog.ui) - -ecm_add_qtwayland_client_protocol(SRC - PROTOCOL ${CMAKE_SOURCE_DIR}/misc/zkde-screencast-unstable-v1.xml - BASENAME zkde-screencast-unstable-v1 -) - -ecm_add_qtwayland_client_protocol(SRC - PROTOCOL ${Wayland_DATADIR}/wayland.xml - BASENAME wayland + ${NotificationInterface} + xdg-desktop-portal-dde.cpp + ddesktopportal.h + ddesktopportal.cpp + screenshot.h + screenshot.cpp + background.h + background.cpp + filechooser.h + filechooser.cpp + wallpaper.h + wallpaper.cpp + notification.h + notification.cpp + settings.h + settings.cpp + inhibit.h + inhibit.cpp + appchooser.h + appchooser.cpp + appchooserdialog.h + appchooserdialog.cpp + appchooserdelegate.h + appchooserdelegate.cpp + appchoosermodel.h + appchoosermodel.cpp + iteminfo.h + iteminfo.cpp + account.h + account.cpp + globalshortcut.h + globalshortcut.cpp + lockdown.h + lockdown.cpp + secret.h + secret.cpp + request.h + request.cpp + dbushelpers.h + utils.h + utils.cpp ) add_executable(${PROJECT_NAME} - ${SRC}) + ${SRC}) target_link_libraries(${PROJECT_NAME} PUBLIC - Qt${QT_VERSION_MAJOR}::Core - Qt${QT_VERSION_MAJOR}::Widgets - Qt${QT_VERSION_MAJOR}::Gui - Qt${QT_VERSION_MAJOR}::DBus - Qt${QT_VERSION_MAJOR}::Concurrent - KF5::I18n - DWaylandClient - KF5::Notifications - Wayland::Client) + Qt::Core + Qt::Widgets + Qt::Gui + Qt::DBus + Qt::Concurrent + Qt::WaylandClient) install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) diff --git a/src/ddesktopportal.cpp b/src/ddesktopportal.cpp index c54222d..30952f0 100644 --- a/src/ddesktopportal.cpp +++ b/src/ddesktopportal.cpp @@ -8,18 +8,14 @@ #include "secret.h" #include "lockdown.h" #include "globalshortcut.h" -#include "session.h" -#include "remotedesktop.h" #include "account.h" #include "inhibit.h" #include "settings.h" #include "screenshot.h" -#include "screencast.h" #include "background.h" #include "filechooser.h" #include "wallpaper.h" #include "notification.h" -#include "waylandintegration.h" DDesktopPortal::DDesktopPortal(QObject *parent) : QObject(parent) @@ -31,16 +27,12 @@ DDesktopPortal::DDesktopPortal(QObject *parent) const QByteArray &xdgCurrentDesktop = qgetenv("XDG_CURRENT_DESKTOP").toUpper(); if (xdgCurrentDesktop == "DDE" || xdgCurrentDesktop == "DEEPIN") { m_screenshot = new ScreenshotPortal(this); - m_screencast = new ScreenCastPortal(this); m_background = new BackgroundPortal(this); m_settings = new SettingsPortal(this); m_inhibit = new InhibitPortal(this); m_account = new AccountPortal(this); - m_session = new SessionPortal(this); - m_remote = new RemoteDesktopPortal(this); m_shortcut = new GlobalShortcutPortal(this); m_lockdown = new LockdownPortal(this); m_secret = new SecretPortal(this); - WaylandIntegration::init(); } } diff --git a/src/ddesktopportal.h b/src/ddesktopportal.h index fdfd35d..9ada16d 100644 --- a/src/ddesktopportal.h +++ b/src/ddesktopportal.h @@ -8,13 +8,10 @@ #include class ScreenshotPortal; -class ScreenCastPortal; class BackgroundPortal; class InhibitPortal; class SettingsPortal; class AccountPortal; -class SessionPortal; -class RemoteDesktopPortal; class GlobalShortcutPortal; class LockdownPortal; class SecretPortal; @@ -35,13 +32,10 @@ class DDesktopPortal : public QObject, public QDBusContext AppChooserPortal *const m_appChooser; FileChooserPortal *const m_fileChooser; ScreenshotPortal *m_screenshot = nullptr; - ScreenCastPortal *m_screencast = nullptr; BackgroundPortal *m_background = nullptr; InhibitPortal *m_inhibit = nullptr; SettingsPortal *m_settings = nullptr; AccountPortal *m_account = nullptr; - SessionPortal *m_session = nullptr; - RemoteDesktopPortal *m_remote = nullptr; GlobalShortcutPortal *m_shortcut = nullptr; LockdownPortal *m_lockdown = nullptr; SecretPortal *m_secret = nullptr; diff --git a/src/notification.cpp b/src/notification.cpp index 9a7e6b6..c183a28 100644 --- a/src/notification.cpp +++ b/src/notification.cpp @@ -49,7 +49,7 @@ void NotificationPortal::AddNotification(const QString &app_id, const QString &i } QStringList actions; - for (const QVariantMap &button : qAsConst(buttons)) { + for (const QVariantMap &button : std::as_const(buttons)) { actions << button.value(QStringLiteral("label")).toString(); } diff --git a/src/remotedesktop.cpp b/src/remotedesktop.cpp deleted file mode 100644 index 6c94728..0000000 --- a/src/remotedesktop.cpp +++ /dev/null @@ -1,296 +0,0 @@ -// Copyright © 2018 Red Hat, Inc -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "remotedesktop.h" -#include "session.h" -#include "remotedesktopdialog.h" -#include "utils.h" -#include "waylandintegration.h" -#include - -Q_LOGGING_CATEGORY(XdgDesktopPortalDdeRemoteDesktop, "xdp-dde-remotedesktop") - -RemoteDesktopPortal::RemoteDesktopPortal(QObject *parent) - : QDBusAbstractAdaptor(parent) -{ -} - -RemoteDesktopPortal::~RemoteDesktopPortal() -{ -} - -uint RemoteDesktopPortal::CreateSession(const QDBusObjectPath &handle, - const QDBusObjectPath &session_handle, - const QString &app_id, - const QVariantMap &options, - QVariantMap &results) -{ - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << "CreateSession called with parameters:"; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " handle: " << handle.path(); - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " session_handle: " << session_handle.path(); - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " app_id: " << app_id; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " options: " << options; - - Session *session = Session::createSession(this, Session::RemoteDesktop, app_id, session_handle.path()); - - if (!session) { - return 2; - } - - connect(session, &Session::closed, [] () { - WaylandIntegration::stopAllStreaming(); - }); - - if (!WaylandIntegration::isStreamingAvailable()) { - qCWarning(XdgDesktopPortalDdeRemoteDesktop) << "zkde_screencast_unstable_v1 does not seem to be available"; - return 2; - } - - return 0; -} - -uint RemoteDesktopPortal::SelectDevices(const QDBusObjectPath &handle, - const QDBusObjectPath &session_handle, - const QString &app_id, - const QVariantMap &options, - QVariantMap &results) -{ - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << "SelectDevices called with parameters:"; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " handle: " << handle.path(); - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " session_handle: " << session_handle.path(); - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " app_id: " << app_id; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " options: " << options; - - RemoteDesktopPortal::DeviceTypes types = RemoteDesktopPortal::None; - if (options.contains(QStringLiteral("types"))) { - types = static_cast(options.value(QStringLiteral("types")).toUInt()); - } - - RemoteDesktopSession *session = qobject_cast(Session::getSession(session_handle.path())); - - if (!session) { - qCWarning(XdgDesktopPortalDdeRemoteDesktop) << "Tried to select sources on non-existing session " << session_handle.path(); - return 2; - } - - if (options.contains(QStringLiteral("types"))) { - types = (DeviceTypes)(options.value(QStringLiteral("types")).toUInt()); - } - session->setDeviceTypes(types); - - return 0; -} - -uint RemoteDesktopPortal::Start(const QDBusObjectPath &handle, - const QDBusObjectPath &session_handle, - const QString &app_id, - const QString &parent_window, - const QVariantMap &options, - QVariantMap &results) -{ - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " RemoteDesktopPortal Start called with parameters:"; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " handle: " << handle.path(); - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " session_handle: " << session_handle.path(); - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " app_id: " << app_id; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " parent_window: " << parent_window; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " options: " << options; - - RemoteDesktopSession *session = qobject_cast(Session::getSession(session_handle.path())); - - if (!session) { - qCWarning(XdgDesktopPortalDdeRemoteDesktop) << "Tried to call start on non-existing session " << session_handle.path(); - return 2; - } - - // TODO check whether we got some outputs? - if (WaylandIntegration::screens().isEmpty()) { - qCWarning(XdgDesktopPortalDdeRemoteDesktop) << "Failed to show dialog as there is no screen to select"; - return 2; - } - - QScopedPointer remoteDesktopDialog(new RemoteDesktopDialog(app_id, session->deviceTypes(), session->screenSharingEnabled(), session->multipleSources())); - Utils::setParentWindow(remoteDesktopDialog.data(), QString()); - - connect(session, &Session::closed, remoteDesktopDialog.data(), &RemoteDesktopDialog::reject); - if (!parent_window.isEmpty() || remoteDesktopDialog->exec()) { - if (session->screenSharingEnabled()) { - if (!WaylandIntegration::startStreamingOutput(remoteDesktopDialog->selectedScreens().first(), Screencasting::Hidden)) { - return 2; - } - - WaylandIntegration::authenticate(); - - QVariant streams = WaylandIntegration::streams(); - - if (!streams.isValid()) { - qCWarning(XdgDesktopPortalDdeRemoteDesktop()) << "Pipewire stream is not ready to be streamed"; - return 2; - } - - results.insert(QStringLiteral("streams"), streams); - } else { - qCWarning(XdgDesktopPortalDdeRemoteDesktop()) << "Only stream input"; - WaylandIntegration::startStreamingInput(); - WaylandIntegration::authenticate(); - } - results.insert(QStringLiteral("devices"), QVariant::fromValue(remoteDesktopDialog->deviceTypes())); - return 0; - } - return 1; -} - -void RemoteDesktopPortal::NotifyPointerMotion(const QDBusObjectPath &session_handle, - const QVariantMap &options, - double dx, - double dy) -{ - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << "NotifyPointerMotion called with parameters:"; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " session_handle: " << session_handle.path(); - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " options: " << options; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " dx: " << dx; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " dy: " << dy; - - RemoteDesktopSession *session = qobject_cast(Session::getSession(session_handle.path())); - - if (!session) { - qCWarning(XdgDesktopPortalDdeRemoteDesktop) << "Tried to call NotifyPointerMotion on non-existing session " << session_handle.path(); - return; - } - - WaylandIntegration::requestPointerMotion(QSizeF(dx, dy)); -} - -void RemoteDesktopPortal::NotifyPointerMotionAbsolute(const QDBusObjectPath &session_handle, - const QVariantMap &options, - uint stream, - double x, - double y) -{ - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << "NotifyPointerMotionAbsolute called with parameters:"; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " session_handle: " << session_handle.path(); - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " options: " << options; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " stream: " << stream; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " x: " << x; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " y: " << y; - - RemoteDesktopSession *session = qobject_cast(Session::getSession(session_handle.path())); - - if (!session) { - qCWarning(XdgDesktopPortalDdeRemoteDesktop) << "Tried to call NotifyPointerMotionAbsolute on non-existing session " << session_handle.path(); - return; - } - - WaylandIntegration::requestPointerMotionAbsolute(QPointF(x, y)); -} - -void RemoteDesktopPortal::NotifyPointerButton(const QDBusObjectPath &session_handle, - const QVariantMap &options, - int button, - uint state) -{ - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << "NotifyPointerButton called with parameters:"; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " session_handle: " << session_handle.path(); - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " options: " << options; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " button: " << button; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " state: " << state; - - RemoteDesktopSession *session = qobject_cast(Session::getSession(session_handle.path())); - - if (!session) { - qCWarning(XdgDesktopPortalDdeRemoteDesktop) << "Tried to call NotifyPointerButton on non-existing session " << session_handle.path(); - return; - } - - if (state) { - WaylandIntegration::requestPointerButtonPress(button); - } else { - WaylandIntegration::requestPointerButtonRelease(button); - } -} - -void RemoteDesktopPortal::NotifyPointerAxis(const QDBusObjectPath &session_handle, - const QVariantMap &options, - double dx, - double dy) -{ - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << "NotifyPointerAxis called with parameters:"; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " session_handle: " << session_handle.path(); - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " options: " << options; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " dx: " << dx; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " dy: " << dy; -} - -void RemoteDesktopPortal::NotifyPointerAxisDiscrete(const QDBusObjectPath &session_handle, - const QVariantMap &options, - uint axis, - int steps) -{ - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << "NotifyPointerAxisDiscrete called with parameters:"; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " session_handle: " << session_handle.path(); - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " options: " << options; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " axis: " << axis; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " steps: " << steps; - - RemoteDesktopSession *session = qobject_cast(Session::getSession(session_handle.path())); - - if (!session) { - qCWarning(XdgDesktopPortalDdeRemoteDesktop) << "Tried to call NotifyPointerAxisDiscrete on non-existing session " << session_handle.path(); - return; - } - - WaylandIntegration::requestPointerAxisDiscrete(!axis ? Qt::Vertical : Qt::Horizontal, steps); -} - -void RemoteDesktopPortal::NotifyKeyboardKeysym(const QDBusObjectPath &session_handle, - const QVariantMap &options, - int keysym, - uint state) -{ -} - -void RemoteDesktopPortal::NotifyKeyboardKeycode(const QDBusObjectPath &session_handle, - const QVariantMap &options, - int keycode, - uint state) -{ - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << "NotifyKeyboardKeycode called with parameters:"; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " session_handle: " << session_handle.path(); - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " options: " << options; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " keycode: " << keycode; - qCDebug(XdgDesktopPortalDdeRemoteDesktop) << " state: " << state; - - RemoteDesktopSession *session = qobject_cast(Session::getSession(session_handle.path())); - - if (!session) { - qCWarning(XdgDesktopPortalDdeRemoteDesktop) << "Tried to call NotifyKeyboardKeycode on non-existing session " << session_handle.path(); - return; - } - - WaylandIntegration::requestKeyboardKeycode(keycode, state != 0); -} - -void RemoteDesktopPortal::NotifyTouchDown(const QDBusObjectPath &session_handle, - const QVariantMap &options, - uint stream, - uint slot, - int x, - int y) -{ -} - -void RemoteDesktopPortal::NotifyTouchMotion(const QDBusObjectPath &session_handle, - const QVariantMap &options, - uint stream, - uint slot, - int x, - int y) -{ -} - -void RemoteDesktopPortal::NotifyTouchUp(const QDBusObjectPath &session_handle, - const QVariantMap &options, - uint slot) -{ -} diff --git a/src/remotedesktop.h b/src/remotedesktop.h deleted file mode 100644 index 9e8419c..0000000 --- a/src/remotedesktop.h +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright © 2018 Red Hat, Inc -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef XDG_DESKTOP_PORTAL_DDE_REMOTEDESKTOP_H -#define XDG_DESKTOP_PORTAL_DDE_REMOTEDESKTOP_H - -#include -#include - - -class RemoteDesktopPortal : public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.freedesktop.impl.portal.RemoteDesktop") -public: - explicit RemoteDesktopPortal(QObject *parent); - ~RemoteDesktopPortal(); - - enum DeviceType { - None = 0x0, - Keyboard = 0x1, - Pointer = 0x2, - TouchScreen = 0x4, - All = (Keyboard | Pointer | TouchScreen) - }; - Q_DECLARE_FLAGS(DeviceTypes, DeviceType) - - uint version() const { return 1; } - uint AvailableDeviceTypes() const { return All; }; - -public Q_SLOTS: - uint CreateSession(const QDBusObjectPath &handle, - const QDBusObjectPath &session_handle, - const QString &app_id, - const QVariantMap &options, - QVariantMap &results); - - uint SelectDevices(const QDBusObjectPath &handle, - const QDBusObjectPath &session_handle, - const QString &app_id, - const QVariantMap &options, - QVariantMap &results); - - uint Start(const QDBusObjectPath &handle, - const QDBusObjectPath &session_handle, - const QString &app_id, - const QString &parent_window, - const QVariantMap &options, - QVariantMap &results); - - void NotifyPointerMotion(const QDBusObjectPath &session_handle, - const QVariantMap &options, - double dx, - double dy); - - void NotifyPointerMotionAbsolute(const QDBusObjectPath &session_handle, - const QVariantMap &options, - uint stream, - double x, - double y); - - void NotifyPointerButton(const QDBusObjectPath &session_handle, - const QVariantMap &options, - int button, - uint state); - - void NotifyPointerAxis(const QDBusObjectPath &session_handle, - const QVariantMap &options, - double dx, - double dy); - - void NotifyPointerAxisDiscrete(const QDBusObjectPath &session_handle, - const QVariantMap &options, - uint axis, - int steps); - - void NotifyKeyboardKeycode(const QDBusObjectPath &session_handle, - const QVariantMap &options, - int keycode, - uint state); - - void NotifyKeyboardKeysym(const QDBusObjectPath &session_handle, - const QVariantMap &options, - int keysym, - uint state); - - void NotifyTouchDown(const QDBusObjectPath &session_handle, - const QVariantMap &options, - uint stream, - uint slot, - int x, - int y); - - void NotifyTouchMotion(const QDBusObjectPath &session_handle, - const QVariantMap &options, - uint stream, - uint slot, - int x, - int y); - - void NotifyTouchUp(const QDBusObjectPath &session_handle, - const QVariantMap &options, - uint slot); -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(RemoteDesktopPortal::DeviceTypes) - -#endif // XDG_DESKTOP_PORTAL_DDE_REMOTEDESKTOP_H - diff --git a/src/remotedesktopdialog.cpp b/src/remotedesktopdialog.cpp deleted file mode 100644 index d5bddd1..0000000 --- a/src/remotedesktopdialog.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright © 2018 Red Hat, Inc -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "remotedesktopdialog.h" -#include "ui_remotedesktopdialog.h" - -#include -#include -#include -#include -#include "klocalizedstring.h" - -Q_LOGGING_CATEGORY(XdgDesktopPortalDdeRemoteDesktopDialog, "xdp-dde-remote-desktop-dialog") - -RemoteDesktopDialog::RemoteDesktopDialog(const QString &appName, RemoteDesktopPortal::DeviceTypes deviceTypes, bool screenSharingEnabled, - bool multiple, QDialog *parent, Qt::WindowFlags flags) - : QDialog(parent, flags) - , m_dialog(new Ui::RemoteDesktopDialog) -{ - m_dialog->setupUi(this); - - m_dialog->screenCastWidget->setVisible(screenSharingEnabled); - if (screenSharingEnabled) { - connect(m_dialog->screenCastWidget, &QListWidget::itemDoubleClicked, this, &RemoteDesktopDialog::accept); - - if (multiple) { - m_dialog->screenCastWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); - } - } - - - m_dialog->screenCastWidget->itemAt(0, 0)->setSelected(true); - - m_dialog->keyboardCheckbox->setChecked(deviceTypes.testFlag(RemoteDesktopPortal::Keyboard)); - m_dialog->pointerCheckbox->setChecked(deviceTypes.testFlag(RemoteDesktopPortal::Pointer)); - m_dialog->touchScreenCheckbox->setChecked(deviceTypes.testFlag(RemoteDesktopPortal::TouchScreen)); - - connect(m_dialog->buttonBox, &QDialogButtonBox::accepted, this, &RemoteDesktopDialog::accept); - connect(m_dialog->buttonBox, &QDialogButtonBox::rejected, this, &RemoteDesktopDialog::reject); - - m_dialog->buttonBox->button(QDialogButtonBox::Ok)->setText(i18n("Share")); - m_dialog->buttonBox->button(QDialogButtonBox::Cancel)->setText(i18n("Cancel")); - - QString applicationName; - const QString desktopFile = appName + QLatin1String(".desktop"); - const QStringList desktopFileLocations = QStandardPaths::locateAll(QStandardPaths::ApplicationsLocation, desktopFile, QStandardPaths::LocateFile); - for (const QString &location : desktopFileLocations) { - QSettings settings(location, QSettings::IniFormat); - settings.beginGroup(QStringLiteral("Desktop Entry")); - if (settings.contains(QStringLiteral("X-GNOME-FullName"))) { - applicationName = settings.value(QStringLiteral("X-GNOME-FullName")).toString(); - } else { - applicationName = settings.value(QStringLiteral("Name")).toString(); - } - - if (!applicationName.isEmpty()) { - break; - } - } - - if (applicationName.isEmpty()) { - setWindowTitle(i18n("Select what to share with the requesting application")); - } else { - setWindowTitle(i18n("Select what to share with %1", applicationName)); - } -} - -RemoteDesktopDialog::~RemoteDesktopDialog() -{ - delete m_dialog; -} - -QList RemoteDesktopDialog::selectedScreens() const -{ - return m_dialog->screenCastWidget->selectedScreens(); -} - -RemoteDesktopPortal::DeviceTypes RemoteDesktopDialog::deviceTypes() const -{ - RemoteDesktopPortal::DeviceTypes types = RemoteDesktopPortal::None; - if (m_dialog->keyboardCheckbox->isChecked()) - types |= RemoteDesktopPortal::Keyboard; - if (m_dialog->pointerCheckbox->isChecked()) - types |= RemoteDesktopPortal::Pointer; - if (m_dialog->touchScreenCheckbox->isChecked()) - types |= RemoteDesktopPortal::TouchScreen; - - return types; -} diff --git a/src/remotedesktopdialog.h b/src/remotedesktopdialog.h deleted file mode 100644 index 8d81347..0000000 --- a/src/remotedesktopdialog.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright © 2018 Red Hat, Inc -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef XDG_DESKTOP_PORTAL_DDE_REMOTEDESKTOP_DIALOG_H -#define XDG_DESKTOP_PORTAL_DDE_REMOTEDESKTOP_DIALOG_H - -#include - -#include "remotedesktop.h" - -namespace Ui -{ -class RemoteDesktopDialog; -} - -class RemoteDesktopDialog : public QDialog -{ - Q_OBJECT -public: - RemoteDesktopDialog(const QString &appName, RemoteDesktopPortal::DeviceTypes deviceTypes, bool screenSharingEnabled = false, - bool multiple = false, QDialog *parent = nullptr, Qt::WindowFlags flags = {}); - ~RemoteDesktopDialog(); - - QList selectedScreens() const; - RemoteDesktopPortal::DeviceTypes deviceTypes() const; - -private: - Ui::RemoteDesktopDialog * m_dialog; -}; - -#endif // XDG_DESKTOP_PORTAL_DDE_REMOTEDESKTOP_DIALOG_H diff --git a/src/remotedesktopdialog.ui b/src/remotedesktopdialog.ui deleted file mode 100644 index ddfbf04..0000000 --- a/src/remotedesktopdialog.ui +++ /dev/null @@ -1,109 +0,0 @@ - - - RemoteDesktopDialog - - - - 0 - 0 - 452 - 286 - - - - Dialog - - - - - - QAbstractItemView::SingleSelection - - - - 48 - 48 - - - - false - - - - - - - - - Allow access to: - - - - - - - - - Pointer - - - true - - - - - - - Keyboard - - - true - - - - - - - Touch screen - - - true - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - ScreenCastWidget - QListWidget -
screencastwidget.h
-
-
- - -
diff --git a/src/screencast.cpp b/src/screencast.cpp deleted file mode 100644 index c18aaa8..0000000 --- a/src/screencast.cpp +++ /dev/null @@ -1,154 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "screencast.h" -#include "screenchooserdialog.h" -#include "session.h" -#include "waylandintegration.h" -#include "utils.h" - -#include - -Q_LOGGING_CATEGORY(XdgDesktopDDEScreenCastProtal, "xdg-dde-screencast") - -ScreenCastPortal::ScreenCastPortal(QObject *parent) - : QDBusAbstractAdaptor(parent) -{ - qCDebug(XdgDesktopDDEScreenCastProtal) << "init screencast"; -} - -ScreenCastPortal::~ScreenCastPortal() -{ -} - -uint ScreenCastPortal::CreateSession(const QDBusObjectPath &handle, - const QDBusObjectPath &session_handle, - const QString &app_id, - const QVariantMap &options, - QVariantMap &results) -{ - Q_UNUSED(results) - - qCDebug(XdgDesktopDDEScreenCastProtal) << "CreateSession called with parameters:"; - qCDebug(XdgDesktopDDEScreenCastProtal) << " handle: " << handle.path(); - qCDebug(XdgDesktopDDEScreenCastProtal) << " session_handle: " << session_handle.path(); - qCDebug(XdgDesktopDDEScreenCastProtal) << " app_id: " << app_id; - qCDebug(XdgDesktopDDEScreenCastProtal) << " options: " << options; - - Session *session = Session::createSession(this, Session::ScreenCast, app_id, session_handle.path()); - - if (!session) { - return 2; - } - - if (!WaylandIntegration::isStreamingAvailable()) { - qCWarning(XdgDesktopDDEScreenCastProtal) << "zkde_screencast_unstable_v1 does not seem to be available"; - return 2; - } - - connect(session, &Session::closed, [] () { - WaylandIntegration::stopAllStreaming(); - }); - - return 0; -} - -uint ScreenCastPortal::SelectSources(const QDBusObjectPath &handle, - const QDBusObjectPath &session_handle, - const QString &app_id, - const QVariantMap &options, - QVariantMap &results) -{ - Q_UNUSED(results) - - qCDebug(XdgDesktopDDEScreenCastProtal) << "SelectSource called with parameters:"; - qCDebug(XdgDesktopDDEScreenCastProtal) << " handle: " << handle.path(); - qCDebug(XdgDesktopDDEScreenCastProtal) << " session_handle: " << session_handle.path(); - qCDebug(XdgDesktopDDEScreenCastProtal) << " app_id: " << app_id; - qCDebug(XdgDesktopDDEScreenCastProtal) << " options: " << options; - - ScreenCastSession *session = qobject_cast(Session::getSession(session_handle.path())); - - if (!session) { - qCWarning(XdgDesktopDDEScreenCastProtal) << "Tried to select sources on non-existing session " << session_handle.path(); - return 2; - } - - session->setMultipleSources(options.value(QStringLiteral("multiple")).toBool()); - if (options.contains(QStringLiteral("types"))) { - session->setSourceTypes(SourceTypes(options.value(QStringLiteral("types")).toUInt())); - } - - // Might be also a RemoteDesktopSession - if (session->type() == Session::RemoteDesktop) { - RemoteDesktopSession *remoteDesktopSession = qobject_cast(session); - if (remoteDesktopSession) { - remoteDesktopSession->setScreenSharingEnabled(true); - } - } - - return 0; -} - -uint ScreenCastPortal::Start(const QDBusObjectPath &handle, - const QDBusObjectPath &session_handle, - const QString &app_id, - const QString &parent_window, - const QVariantMap &options, - QVariantMap &results) -{ - Q_UNUSED(results) - - qCDebug(XdgDesktopDDEScreenCastProtal) << "Start called with parameters:"; - qCDebug(XdgDesktopDDEScreenCastProtal) << " handle: " << handle.path(); - qCDebug(XdgDesktopDDEScreenCastProtal) << " session_handle: " << session_handle.path(); - qCDebug(XdgDesktopDDEScreenCastProtal) << " app_id: " << app_id; - qCDebug(XdgDesktopDDEScreenCastProtal) << " parent_window: " << parent_window; - qCDebug(XdgDesktopDDEScreenCastProtal) << " options: " << options; - - ScreenCastSession *session = qobject_cast(Session::getSession(session_handle.path())); - - if (!session) { - qCWarning(XdgDesktopDDEScreenCastProtal) << "Tried to call start on non-existing session " << session_handle.path(); - return 2; - } - - if (WaylandIntegration::screens().isEmpty()) { - qCWarning(XdgDesktopDDEScreenCastProtal) << "Failed to show dialog as there is no screen to select"; - return 2; - } - - QScopedPointer screenDialog(new ScreenChooserDialog(app_id, session->multipleSources())); - Utils::setParentWindow(screenDialog.data(), parent_window); - screenDialog->setSourceTypes(session->sourceTypes()); - connect(session, &Session::closed, screenDialog.data(), &ScreenChooserDialog::reject); - - if (screenDialog->exec()) { - const auto selectedScreens = screenDialog->selectedScreens(); - for (quint32 outputid : selectedScreens) { - if (!WaylandIntegration::startStreamingOutput(outputid, Screencasting::Hidden)) { - return 2; - } - } - const auto selectedWindows = screenDialog->selectedWindows(); - for (const QByteArray &winid : selectedWindows) { - if (!WaylandIntegration::startStreamingWindow(winid)) { - return 2; - } - } - - QVariant streams = WaylandIntegration::streams(); - - if (!streams.isValid()) { - qCWarning(XdgDesktopDDEScreenCastProtal) << "Pipewire stream is not ready to be streamed"; - return 2; - } - - results.insert(QStringLiteral("streams"), streams); - - return 0; - } - - return 1; -} diff --git a/src/screencast.h b/src/screencast.h deleted file mode 100644 index 382056e..0000000 --- a/src/screencast.h +++ /dev/null @@ -1,60 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#pragma once - -#include -#include - - -class ScreenCastPortal : public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.freedesktop.impl.portal.ScreenCast") - Q_PROPERTY(uint version READ version CONSTANT) - Q_PROPERTY(uint AvailableSourceTypes READ AvailableSourceTypes CONSTANT) - Q_PROPERTY(uint AvailableCursorModes READ AvailableCursorModes CONSTANT) -public: - enum SourceType { - Any = 0, - Monitor, - Window - }; - Q_ENUM(SourceType); - Q_DECLARE_FLAGS(SourceTypes, SourceType) - - enum CursorModes { - Hidden = 1, - Embedded = 2, - Metadata = 4, - }; - Q_ENUM(CursorModes); - - explicit ScreenCastPortal(QObject *parent); - ~ScreenCastPortal(); - - uint version() const { return 1; } - uint AvailableSourceTypes() const { return Monitor; }; - uint AvailableCursorModes() const { return Hidden | Embedded; }; - -public Q_SLOTS: - uint CreateSession(const QDBusObjectPath &handle, - const QDBusObjectPath &session_handle, - const QString &app_id, - const QVariantMap &options, - QVariantMap &results); - - uint SelectSources(const QDBusObjectPath &handle, - const QDBusObjectPath &session_handle, - const QString &app_id, - const QVariantMap &options, - QVariantMap &results); - - uint Start(const QDBusObjectPath &handle, - const QDBusObjectPath &session_handle, - const QString &app_id, - const QString &parent_window, - const QVariantMap &options, - QVariantMap &results); -}; diff --git a/src/screencasting.cpp b/src/screencasting.cpp deleted file mode 100644 index e50b2e0..0000000 --- a/src/screencasting.cpp +++ /dev/null @@ -1,118 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "screencasting.h" -#include "qwayland-zkde-screencast-unstable-v1.h" -#include -#include -#include -#include -#include - -using namespace KWayland::Client; - -class ScreencastingStreamPrivate : public QtWayland::zkde_screencast_stream_unstable_v1 -{ -public: - ScreencastingStreamPrivate(ScreencastingStream* q) : q(q) {} - ~ScreencastingStreamPrivate() { - close(); - q->deleteLater(); - } - - void zkde_screencast_stream_unstable_v1_created(uint32_t node) override { - m_nodeid = node; - Q_EMIT q->created(node); - } - - void zkde_screencast_stream_unstable_v1_closed() override { - Q_EMIT q->closed(); - } - - void zkde_screencast_stream_unstable_v1_failed(const QString &error) override { - Q_EMIT q->failed(error); - } - - uint m_nodeid = 0; - QPointer q; -}; - -ScreencastingStream::ScreencastingStream(QObject* parent) - : QObject(parent) - , d(new ScreencastingStreamPrivate(this)) -{ -} - -ScreencastingStream::~ScreencastingStream() = default; - -quint32 ScreencastingStream::nodeid() const -{ - return d->m_nodeid; -} - -class ScreencastingPrivate : public QtWayland::zkde_screencast_unstable_v1 -{ -public: - ScreencastingPrivate(Registry *registry, int id, int version, Screencasting *q) - : QtWayland::zkde_screencast_unstable_v1(*registry, id, version) - , q(q) - { - } - - ScreencastingPrivate(::zkde_screencast_unstable_v1* screencasting, Screencasting *q) - : QtWayland::zkde_screencast_unstable_v1(screencasting) - , q(q) - { - } - - ~ScreencastingPrivate() - { - destroy(); - } - - Screencasting *const q; -}; - -Screencasting::Screencasting(QObject* parent) - : QObject(parent) -{} - -Screencasting::Screencasting(Registry *registry, int id, int version, QObject* parent) - : QObject(parent) - , d(new ScreencastingPrivate(registry, id, version, this)) -{} - -Screencasting::~Screencasting() = default; - -ScreencastingStream* Screencasting::createOutputStream(Output* output, CursorMode mode) -{ - auto stream = new ScreencastingStream(this); - stream->setObjectName(output->model()); - stream->d->init(d->stream_output(*output, mode)); - return stream; -} - -ScreencastingStream* Screencasting::createWindowStream(PlasmaWindow *window, CursorMode mode) -{ - auto stream = createWindowStream(QString::number(window->internalId()), mode); - stream->setObjectName(window->appId()); - return stream; -} - -ScreencastingStream* Screencasting::createWindowStream(const QString &uuid, CursorMode mode) -{ - auto stream = new ScreencastingStream(this); - stream->d->init(d->stream_window(uuid, mode)); - return stream; -} - -void Screencasting::setup(::zkde_screencast_unstable_v1* screencasting) -{ - d.reset(new ScreencastingPrivate(screencasting, this)); -} - -void Screencasting::destroy() -{ - d.reset(nullptr); -} diff --git a/src/screencasting.h b/src/screencasting.h deleted file mode 100644 index d45705d..0000000 --- a/src/screencasting.h +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#pragma once - -#include -#include -#include -#include - -struct zkde_screencast_unstable_v1; - -namespace KWayland -{ -namespace Client -{ -class PlasmaWindow; -class Registry; -class Output; -} -} - -class ScreencastingPrivate; -class ScreencastingSourcePrivate; -class ScreencastingStreamPrivate; -class ScreencastingStream : public QObject -{ - Q_OBJECT -public: - ScreencastingStream(QObject* parent); - ~ScreencastingStream() override; - - quint32 nodeid() const; - -Q_SIGNALS: - void created(quint32 nodeid); - void failed(const QString &error); - void closed(); - -private: - friend class Screencasting; - QScopedPointer d; -}; - -class Screencasting : public QObject -{ - Q_OBJECT -public: - explicit Screencasting(QObject *parent = nullptr); - explicit Screencasting(KWayland::Client::Registry *registry, int id, int version, QObject *parent = nullptr); - ~Screencasting() override; - - enum CursorMode { - Hidden = 1, - Embedded = 2, - Metadata = 4, - }; - Q_ENUM(CursorMode); - - ScreencastingStream* createOutputStream(KWayland::Client::Output* output, CursorMode mode); - ScreencastingStream* createWindowStream(KWayland::Client::PlasmaWindow* window, CursorMode mode); - ScreencastingStream* createWindowStream(const QString &uuid, CursorMode mode); - - void setup(zkde_screencast_unstable_v1* screencasting); - void destroy(); - -Q_SIGNALS: - void initialized(); - void removed(); - void sourcesChanged(); - -private: - QScopedPointer d; -}; diff --git a/src/screencastwidget.cpp b/src/screencastwidget.cpp deleted file mode 100644 index 44711f9..0000000 --- a/src/screencastwidget.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright © 2018 Red Hat, Inc -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "screencastwidget.h" -#include "waylandintegration.h" - -#include - -ScreenCastWidget::ScreenCastWidget(QWidget *parent) - : QListWidget(parent) -{ - QMapIterator it(WaylandIntegration::screens()); - while (it.hasNext()) { - it.next(); - QListWidgetItem *widgetItem = new QListWidgetItem(this); - widgetItem->setData(Qt::UserRole, it.key()); - if (it.value().outputType() == WaylandIntegration::WaylandOutput::Laptop) { - widgetItem->setIcon(QIcon::fromTheme(QStringLiteral("computer-laptop"))); - widgetItem->setText(i18n("Laptop screen\nModel: %1", it.value().model())); - } else if (it.value().outputType() == WaylandIntegration::WaylandOutput::Monitor) { - widgetItem->setIcon(QIcon::fromTheme(QStringLiteral("video-display"))); - widgetItem->setText(i18n("Manufacturer: %1\nModel: %2", it.value().manufacturer(), it.value().model())); - } else { - widgetItem->setIcon(QIcon::fromTheme(QStringLiteral("video-television"))); - widgetItem->setText(i18n("Manufacturer: %1\nModel: %2", it.value().manufacturer(), it.value().model())); - } - } -} - -ScreenCastWidget::~ScreenCastWidget() -{ -} - -QList ScreenCastWidget::selectedScreens() const -{ - QList selectedScreens; - - const auto selectedItems = this->selectedItems(); - for (QListWidgetItem *item : selectedItems) { - selectedScreens << item->data(Qt::UserRole).toUInt(); - } - - return selectedScreens; -} diff --git a/src/screencastwidget.h b/src/screencastwidget.h deleted file mode 100644 index 72fd3d2..0000000 --- a/src/screencastwidget.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright © 2018 Red Hat, Inc -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef XDG_DESKTOP_PORTAL_DDE_SCREENCAST_WIDGET_H -#define XDG_DESKTOP_PORTAL_DDE_SCREENCAST_WIDGET_H - -#include - -class ScreenCastWidget : public QListWidget -{ - Q_OBJECT -public: - ScreenCastWidget(QWidget *parent = nullptr); - ~ScreenCastWidget(); - - QList selectedScreens() const; -}; - -#endif // XDG_DESKTOP_PORTAL_DDE_SCREENCAST_WIDGET_H - diff --git a/src/screenchooserdialog.cpp b/src/screenchooserdialog.cpp deleted file mode 100644 index 23b104b..0000000 --- a/src/screenchooserdialog.cpp +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright © 2018 Red Hat, Inc -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "screenchooserdialog.h" -#include "ui_screenchooserdialog.h" -#include "waylandintegration.h" - -#include -#include -#include -#include -#include -#include -#include - -class FilteredWindowModel : public QSortFilterProxyModel -{ -public: - FilteredWindowModel(QObject* parent) : QSortFilterProxyModel(parent) - {} - - bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override { - if (source_parent.isValid()) - return false; - - const auto idx = sourceModel()->index(source_row, 0); - using KWayland::Client::PlasmaWindowModel; - - return !idx.data(PlasmaWindowModel::SkipTaskbar).toBool() - && !idx.data(PlasmaWindowModel::SkipSwitcher).toBool() - && idx.data(PlasmaWindowModel::Pid) != QCoreApplication::applicationPid(); - } -}; - -ScreenChooserDialog::ScreenChooserDialog(const QString &appName, bool multiple, QDialog *parent, Qt::WindowFlags flags) - : QDialog(parent, flags) - , m_multiple(multiple) - , m_dialog(new Ui::ScreenChooserDialog) -{ - m_dialog->setupUi(this); - - const auto selection = multiple ? QAbstractItemView::ExtendedSelection : QAbstractItemView::SingleSelection; - m_dialog->screenView->setSelectionMode(selection); - m_dialog->windowsView->setSelectionMode(selection); - - auto model = new KWayland::Client::PlasmaWindowModel(WaylandIntegration::plasmaWindowManagement()); - auto proxy = new FilteredWindowModel(this); - proxy->setSourceModel(model); - m_dialog->windowsView->setModel(proxy); - - connect(m_dialog->buttonBox, &QDialogButtonBox::accepted, this, &ScreenChooserDialog::accept); - connect(m_dialog->buttonBox, &QDialogButtonBox::rejected, this, &ScreenChooserDialog::reject); - connect(m_dialog->screenView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ScreenChooserDialog::selectionChanged); - connect(m_dialog->windowsView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ScreenChooserDialog::selectionChanged); - connect(m_dialog->screenView, &QListWidget::doubleClicked, this, &ScreenChooserDialog::accept); - connect(m_dialog->windowsView, &QListView::doubleClicked, this, &ScreenChooserDialog::accept); - - auto okButton = m_dialog->buttonBox->button(QDialogButtonBox::Ok); - okButton->setText(i18n("Share")); - okButton->setEnabled(false); - - QString applicationName; - const QString desktopFile = appName + QLatin1String(".desktop"); - const QStringList desktopFileLocations = QStandardPaths::locateAll(QStandardPaths::ApplicationsLocation, desktopFile, QStandardPaths::LocateFile); - for (const QString &location : desktopFileLocations) { - QSettings settings(location, QSettings::IniFormat); - settings.beginGroup(QStringLiteral("Desktop Entry")); - if (settings.contains(QStringLiteral("X-GNOME-FullName"))) { - applicationName = settings.value(QStringLiteral("X-GNOME-FullName")).toString(); - } else { - applicationName = settings.value(QStringLiteral("Name")).toString(); - } - - if (!applicationName.isEmpty()) { - break; - } - } - - if (applicationName.isEmpty()) { - setWindowTitle(i18n("Select screen to share with the requesting application")); - } else { - setWindowTitle(i18n("Select screen to share with %1", applicationName)); - } -} - -ScreenChooserDialog::~ScreenChooserDialog() -{ - delete m_dialog; -} - -void ScreenChooserDialog::selectionChanged(const QItemSelection &selected) -{ - if (!m_multiple && !selected.isEmpty()) { - if (selected.constFirst().model() == m_dialog->windowsView->model()) - m_dialog->screenView->clearSelection(); - else - m_dialog->windowsView->clearSelection(); - } - - auto okButton = m_dialog->buttonBox->button(QDialogButtonBox::Ok); - const auto count = m_dialog->screenView->selectionModel()->hasSelection() - + m_dialog->windowsView->selectionModel()->hasSelection(); - okButton->setEnabled(m_multiple ? count > 0 : count == 1); -} - -void ScreenChooserDialog::setSourceTypes(ScreenCastPortal::SourceTypes types) -{ -// m_dialog->windowsTab->setEnabled(types & ScreenCastPortal::Window); -// m_dialog->screensTab->setEnabled(types & ScreenCastPortal::Monitor); - m_dialog->tabWidget->setTabEnabled(m_dialog->tabWidget->indexOf(m_dialog->windowsTab),types & ScreenCastPortal::Window); - m_dialog->tabWidget->setTabEnabled(m_dialog->tabWidget->indexOf(m_dialog->screensTab),types & ScreenCastPortal::Monitor); - -} - -QList ScreenChooserDialog::selectedScreens() const -{ - return m_dialog->screenView->selectedScreens(); -} - -QList ScreenChooserDialog::selectedWindows() const -{ - const auto idxs = m_dialog->windowsView->selectionModel()->selectedIndexes(); - - QList ret; - ret.reserve(idxs.count()); - for (const auto &idx : idxs) { - //ret += idx.data(KWayland::Client::PlasmaWindowModel::Uuid).toByteArray(); - } - return ret; -} diff --git a/src/screenchooserdialog.h b/src/screenchooserdialog.h deleted file mode 100644 index a071b71..0000000 --- a/src/screenchooserdialog.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright © 2018 Red Hat, Inc -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef XDG_DESKTOP_PORTAL_DDE_SCREENCHOOSER_DIALOG_H -#define XDG_DESKTOP_PORTAL_DDE_SCREENCHOOSER_DIALOG_H - -#include -#include "screencast.h" - -namespace Ui -{ -class ScreenChooserDialog; -} -class QItemSelection; - -class ScreenChooserDialog : public QDialog -{ - Q_OBJECT -public: - ScreenChooserDialog(const QString &appName, bool multiple, QDialog *parent = nullptr, Qt::WindowFlags flags = {}); - ~ScreenChooserDialog(); - - void setSourceTypes(ScreenCastPortal::SourceTypes types); - - QList selectedScreens() const; - QList selectedWindows() const; - -private: - void selectionChanged(const QItemSelection &selected); - - const bool m_multiple; - Ui::ScreenChooserDialog *m_dialog; -}; - -#endif // XDG_DESKTOP_PORTAL_DDE_SCREENCHOOSER_DIALOG_H diff --git a/src/screenchooserdialog.ui b/src/screenchooserdialog.ui deleted file mode 100644 index 6acb939..0000000 --- a/src/screenchooserdialog.ui +++ /dev/null @@ -1,73 +0,0 @@ - - - ScreenChooserDialog - - - - 0 - 0 - 400 - 300 - - - - Dialog - - - - - - 0 - - - - Screens - - - - - - - 48 - 48 - - - - - - - - - Windows - - - - - - true - - - - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - ScreenCastWidget - QListWidget -
screencastwidget.h
-
-
- - -
diff --git a/src/session.cpp b/src/session.cpp deleted file mode 100644 index e6b64a0..0000000 --- a/src/session.cpp +++ /dev/null @@ -1,201 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "session.h" -#include "ddesktopportal.h" - -#include -#include -#include -#include -#include -#include -#include - -Q_LOGGING_CATEGORY(XdgDesktopDDESession, "xdg-dde-session") - -SessionPortal::SessionPortal(QObject *parent) - : QDBusAbstractAdaptor(parent) -{ -} - -void SessionPortal::Close() -{ - qCDebug(XdgDesktopDDESession) << "Closed"; -} - -static QMap sessionList; - -Session::Session(QObject *parent, const QString &appId, const QString &path) - : QDBusVirtualObject(parent) - , m_appId(appId) - , m_path(path) -{ -} - -Session::~Session() -{ -} - -bool Session::handleMessage(const QDBusMessage &message, const QDBusConnection &connection) -{ - Q_UNUSED(connection); - - if (message.path() != m_path) { - return false; - } - - /* Check to make sure we're getting properties on our interface */ - if (message.type() != QDBusMessage::MessageType::MethodCallMessage) { - return false; - } - - qCDebug(XdgDesktopDDESession) << message.interface(); - qCDebug(XdgDesktopDDESession) << message.member(); - qCDebug(XdgDesktopDDESession) << message.path(); - - if (message.interface() == QLatin1String("org.freedesktop.impl.portal.Session")) { - if (message.member() == QLatin1String("Close")) { - Q_EMIT closed(); - QDBusMessage reply = message.createReply(); - return connection.send(reply); - } - } else if (message.interface() == QLatin1String("org.freedesktop.DBus.Properties")) { - if (message.member() == QLatin1String("Get")) { - if (message.arguments().count() == 2) { - const QString interface = message.arguments().at(0).toString(); - const QString property = message.arguments().at(1).toString(); - - if (interface == QLatin1String("org.freedesktop.impl.portal.Session") && - property == QLatin1String("version")) { - QList arguments; - arguments << 1; - - QDBusMessage reply = message.createReply(); - reply.setArguments(arguments); - return connection.send(reply); - } - } - } - } - - return false; -} - -QString Session::introspect(const QString &path) const -{ - QString nodes; - - if (path.startsWith(QLatin1String("/org/freedesktop/portal/desktop/session/"))) { - nodes = QStringLiteral( - "" - " " - " " - "" - "" - "" - ""); - } - - qCDebug(XdgDesktopDDESession) << nodes; - - return nodes; -} - -bool Session::close() -{ - QDBusMessage reply = QDBusMessage::createSignal(m_path, QStringLiteral("org.freedesktop.impl.portal.Session"), QStringLiteral("Closed")); - return QDBusConnection::sessionBus().send(reply); -} - -Session * Session::createSession(QObject *parent, SessionType type, const QString &appId, const QString &path) -{ - QDBusConnection sessionBus = QDBusConnection::sessionBus(); - - Session *session = nullptr; - if (type == ScreenCast) { - session = new ScreenCastSession(parent, appId, path); - } else { - session = new RemoteDesktopSession(parent, appId, path); - } - - if (sessionBus.registerVirtualObject(path, session, QDBusConnection::VirtualObjectRegisterOption::SubPath)) { - connect(session, &Session::closed, [session, path] () { - sessionList.remove(path); - QDBusConnection::sessionBus().unregisterObject(path); - session->deleteLater(); - }); - sessionList.insert(path, session); - return session; - } else { - qCDebug(XdgDesktopDDESession) << sessionBus.lastError().message(); - qCDebug(XdgDesktopDDESession) << "Failed to register session object: " << path; - session->deleteLater(); - return nullptr; - } -} - -Session * Session::getSession(const QString &sessionHandle) -{ - return sessionList.value(sessionHandle); -} - -ScreenCastSession::ScreenCastSession(QObject *parent, const QString &appId, const QString &path) - : Session(parent, appId, path) -{ -} - -ScreenCastSession::~ScreenCastSession() -{ -} - -ScreenCastPortal::SourceTypes ScreenCastSession::sourceTypes() const { - return m_sourceTypes; -} - -void ScreenCastSession::setSourceTypes(ScreenCastPortal::SourceTypes sourcetypes) { - m_sourceTypes = sourcetypes; -} - - - -bool ScreenCastSession::multipleSources() const -{ - return m_multipleSources; -} - -void ScreenCastSession::setMultipleSources(bool multipleSources) -{ - m_multipleSources = multipleSources; -} - -RemoteDesktopSession::RemoteDesktopSession(QObject *parent, const QString &appId, const QString &path) - : ScreenCastSession(parent, appId, path) - , m_screenSharingEnabled(false) -{ -} - -RemoteDesktopSession::~RemoteDesktopSession() -{ -} - -RemoteDesktopPortal::DeviceTypes RemoteDesktopSession::deviceTypes() const -{ - return m_deviceTypes; -} - -void RemoteDesktopSession::setDeviceTypes(RemoteDesktopPortal::DeviceTypes deviceTypes) -{ - m_deviceTypes = deviceTypes; -} - -bool RemoteDesktopSession::screenSharingEnabled() const -{ - return m_screenSharingEnabled; -} - -void RemoteDesktopSession::setScreenSharingEnabled(bool enabled) -{ - m_screenSharingEnabled = enabled; -} diff --git a/src/session.h b/src/session.h deleted file mode 100644 index 02fa76b..0000000 --- a/src/session.h +++ /dev/null @@ -1,102 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#pragma once - - -#include -#include - -#include "remotedesktop.h" -#include "screencast.h" -#include -#include - -class SessionPortal : public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.freedesktop.impl.portal.Session") - Q_PROPERTY(uint version READ version CONSTANT) - inline uint version() const { return 1; } - -public: - explicit SessionPortal(QObject *parent); - ~SessionPortal() = default; - -public slots: - void Close(); - -signals: - void Closed(); -}; - -class Session : public QDBusVirtualObject -{ - Q_OBJECT -public: - explicit Session(QObject *parent = nullptr, const QString &appId = QString(), const QString &path = QString()); - ~Session(); - - enum SessionType { - ScreenCast = 0, - RemoteDesktop = 1 - }; - - bool handleMessage(const QDBusMessage &message, const QDBusConnection &connection) override; - QString introspect(const QString &path) const override; - - bool close(); - virtual SessionType type() const = 0; - - static Session *createSession(QObject *parent, SessionType type, const QString &appId, const QString &path); - static Session *getSession(const QString &sessionHandle); - -Q_SIGNALS: - void closed(); - -private: - const QString m_appId; - const QString m_path; -}; - -class ScreenCastSession : public Session -{ - Q_OBJECT -public: - explicit ScreenCastSession(QObject *parent = nullptr, const QString &appId = QString(), const QString &path = QString()); - ~ScreenCastSession(); - - bool multipleSources() const; - void setMultipleSources(bool multipleSources); - ScreenCastPortal::SourceTypes sourceTypes() const; - void setSourceTypes(ScreenCastPortal::SourceTypes sourcetypes); - SessionType type() const override { return SessionType::ScreenCast; } - -private: - bool m_multipleSources; - ScreenCastPortal::SourceTypes m_sourceTypes = ScreenCastPortal::SourceTypes(ScreenCastPortal::SourceType::Any); - // TODO type -}; - -class RemoteDesktopSession : public ScreenCastSession -{ - Q_OBJECT -public: - explicit RemoteDesktopSession(QObject *parent = nullptr, const QString &appId = QString(), const QString &path = QString()); - ~RemoteDesktopSession(); - - RemoteDesktopPortal::DeviceTypes deviceTypes() const; - void setDeviceTypes(RemoteDesktopPortal::DeviceTypes deviceTypes); - - bool screenSharingEnabled() const; - void setScreenSharingEnabled(bool enabled); - - SessionType type() const override { return SessionType::RemoteDesktop; } - -private: - bool m_screenSharingEnabled; - RemoteDesktopPortal::DeviceTypes m_deviceTypes; -}; - - diff --git a/src/waylandintegration.cpp b/src/waylandintegration.cpp deleted file mode 100644 index 36183a5..0000000 --- a/src/waylandintegration.cpp +++ /dev/null @@ -1,485 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "waylandintegration.h" -#include "waylandintegration_p.h" -#include "screencasting.h" -#include "screencast.h" - -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include - -// KWayland -#include -#include -#include -#include - -// system -#include -#include - -#include -#include - -Q_LOGGING_CATEGORY(XdgDesktopPortalDdeWaylandIntegration, "xdp-dde-wayland-integration") - -Q_GLOBAL_STATIC(WaylandIntegration::WaylandIntegrationPrivate, globalWaylandIntegration) - -static QDebug operator<<(QDebug dbg, const WaylandIntegration::WaylandIntegrationPrivate::Stream &c) -{ - dbg.nospace() << "Stream("<< c.map << ", " << c.nodeId << ")"; - return dbg.space(); - -} - -void WaylandIntegration::init() -{ - globalWaylandIntegration->initWayland(); -} - -void WaylandIntegration::authenticate() -{ - globalWaylandIntegration->authenticate(); -} - -bool WaylandIntegration::isStreamingEnabled() -{ - return globalWaylandIntegration->isStreamingEnabled(); -} - -bool WaylandIntegration::isStreamingAvailable() -{ - return globalWaylandIntegration->isStreamingAvailable(); -} - -void WaylandIntegration::startStreamingInput() -{ - globalWaylandIntegration->startStreamingInput(); -} - -bool WaylandIntegration::startStreamingOutput(quint32 outputName, Screencasting::CursorMode mode) -{ - return globalWaylandIntegration->startStreamingOutput(outputName, mode); -} - -bool WaylandIntegration::startStreamingWindow(const QByteArray &winid) -{ - return globalWaylandIntegration->startStreamingWindow(winid); -} - -void WaylandIntegration::stopAllStreaming() -{ - globalWaylandIntegration->stopAllStreaming(); -} - -void WaylandIntegration::requestPointerButtonPress(quint32 linuxButton) -{ - globalWaylandIntegration->requestPointerButtonPress(linuxButton); -} - -void WaylandIntegration::requestPointerButtonRelease(quint32 linuxButton) -{ - globalWaylandIntegration->requestPointerButtonRelease(linuxButton); -} - -void WaylandIntegration::requestPointerMotion(const QSizeF &delta) -{ - globalWaylandIntegration->requestPointerMotion(delta); -} - -void WaylandIntegration::requestPointerMotionAbsolute(const QPointF &pos) -{ - globalWaylandIntegration->requestPointerMotionAbsolute(pos); -} - -void WaylandIntegration::requestPointerAxisDiscrete(Qt::Orientation axis, qreal delta) -{ - globalWaylandIntegration->requestPointerAxisDiscrete(axis, delta); -} - -void WaylandIntegration::requestKeyboardKeycode(int keycode, bool state) -{ - globalWaylandIntegration->requestKeyboardKeycode(keycode, state); -} - -QMap WaylandIntegration::screens() -{ - return globalWaylandIntegration->screens(); -} - -QVariant WaylandIntegration::streams() -{ - return globalWaylandIntegration->streams(); -} - -// Thank you kscreen -void WaylandIntegration::WaylandOutput::setOutputType(const QString &type) -{ - const auto embedded = { QLatin1String("LVDS"), - QLatin1String("IDP"), - QLatin1String("EDP"), - QLatin1String("LCD") }; - - for (const QLatin1String &pre : embedded) { - if (type.startsWith(pre, Qt::CaseInsensitive)) { - m_outputType = OutputType::Laptop; - return; - } - } - - if (type.contains(QLatin1String("VGA")) || type.contains(QLatin1String("DVI")) || type.contains(QLatin1String("HDMI")) || type.contains(QLatin1String("Panel")) || - type.contains(QLatin1String("DisplayPort")) || type.startsWith(QLatin1String("DP")) || type.contains(QLatin1String("unknown"))) { - m_outputType = OutputType::Monitor; - } else if (type.contains(QLatin1String("TV"))) { - m_outputType = OutputType::Television; - } else { - m_outputType = OutputType::Monitor; - } -} - -const QDBusArgument &operator >> (const QDBusArgument &arg, WaylandIntegration::WaylandIntegrationPrivate::Stream &stream) -{ - arg.beginStructure(); - arg >> stream.nodeId; - - arg.beginMap(); - while (!arg.atEnd()) { - QString key; - QVariant map; - arg.beginMapEntry(); - arg >> key >> map; - arg.endMapEntry(); - stream.map.insert(key, map); - } - arg.endMap(); - arg.endStructure(); - - return arg; -} - -const QDBusArgument &operator << (QDBusArgument &arg, const WaylandIntegration::WaylandIntegrationPrivate::Stream &stream) -{ - arg.beginStructure(); - arg << stream.nodeId; - arg << stream.map; - arg.endStructure(); - - return arg; -} - -Q_DECLARE_METATYPE(WaylandIntegration::WaylandIntegrationPrivate::Stream) -Q_DECLARE_METATYPE(WaylandIntegration::WaylandIntegrationPrivate::Streams) - -KWayland::Client::PlasmaWindowManagement * WaylandIntegration::plasmaWindowManagement() -{ - return globalWaylandIntegration->plasmaWindowManagement(); -} - -WaylandIntegration::WaylandIntegration * WaylandIntegration::waylandIntegration() -{ - return globalWaylandIntegration; -} - -WaylandIntegration::WaylandIntegrationPrivate::WaylandIntegrationPrivate() - : WaylandIntegration() - , m_registryInitialized(false) - , m_connection(nullptr) - , m_queue(nullptr) - , m_registry(nullptr) - , m_fakeInput(nullptr) - , m_screencasting(nullptr) -{ - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); -} - -WaylandIntegration::WaylandIntegrationPrivate::~WaylandIntegrationPrivate() = default; - -bool WaylandIntegration::WaylandIntegrationPrivate::isStreamingEnabled() const -{ - return !m_streams.isEmpty(); -} - -bool WaylandIntegration::WaylandIntegrationPrivate::isStreamingAvailable() const -{ - return m_screencasting; -} - -void WaylandIntegration::WaylandIntegrationPrivate::bindOutput(int outputName, int outputVersion) -{ - KWayland::Client::Output *output = new KWayland::Client::Output(this); - output->setup(m_registry->bindOutput(outputName, outputVersion)); - m_bindOutputs << output; -} - -void WaylandIntegration::WaylandIntegrationPrivate::startStreamingInput() -{ - m_streamInput = true; -} - -bool WaylandIntegration::WaylandIntegrationPrivate::startStreamingWindow(const QByteArray &winid) -{ - return startStreaming(m_screencasting->createWindowStream(QString::fromUtf8(winid), Screencasting::Hidden), {}); -} - -bool WaylandIntegration::WaylandIntegrationPrivate::startStreamingOutput(quint32 outputName, Screencasting::CursorMode mode) -{ - auto output = m_outputMap.value(outputName).output(); - - return startStreaming(m_screencasting->createOutputStream(output.data(), mode), output); -} - -bool WaylandIntegration::WaylandIntegrationPrivate::startStreaming(ScreencastingStream *stream, QSharedPointer output) -{ - QEventLoop loop; - bool streamReady = false; - connect(stream, &ScreencastingStream::failed, this, [&] (const QString &error) { - qCWarning(XdgDesktopPortalDdeWaylandIntegration) << "failed to start streaming" << stream << error; - - KNotification *notification = new KNotification(QStringLiteral("screencastfailure"), KNotification::CloseOnTimeout); - notification->setTitle(i18n("Failed to start screencasting")); - notification->setText(error); - notification->setIconName(QStringLiteral("dialog-error")); - notification->sendEvent(); - - streamReady = false; - loop.quit(); - }); - connect(stream, &ScreencastingStream::created, this, [&] (uint32_t nodeid) { - Stream s; - s.stream = stream; - s.nodeId = nodeid; - if (output) { - m_streamedScreenPosition = output->globalPosition(); - s.map = { - {QLatin1String("size"), output->pixelSize()}, - {QLatin1String("source_type"), static_cast(ScreenCastPortal::Monitor)}, - {QLatin1String("screenpositionX"),m_streamedScreenPosition.x()}, - {QLatin1String("screenpositionY"),m_streamedScreenPosition.y()} - }; - } else { - s.map = { - {QLatin1String("source_type"), static_cast(ScreenCastPortal::Window)}, - {QLatin1String("screenpositionX"),0}, - {QLatin1String("screenpositionY"),0} - }; - } - m_streams.append(s); - startStreamingInput(); - - connect(stream, &ScreencastingStream::closed, this, [this, nodeid] { stopStreaming(nodeid); }); - streamReady = true; - loop.quit(); - }); - QTimer::singleShot(3000, &loop, &QEventLoop::quit); - loop.exec(); - - return streamReady; -} - -void WaylandIntegration::WaylandIntegrationPrivate::Stream::close() -{ - stream->deleteLater(); -} - -void WaylandIntegration::WaylandIntegrationPrivate::stopAllStreaming() -{ - for (auto & stream : m_streams) { - stream.close(); - } - m_streams.clear(); - - m_streamInput = false; - // First unbound outputs and destroy remote access manager so we no longer receive buffers -} - -void WaylandIntegration::WaylandIntegrationPrivate::stopStreaming(uint32_t nodeid) -{ - for(auto it = m_streams.begin(), itEnd = m_streams.end(); it != itEnd; ++it) { - if (it->nodeId == nodeid) { - m_streams.erase(it); - break; - } - } - - if (m_streams.isEmpty()) { - stopAllStreaming(); - } -} - -void WaylandIntegration::WaylandIntegrationPrivate::requestPointerButtonPress(quint32 linuxButton) -{ - if (m_streamInput && m_fakeInput) { - m_fakeInput->requestPointerButtonPress(linuxButton); - } -} - -void WaylandIntegration::WaylandIntegrationPrivate::requestPointerButtonRelease(quint32 linuxButton) -{ - if (m_streamInput && m_fakeInput) { - m_fakeInput->requestPointerButtonRelease(linuxButton); - } -} - -void WaylandIntegration::WaylandIntegrationPrivate::requestPointerMotion(const QSizeF &delta) -{ - if (m_streamInput && m_fakeInput) { - m_fakeInput->requestPointerMove(delta); - } -} - -void WaylandIntegration::WaylandIntegrationPrivate::requestPointerMotionAbsolute(const QPointF &pos) -{ - if (m_streamInput && m_fakeInput) { - m_fakeInput->requestPointerMoveAbsolute(pos + m_streamedScreenPosition); - } -} - -void WaylandIntegration::WaylandIntegrationPrivate::requestPointerAxisDiscrete(Qt::Orientation axis, qreal delta) -{ - if (m_streamInput && m_fakeInput) { - m_fakeInput->requestPointerAxis(axis, delta); - } -} - -void WaylandIntegration::WaylandIntegrationPrivate::requestKeyboardKeycode(int keycode, bool state) -{ - if (m_streamInput && m_fakeInput) { - if (state) { - m_fakeInput->requestKeyboardKeyPress(keycode); - } else { - m_fakeInput->requestKeyboardKeyRelease(keycode); - } - } -} - -QMap WaylandIntegration::WaylandIntegrationPrivate::screens() -{ - return m_outputMap; -} - -QVariant WaylandIntegration::WaylandIntegrationPrivate::streams() -{ - return QVariant::fromValue(m_streams); -} - -void WaylandIntegration::WaylandIntegrationPrivate::authenticate() -{ - if (!m_waylandAuthenticationRequested) { - m_fakeInput->authenticate(i18n("xdg-desktop-portals-kde"), i18n("Remote desktop")); - m_waylandAuthenticationRequested = true; - } -} - -KWayland::Client::PlasmaWindowManagement * WaylandIntegration::WaylandIntegrationPrivate::plasmaWindowManagement() -{ - return m_windowManagement; -} - -void WaylandIntegration::WaylandIntegrationPrivate::initWayland() -{ - m_thread = new QThread(this); - m_connection = new KWayland::Client::ConnectionThread; - - connect(m_connection, &KWayland::Client::ConnectionThread::connected, this, &WaylandIntegrationPrivate::setupRegistry, Qt::QueuedConnection); - connect(m_connection, &KWayland::Client::ConnectionThread::connectionDied, this, [this] { - if (m_queue) { - delete m_queue; - m_queue = nullptr; - } - - m_connection->deleteLater(); - m_connection = nullptr; - - if (m_thread) { - m_thread->quit(); - if (!m_thread->wait(3000)) { - m_thread->terminate(); - m_thread->wait(); - } - delete m_thread; - m_thread = nullptr; - } - }); - connect(m_connection, &KWayland::Client::ConnectionThread::failed, this, [this] { - m_thread->quit(); - m_thread->wait(); - }); - - m_thread->start(); - m_connection->moveToThread(m_thread); - m_connection->initConnection(); -} - -void WaylandIntegration::WaylandIntegrationPrivate::addOutput(quint32 name, quint32 version) -{ - QSharedPointer output(new KWayland::Client::Output(this)); - output->setup(m_registry->bindOutput(name, version)); - - connect(output.data(), &KWayland::Client::Output::changed, this, [this, name, version, output] () { - qCDebug(XdgDesktopPortalDdeWaylandIntegration) << "Adding output:"; - qCDebug(XdgDesktopPortalDdeWaylandIntegration) << " manufacturer: " << output->manufacturer(); - qCDebug(XdgDesktopPortalDdeWaylandIntegration) << " model: " << output->model(); - qCDebug(XdgDesktopPortalDdeWaylandIntegration) << " resolution: " << output->pixelSize(); - - WaylandOutput portalOutput; - portalOutput.setOutput(output); - portalOutput.setWaylandOutputName(name); - portalOutput.setWaylandOutputVersion(version); - - m_outputMap.insert(name, portalOutput); - }); -} - -void WaylandIntegration::WaylandIntegrationPrivate::removeOutput(quint32 name) -{ - WaylandOutput output = m_outputMap.take(name); - qCDebug(XdgDesktopPortalDdeWaylandIntegration) << "Removing output:"; - qCDebug(XdgDesktopPortalDdeWaylandIntegration) << " manufacturer: " << output.manufacturer(); - qCDebug(XdgDesktopPortalDdeWaylandIntegration) << " model: " << output.model(); -} - -void WaylandIntegration::WaylandIntegrationPrivate::setupRegistry() -{ - m_queue = new KWayland::Client::EventQueue(this); - m_queue->setup(m_connection); - - m_registry = new KWayland::Client::Registry(this); - - connect(m_registry, &KWayland::Client::Registry::fakeInputAnnounced, this, [this] (quint32 name, quint32 version) { - m_fakeInput = m_registry->createFakeInput(name, version, this); - }); - connect(m_registry, &KWayland::Client::Registry::outputAnnounced, this, &WaylandIntegrationPrivate::addOutput); - connect(m_registry, &KWayland::Client::Registry::outputRemoved, this, &WaylandIntegrationPrivate::removeOutput); - - connect(m_registry, &KWayland::Client::Registry::interfaceAnnounced, this, [this] (const QByteArray &interfaceName, quint32 name, quint32 version) { - if (interfaceName != "zkde_screencast_unstable_v1") - return; - m_screencasting = new Screencasting(m_registry, name, version, this); - }); - connect(m_registry, &KWayland::Client::Registry::plasmaWindowManagementAnnounced, this, [this] (quint32 name, quint32 version) { - m_windowManagement = m_registry->createPlasmaWindowManagement(name, version, this); - Q_EMIT waylandIntegration()->plasmaWindowManagementInitialized(); - }); - - connect(m_registry, &KWayland::Client::Registry::interfacesAnnounced, this, [this] { - m_registryInitialized = true; - qCDebug(XdgDesktopPortalDdeWaylandIntegration) << "Registry initialized"; - }); - - m_registry->create(m_connection); - m_registry->setEventQueue(m_queue); - m_registry->setup(); -} diff --git a/src/waylandintegration.h b/src/waylandintegration.h deleted file mode 100644 index fd17e4d..0000000 --- a/src/waylandintegration.h +++ /dev/null @@ -1,100 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef XDG_DESKTOP_PORTAL_DDE_WAYLAND_INTEGRATION_H -#define XDG_DESKTOP_PORTAL_DDE_WAYLAND_INTEGRATION_H - -#include -#include -#include -#include - -#include -#include - -namespace KWayland { - namespace Client { - class PlasmaWindowManagement; - class ScreencastingSource; - } -} - -namespace WaylandIntegration -{ - -class WaylandOutput -{ -public: - enum OutputType { - Laptop, - Monitor, - Television - }; - QString manufacturer() const { return m_output->manufacturer(); } - QString model() const { return m_output->model(); } - QPoint globalPosition() const { return m_output->globalPosition(); } - QSize resolution() const { return m_output->pixelSize(); } - OutputType outputType() const { return m_outputType; } - - QSharedPointer output() const { return m_output; } - void setOutput(const QSharedPointer &output) { - m_output = output; - setOutputType(output->model()); - } - - void setWaylandOutputName(int outputName) { m_waylandOutputName = outputName; } - int waylandOutputName() const { return m_waylandOutputName; } - - void setWaylandOutputVersion(int outputVersion) { m_waylandOutputVersion = outputVersion; } - int waylandOutputVersion() const { return m_waylandOutputVersion; } - -private: - void setOutputType(const QString &model); - OutputType m_outputType = Monitor; - QSharedPointer m_output; - - // Needed for later output binding - int m_waylandOutputName; - int m_waylandOutputVersion; -}; - -class WaylandIntegration : public QObject -{ - Q_OBJECT -Q_SIGNALS: - void newBuffer(uint8_t *screenData); - void plasmaWindowManagementInitialized(); -}; - - void authenticate(); - - bool isStreamingEnabled(); - bool isStreamingAvailable(); - - void startStreamingInput(); - bool startStreamingOutput(quint32 outputName, Screencasting::CursorMode mode); - bool startStreamingWindow(const QByteArray &winid); - void stopAllStreaming(); - - void requestPointerButtonPress(quint32 linuxButton); - void requestPointerButtonRelease(quint32 linuxButton); - void requestPointerMotion(const QSizeF &delta); - void requestPointerMotionAbsolute(const QPointF &pos); - void requestPointerAxisDiscrete(Qt::Orientation axis, qreal delta); - - void requestKeyboardKeycode(int keycode, bool state); - - QMap screens(); - QVariant streams(); - - void init(); - - KWayland::Client::PlasmaWindowManagement *plasmaWindowManagement(); - - WaylandIntegration *waylandIntegration(); -} - -#endif // XDG_DESKTOP_PORTAL_DDE_WAYLAND_INTEGRATION_H - - diff --git a/src/waylandintegration_p.h b/src/waylandintegration_p.h deleted file mode 100644 index 3066171..0000000 --- a/src/waylandintegration_p.h +++ /dev/null @@ -1,115 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef XDG_DESKTOP_PORTAL_DDE_WAYLAND_INTEGRATION_P_H -#define XDG_DESKTOP_PORTAL_DDE_WAYLAND_INTEGRATION_P_H - -#include "waylandintegration.h" - -#include -#include -#include - -class Screencasting; -class ScreencastingStream; - -namespace KWayland { - namespace Client { - class ConnectionThread; - class EventQueue; - class Registry; - class PlasmaWindow; - class PlasmaWindowManagement; - class FakeInput; - class RemoteBuffer; - class Output; - } -} - -namespace WaylandIntegration -{ - -class WaylandIntegrationPrivate : public WaylandIntegration::WaylandIntegration -{ - Q_OBJECT -public: - WaylandIntegrationPrivate(); - ~WaylandIntegrationPrivate(); - - void initWayland(); - - KWayland::Client::PlasmaWindowManagement *plasmaWindowManagement(); - -protected Q_SLOTS: - void setupRegistry(); - -private: - bool m_registryInitialized = false; - - QThread *m_thread = nullptr; - KWayland::Client::ConnectionThread *m_connection = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - KWayland::Client::Registry *m_registry = nullptr; - KWayland::Client::PlasmaWindowManagement *m_windowManagement = nullptr; - -public: - struct Stream { - ScreencastingStream *stream = nullptr; - uint nodeId; - QVariantMap map; - - void close(); - }; - typedef QVector Streams; - - void authenticate(); - - bool isStreamingEnabled() const; - bool isStreamingAvailable() const; - - void startStreamingInput(); - - bool startStreaming(ScreencastingStream *stream, QSharedPointer output); - bool startStreamingOutput(quint32 outputName, Screencasting::CursorMode mode); - bool startStreamingWindow(const QByteArray &winid); - void stopStreaming(uint32_t nodeid); - void stopAllStreaming(); - - void requestPointerButtonPress(quint32 linuxButton); - void requestPointerButtonRelease(quint32 linuxButton); - void requestPointerMotion(const QSizeF &delta); - void requestPointerMotionAbsolute(const QPointF &pos); - void requestPointerAxisDiscrete(Qt::Orientation axis, qreal delta); - void requestKeyboardKeycode(int keycode, bool state); - void bindOutput(int outputName, int outputVersion); - - QMap screens(); - QVariant streams(); - -protected Q_SLOTS: - void addOutput(quint32 name, quint32 version); - void removeOutput(quint32 name); - -private: - bool m_streamInput = false; - bool m_waylandAuthenticationRequested = false; - - quint32 m_output; - QDateTime m_lastFrameTime; - QVector m_streams; - - QPoint m_streamedScreenPosition; - - QMap m_outputMap; - QList m_bindOutputs; - - KWayland::Client::FakeInput *m_fakeInput = nullptr; - Screencasting *m_screencasting = nullptr; -}; - -} - -#endif // XDG_DESKTOP_PORTAL_DDE_WAYLAND_INTEGRATION_P_H - -