From e845729dfdf55660b82517d1eb1ace2d0aff29f1 Mon Sep 17 00:00:00 2001 From: tytan652 Date: Sun, 8 Dec 2024 16:20:11 +0100 Subject: [PATCH] libobs/util: Improve inhibit portal detection on Linux Check for a property of the inhibit portal rather than just the portal D-Bus name that does not indicate if the specific portal is available. --- libobs/util/platform-nix-portal.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libobs/util/platform-nix-portal.c b/libobs/util/platform-nix-portal.c index d26b4295d15504..ac701530088179 100644 --- a/libobs/util/platform-nix-portal.c +++ b/libobs/util/platform-nix-portal.c @@ -21,6 +21,8 @@ #include "dstr.h" #define PORTAL_NAME "org.freedesktop.portal.Desktop" +#define PORTAL_PATH "/org/freedesktop/portal/desktop" +#define INHIBIT_PORTAL_IFACE "org.freedesktop.portal.Inhibit" struct portal_inhibit_info { GDBusConnection *c; @@ -129,8 +131,7 @@ static void do_inhibit(struct portal_inhibit_info *info, const char *reason) bfree(token); info->cancellable = g_cancellable_new(); - g_dbus_connection_call(info->c, PORTAL_NAME, "/org/freedesktop/portal/desktop", - "org.freedesktop.portal.Inhibit", "Inhibit", + g_dbus_connection_call(info->c, PORTAL_NAME, PORTAL_PATH, INHIBIT_PORTAL_IFACE, "Inhibit", g_variant_new("(sua{sv})", "", flags, &options), NULL, G_DBUS_CALL_FLAGS_NONE, -1, info->cancellable, inhibited_cb, info); } @@ -197,9 +198,9 @@ struct portal_inhibit_info *portal_inhibit_info_create(void) while ((aux = strstr(info->sender_name, ".")) != NULL) *aux = '_'; - reply = g_dbus_connection_call_sync(info->c, "org.freedesktop.DBus", "/org/freedesktop/DBus", - "org.freedesktop.DBus", "GetNameOwner", g_variant_new("(s)", PORTAL_NAME), - NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, NULL); + reply = g_dbus_connection_call_sync(info->c, PORTAL_NAME, PORTAL_PATH, "org.freedesktop.DBus.Properties", "Get", + g_variant_new("(ss)", INHIBIT_PORTAL_IFACE, "version"), + G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); if (reply != NULL) { blog(LOG_DEBUG, "Found portal inhibitor");