Taking screenshots via org.freedesktop.portal.Screenshot

I’m trying to take a screenshot under Wayland via org.freedesktop.portal.Screenshot but all I get is: “The name org.freedesktop.portal.Screenshot was not provided by any .service files”.

Is there something specific that needs to be done in order to get access? This is our manifest: https://github.com/flathub/org.ksnip.ksnip/blob/master/org.ksnip.ksnip.yaml

org.freedesktop.portal.Screenshot is the interface, not the bus name. All xdg-desktop-portals portals are exported under org.freedesktop.portal.Desktop.

Thanks, that brings me a bit further. I have tried now following:

QDBusInterface interface(QStringLiteral("org.freedesktop.portal.Desktop"), QStringLiteral("/org/freedesktop/portal/Desktop"), QStringLiteral("org.freedesktop.portal.Screenshot"));
QDBusPendingReply<bool, QString> reply;

reply = interface.asyncCall(QStringLiteral("Screenshot"), "s", "a");

Where:

org.freedesktop.portal.Desktop -> Service
/org/freedesktop/portal/Desktop -> Path
org.freedesktop.portal.Screenshot -> Interface
Screenshot -> Method

This gives me now following error

I’m obviously still doing something wrong.

org.freedesktop.portal.Desktop → Service
/org/freedesktop/portal/Desktop → Path

That should be /org/freedesktop/portal/desktop.

That should be /org/freedesktop/portal/desktop .

Thanks, that was helpful again. Now I’m at the method call, the method seems to be correct but I’n not sure what I’m supposed to pass as parameters?

That’s what documentation is there for :wink:

I’m aware of the documentation but can’t say that it really helped me here, otherwise I wouldn’t be asking around the forum for help.

For Example, the options parameter of the Screenshot method has format a{sv}, I didn’t find any clue what this is supposed to be. Is this an array of string value pairs? Is it mandatory? Is there any working example usage?

Your questions are rather DBus specific. a {sv} means it’s hashmap of string keys & a value that could be of any type. You can check https://github.com/flatpak/libportal which provides wrappers around the DBus calls.

There must be, as a{sv} is a very common type.

Looking at the KDE portal implementation I’d say that you want QVariantMap, but that’s the guess of a GNOME developer :slight_smile:

I’d say that you want QVariantMap , but that’s the guess of a GNOME developer

I think that this is a good guess, found that too after @bilelmoussaoui told me that this is a general DBus thing and I “refined” my Internet search. Will test it later when I’m home.

Ok, finally somethings happening, I get a dialog with Output with this:

	QDBusInterface interface(QStringLiteral("org.freedesktop.portal.Desktop"), QStringLiteral("/org/freedesktop/portal/Screenshot"), QStringLiteral("org.freedesktop.portal.Screenshot"));
	QDBusPendingReply<QDBusObjectPath> reply;

	reply = interface.call(QStringLiteral("Screenshot"), "", QVariantMap());

	if (reply.isError()) {
		qCritical("Invalid reply from DBus: %s", qPrintable(reply.error().message()));
	} else {
            qCritical("Dbus success: %s", qPrintable(reply.argumentAt<0>().path()));
	}

The response seems to be a Request /org/freedesktop/portal/desktop/request/1_181/t, how can I get notified about the user clicking “share”, the dialog closing and fetching the screenshot?