Inhibit sleeping while a session is active
This commit is contained in:
@@ -31,6 +31,8 @@ finish-args:
|
||||
- --talk-name=org.kde.StatusNotifierWatcher
|
||||
# Run processes outside of sandbox
|
||||
- --talk-name=org.freedesktop.Flatpak
|
||||
# Inhibit sleeping while a session is active
|
||||
- --system-talk-name=org.freedesktop.login1
|
||||
|
||||
cleanup:
|
||||
- /lib/pkgconfig
|
||||
|
||||
@@ -65,6 +65,7 @@ add_executable(wivrn-server
|
||||
avahi_publisher.cpp
|
||||
hostname.cpp
|
||||
main.cpp
|
||||
sleep_inhibitor.cpp
|
||||
start_application.cpp
|
||||
target_instance_wivrn.cpp
|
||||
wivrn_ipc.cpp
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "openxr/openxr.h"
|
||||
#include "sleep_inhibitor.h"
|
||||
#include "util/u_trace_marker.h"
|
||||
|
||||
#include "active_runtime.h"
|
||||
@@ -198,6 +199,7 @@ WivrnServer * dbus_server;
|
||||
*/
|
||||
std::optional<active_runtime> runtime_setter;
|
||||
std::optional<avahi_publisher> publisher;
|
||||
std::optional<sleep_inhibitor> inhibitor;
|
||||
|
||||
gboolean headset_connected(gint fd, GIOCondition condition, gpointer user_data);
|
||||
void stop_listening();
|
||||
@@ -446,16 +448,19 @@ gboolean control_received(gint fd, GIOCondition condition, gpointer user_data)
|
||||
if (std::holds_alternative<wivrn::from_headset::headset_info_packet>(*packet))
|
||||
{
|
||||
on_headset_info_packet(std::get<wivrn::from_headset::headset_info_packet>(*packet));
|
||||
inhibitor.emplace();
|
||||
wivrn_server_set_headset_connected(dbus_server, true);
|
||||
}
|
||||
else if (std::holds_alternative<from_monado::headsdet_connected>(*packet))
|
||||
{
|
||||
stop_publishing();
|
||||
inhibitor.emplace();
|
||||
wivrn_server_set_headset_connected(dbus_server, true);
|
||||
}
|
||||
else if (std::holds_alternative<from_monado::headsdet_disconnected>(*packet))
|
||||
{
|
||||
start_publishing();
|
||||
inhibitor.reset();
|
||||
wivrn_server_set_headset_connected(dbus_server, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* 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 3 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "sleep_inhibitor.h"
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
sleep_inhibitor::sleep_inhibitor()
|
||||
{
|
||||
std::cerr << "Inhibiting sleep" << std::endl;
|
||||
|
||||
GError * error = nullptr;
|
||||
GDBusProxy * proxy = g_dbus_proxy_new_for_bus_sync(
|
||||
G_BUS_TYPE_SYSTEM,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
nullptr,
|
||||
"org.freedesktop.login1",
|
||||
"/org/freedesktop/login1",
|
||||
"org.freedesktop.login1.Manager",
|
||||
nullptr,
|
||||
&error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
std::cerr << "Cannot create DBus proxy for org.freedesktop.login1: " << error->message << std::endl;
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
GUnixFDList * fd_list;
|
||||
|
||||
GVariant * output = g_dbus_proxy_call_with_unix_fd_list_sync(
|
||||
proxy,
|
||||
"Inhibit",
|
||||
g_variant_new(
|
||||
"(ssss)",
|
||||
"sleep:idle", // What
|
||||
"WiVRn", // Who
|
||||
"A WiVRn session is active", // Why
|
||||
"block"), // Mode
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1, // timeout_msec
|
||||
nullptr, // fd_list
|
||||
&fd_list, // out_fd_list
|
||||
nullptr, // cancellable
|
||||
&error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
std::cerr << "Cannot inhibit sleep: " << error->message << std::endl;
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
std::cerr << "Received variant type " << g_variant_get_type_string(output) << std::endl;
|
||||
|
||||
int fd_index;
|
||||
g_variant_get(output, "(h)", &fd_index);
|
||||
|
||||
int fd_count;
|
||||
int * fds = g_unix_fd_list_steal_fds(fd_list, &fd_count);
|
||||
|
||||
if (fd_index < fd_count)
|
||||
fd = fds[fd_index];
|
||||
|
||||
g_free(fds);
|
||||
|
||||
std::cerr << "File descriptor " << fd << std::endl;
|
||||
|
||||
g_variant_unref(output);
|
||||
g_object_unref(fd_list);
|
||||
}
|
||||
|
||||
sleep_inhibitor::~sleep_inhibitor()
|
||||
{
|
||||
std::cerr << "Uninhibiting sleep" << std::endl;
|
||||
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* 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 3 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
class sleep_inhibitor
|
||||
{
|
||||
int fd = -1;
|
||||
|
||||
public:
|
||||
sleep_inhibitor();
|
||||
~sleep_inhibitor();
|
||||
};
|
||||
Reference in New Issue
Block a user