forked from obsproject/obs-studio
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
linux-capture: Conditionally register PipeWire captures
Right now we just assume that every compositor and portal implementation exposes both window and monitor captures, but that's not true, and in fact the Desktop portal provides a simple mechanism to check which source types are available: a D-Bus property called "AvailableSourceTypes". Read this D-Bus property, and use it to conditionally register the desktop and the window captures. Related: obsproject#4815
- Loading branch information
1 parent
81691f1
commit 7c614d5
Showing
4 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* portal.c | ||
* | ||
* Copyright 2021 Georges Basile Stavracas Neto <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#include "portal.h" | ||
#include "pipewire.h" | ||
|
||
static GDBusConnection *connection = NULL; | ||
static GDBusProxy *proxy = NULL; | ||
|
||
static void ensure_proxy(void) | ||
{ | ||
g_autoptr(GError) error = NULL; | ||
if (!connection) { | ||
connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); | ||
|
||
if (error) { | ||
blog(LOG_WARNING, | ||
"[portals] Error retrieving D-Bus connection: %s", | ||
error->message); | ||
return; | ||
} | ||
} | ||
|
||
if (!proxy) { | ||
proxy = g_dbus_proxy_new_sync( | ||
connection, G_DBUS_PROXY_FLAGS_NONE, NULL, | ||
"org.freedesktop.portal.Desktop", | ||
"/org/freedesktop/portal/desktop", | ||
"org.freedesktop.portal.ScreenCast", NULL, &error); | ||
|
||
if (error) { | ||
blog(LOG_WARNING, | ||
"[portals] Error retrieving D-Bus proxy: %s", | ||
error->message); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
uint32_t portal_get_available_capture_types(void) | ||
{ | ||
g_autoptr(GVariant) cached_source_types = NULL; | ||
uint32_t available_source_types; | ||
|
||
ensure_proxy(); | ||
|
||
if (!proxy) | ||
return 0; | ||
|
||
cached_source_types = | ||
g_dbus_proxy_get_cached_property(proxy, "AvailableSourceTypes"); | ||
available_source_types = | ||
cached_source_types ? g_variant_get_uint32(cached_source_types) | ||
: 0; | ||
|
||
return available_source_types; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* portal.c | ||
* | ||
* Copyright 2021 Georges Basile Stavracas Neto <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
uint32_t portal_get_available_capture_types(void); |