[dbus] Use GameMode portal inside flatpak

This commit is contained in:
jackun 2022-03-24 12:02:21 +02:00
parent 906542f587
commit a26e6325cc
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3
2 changed files with 24 additions and 4 deletions

View File

@ -6,6 +6,7 @@
#include "dbus_helpers.h"
#include "dbus_info.h"
#include "string_utils.h"
#include "file_utils.h"
using ms = std::chrono::milliseconds;
using namespace DBus_helpers;
@ -341,14 +342,33 @@ bool dbus_manager::handle_name_owner_changed(DBusMessage* _msg,
return true;
}
bool dbus_manager::gamemode_enabled(int32_t pid) {
bool dbus_manager::gamemode_enabled(pid_t pid) {
if (!m_inited)
return false;
static int isvc = file_exists("/.flatpak-info") ? 1 : 0;
const struct dbus_ep
{
const char *name;
const char *path;
const char *iface;
} svc[] {
{
"com.feralinteractive.GameMode",
"/com/feralinteractive/GameMode",
"com.feralinteractive.GameMode"
},
{
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.GameMode"
}
};
auto reply =
DBusMessage_wrap::new_method_call(
"com.feralinteractive.GameMode", "/com/feralinteractive/GameMode",
"com.feralinteractive.GameMode", "QueryStatus", &dbus_mgr.dbus())
svc[isvc].name, svc[isvc].path, svc[isvc].iface,
"QueryStatus", &dbus_mgr.dbus())
.argument(pid)
.send_with_reply_and_block(dbus_mgr.get_conn(), DBUS_TIMEOUT);
if (!reply) return false;

View File

@ -88,7 +88,7 @@ class dbus_manager {
void disconnect_from_signals(Service srv);
DBusConnection* get_conn() const { return m_dbus_conn; }
bool gamemode_enabled(int32_t pid);
bool gamemode_enabled(pid_t pid);
libdbus_loader& dbus() { return m_dbus_ldr; }