#include #include #include #include #include #include #include // QDBus callback for xdg-desktop-portal response void handlePortalResponse(QDBusPendingCallWatcher *watcher) { QDBusPendingCall reply = *watcher; watcher->deleteLater(); if (reply.isError()) { qCritical() << "D-Bus call to xdg-desktop-portal failed:" << reply.error().message(); QCoreApplication::quit(); return; } QList arguments = reply.reply().arguments(); if (arguments.isEmpty()) { qCritical() << "xdg-desktop-portal response has no arguments."; QCoreApplication::quit(); return; } QVariant firstArg = arguments.at(0); if (!firstArg.canConvert()) { qCritical() << "xdg-desktop-portal response first argument is not a map."; QCoreApplication::quit(); return; } QVariantMap responseMap = firstArg.toMap(); if (!responseMap.contains("pipewire_node_id")) { qCritical() << "xdg-desktop-portal response missing pipewire_node_id."; QCoreApplication::quit(); return; } quint32 node_id = responseMap.value("pipewire_node_id").toUInt(); qDebug() << "xdg-desktop-portal granted screen capture. PipeWire node ID:" << node_id; QCoreApplication::quit(); // Quit after getting the node ID for POC } int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); qDebug() << "Requesting screen capture via xdg-desktop-portal..."; QDBusConnection sessionBus = QDBusConnection::sessionBus(); if (!sessionBus.isConnected()) { qCritical() << "Failed to connect to D-Bus session bus."; return -1; } QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop", "org.freedesktop.portal.ScreenCast", "SelectSources" ); QVariantMap options; options.insert("multiple", false); // Request single source message << "" << options; // parent_window (empty), options QDBusPendingCall pendingCall = sessionBus.asyncCall(message); // Use asyncCall QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingCall); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, handlePortalResponse); return app.exec(); }