From 7a18dc096a96db26ab41ff9b3059975793e725f4 Mon Sep 17 00:00:00 2001 From: nullobsi Date: Mon, 1 Feb 2021 15:45:51 -0800 Subject: [PATCH] preliminary support for sway/wlroots compositors --- src/utils/CMakeLists.txt | 2 ++ src/utils/desktopinfo.cpp | 4 ++- src/utils/desktopinfo.h | 3 +- src/utils/request.cpp | 16 +++++++++++ src/utils/request.h | 56 +++++++++++++++++++++++++++++++++++++ src/utils/screengrabber.cpp | 41 +++++++++++++++++++++++++++ 6 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 src/utils/request.cpp create mode 100644 src/utils/request.h diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 80973565..207e3dc1 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -6,6 +6,7 @@ target_sources( screengrabber.h systemnotification.h configshortcuts.h + request.h ) target_sources( @@ -23,4 +24,5 @@ target_sources( colorutils.cpp history.cpp configshortcuts.cpp + request.cpp ) diff --git a/src/utils/desktopinfo.cpp b/src/utils/desktopinfo.cpp index bb932b78..b9688c9d 100644 --- a/src/utils/desktopinfo.cpp +++ b/src/utils/desktopinfo.cpp @@ -44,7 +44,9 @@ DesktopInfo::WM DesktopInfo::windowManager() Qt::CaseInsensitive) || !GNOME_DESKTOP_SESSION_ID.isEmpty()) { res = DesktopInfo::GNOME; - } else if (!KDE_FULL_SESSION.isEmpty() || + } else if (XDG_CURRENT_DESKTOP.contains(QLatin1String("sway"), Qt::CaseInsensitive)) { + res = DesktopInfo::SWAY; + }else if (!KDE_FULL_SESSION.isEmpty() || DESKTOP_SESSION == QLatin1String("kde-plasma")) { res = DesktopInfo::KDE; } diff --git a/src/utils/desktopinfo.h b/src/utils/desktopinfo.h index 061c6e0a..fd82f4f3 100644 --- a/src/utils/desktopinfo.h +++ b/src/utils/desktopinfo.h @@ -28,7 +28,8 @@ public: { GNOME, KDE, - OTHER + OTHER, + SWAY }; bool waylandDectected(); diff --git a/src/utils/request.cpp b/src/utils/request.cpp new file mode 100644 index 00000000..30307a31 --- /dev/null +++ b/src/utils/request.cpp @@ -0,0 +1,16 @@ +// +// Created by nullobsi on 2021/02/01. +// +/* + * Implementation of interface class OrgFreedesktopPortalRequestInterface + */ + +#include "request.h" +OrgFreedesktopPortalRequestInterface::OrgFreedesktopPortalRequestInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +OrgFreedesktopPortalRequestInterface::~OrgFreedesktopPortalRequestInterface() +{ +} \ No newline at end of file diff --git a/src/utils/request.h b/src/utils/request.h new file mode 100644 index 00000000..83a33e4a --- /dev/null +++ b/src/utils/request.h @@ -0,0 +1,56 @@ +/* + * This file was generated by qdbusxml2cpp version 0.8 + * Command line was: qdbusxml2cpp -p response.cpp resp.xml + * + * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef RESPONSE_CPP +#define RESPONSE_CPP +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface org.freedesktop.portal.Request + */ +class OrgFreedesktopPortalRequestInterface: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "org.freedesktop.portal.Request"; } + +public: + OrgFreedesktopPortalRequestInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr); + + ~OrgFreedesktopPortalRequestInterface(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<> Close() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("Close"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void Response(uint response, QVariantMap results); +}; + +namespace org { + namespace freedesktop { + namespace portal { + typedef ::OrgFreedesktopPortalRequestInterface Request; + } + } +} +#endif + diff --git a/src/utils/screengrabber.cpp b/src/utils/screengrabber.cpp index 4e970ba9..9ebce59a 100644 --- a/src/utils/screengrabber.cpp +++ b/src/utils/screengrabber.cpp @@ -28,6 +28,7 @@ #include #include #include +#include "request.h" #endif ScreenGrabber::ScreenGrabber(QObject* parent) @@ -88,6 +89,46 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool& ok) } break; } + case DesktopInfo::SWAY: { + qDebug("Sway"); + QDBusInterface screenshotInterface( + QStringLiteral("org.freedesktop.portal.Desktop"), + QStringLiteral("/org/freedesktop/portal/desktop"), + QStringLiteral("org.freedesktop.portal.Screenshot")); + + QDBusReply reply = + screenshotInterface.call(QStringLiteral("Screenshot"), + "", + QMap()); + OrgFreedesktopPortalRequestInterface request( + QStringLiteral("org.freedesktop.portal.Desktop"), + reply.value().path(), + QDBusConnection::sessionBus(), + this); + QEventLoop loop; + const auto gotSignal = + [&res, &loop](uint status, + const QVariantMap &map) { + qDebug() << "Signal" << status << map; + if (status == 0) { + QString uri = map.value("uri").toString().remove(0, 7); + qDebug() << uri; + res = QPixmap(uri); + QFile imgFile(uri); + imgFile.remove(); + loop.quit(); + } + }; + connect(&request, + &org::freedesktop::portal::Request::Response, + gotSignal); + loop.exec(); + request.Close(); + if (res.isNull()) { + ok = false; + } + break; + } default: ok = false; break;