diff --git a/lessons_learned.md b/lessons_learned.md index fa66c46..79ee0bc 100644 --- a/lessons_learned.md +++ b/lessons_learned.md @@ -113,6 +113,11 @@ This document summarizes the key challenges, debugging steps, and solutions enco * **Diagnosis:** The `CreateSession` method, while expecting a single dictionary of options, also requires a `handle_token` within that dictionary. * **Fix:** Added a `handle_token` to the `QVariantMap` passed to the `CreateSession` call in `wayland_poc.cpp`. +* **D-Bus `CreateSession` Signature Mismatch (Revisited):** + * **Problem:** The `CreateSession` call was failing with "Type of message, “(oa{sv})”, does not match expected type “(a{sv})”". This indicated that `CreateSession` expects only a single dictionary of options (`a{sv}`), and the previously added `parent_window` object path argument was unexpected. + * **Diagnosis:** The `xdg-desktop-portal` API for `CreateSession` does not expect a `parent_window` argument. + * **Fix:** Removed the `QDBusObjectPath("/")` argument from the `CreateSession` call in `wayland_poc.cpp`. + * **New Runtime Error: "Remote peer disconnected"** * **Problem:** After successfully building and copying `wayland_poc` to the host, running it resulted in "D-Bus call to SelectSources failed: "Remote peer disconnected"". * **Diagnosis:** This indicates a problem with the D-Bus connection itself, rather than a rejection from the portal. Possible causes include incorrect D-Bus environment variables on the host, `xdg-desktop-portal` not running, or permission issues. diff --git a/wayland_poc.cpp b/wayland_poc.cpp index 2665d3f..56f6ace 100644 --- a/wayland_poc.cpp +++ b/wayland_poc.cpp @@ -19,28 +19,28 @@ void handleSelectSourcesResponse(QDBusPendingCallWatcher *watcher) { watcher->deleteLater(); if (reply.isError()) { - qCritical() << "D-Bus call to SelectSources failed:" << reply.error().message(); + qCritical() << "D-Bus call to SelectSources failed:" << reply.error().message(); fflush(stderr); QCoreApplication::quit(); return; } QList arguments = reply.reply().arguments(); if (arguments.isEmpty()) { - qCritical() << "SelectSources response has no arguments."; + qCritical() << "SelectSources response has no arguments."; fflush(stderr); QCoreApplication::quit(); return; } bool success = arguments.at(0).toBool(); if (!success) { - qCritical() << "SelectSources request denied or failed."; + qCritical() << "SelectSources request denied or failed."; fflush(stderr); QCoreApplication::quit(); return; } QVariantList sources = arguments.at(1).toList(); if (sources.isEmpty()) { - qCritical() << "No sources selected."; + qCritical() << "No sources selected."; fflush(stderr); QCoreApplication::quit(); return; } @@ -48,7 +48,7 @@ void handleSelectSourcesResponse(QDBusPendingCallWatcher *watcher) { // For POC, just take the first source QVariantMap sourceMap = sources.at(0).toMap(); if (!sourceMap.contains("pipewire_node_id")) { - qCritical() << "Selected source missing pipewire_node_id."; + qCritical() << "Selected source missing pipewire_node_id."; fflush(stderr); QCoreApplication::quit(); return; } @@ -66,21 +66,21 @@ void handleCreateSessionFinished(QDBusPendingCallWatcher *watcher) { watcher->deleteLater(); if (reply.isError()) { - qCritical() << "D-Bus call to CreateSession failed:" << reply.error().message(); + qCritical() << "D-Bus call to CreateSession failed:" << reply.error().message(); fflush(stderr); QCoreApplication::quit(); return; } QList arguments = reply.reply().arguments(); if (arguments.isEmpty()) { - qCritical() << "CreateSession response has no arguments."; + qCritical() << "CreateSession response has no arguments."; fflush(stderr); QCoreApplication::quit(); return; } QVariant firstArg = arguments.at(0); if (!firstArg.canConvert()) { - qCritical() << "CreateSession response first argument is not an object path."; + qCritical() << "CreateSession response first argument is not an object path."; fflush(stderr); QCoreApplication::quit(); return; } @@ -122,13 +122,7 @@ int main(int argc, char *argv[]) { QDBusConnection sessionBus = QDBusConnection::sessionBus(); if (!sessionBus.isConnected()) { - qCritical() << "Failed to connect to D-Bus session bus."; - return -1; - } - - QThread::msleep(100); // Add a small delay - if (!sessionBus.interface()->isServiceRegistered("org.freedesktop.portal.Desktop")) { - qCritical() << "xdg-desktop-portal service not found. Please ensure it is installed and running."; + qCritical() << "Failed to connect to D-Bus session bus."; fflush(stderr); return -1; } @@ -140,14 +134,9 @@ int main(int argc, char *argv[]) { "CreateSession" ); - // Generate unique object paths for handle and session_handle - QDBusObjectPath handlePath("/org/freedesktop/portal/request/12345/screencast_req_1"); - QDBusObjectPath sessionPath("/org/freedesktop/portal/session/12345/screencast_sess_1"); - - // Add arguments: handle, session_handle, app_id, options QVariantMap options; options.insert("handle_token", QUuid::createUuid().toString(QUuid::WithoutBraces)); // Add handle_token - message << options; // Empty options map + message << options; QDBusPendingCall pendingCall = sessionBus.asyncCall(message); QDBusPendingCallWatcher *mainWatcher = new QDBusPendingCallWatcher(pendingCall); @@ -155,4 +144,4 @@ int main(int argc, char *argv[]) { QObject::connect(mainWatcher, &QDBusPendingCallWatcher::finished, handleCreateSessionFinished); return app.exec(); -} +} \ No newline at end of file