2023-06-07 08:17:42 +00:00
|
|
|
#include "util/prepare_for_sleep.h"
|
|
|
|
|
|
|
|
#include <gio/gio.h>
|
fix(util): don't abort modules from SleeperThread after 3c9cbc99d736
[warning] module sway/workspaces: Disabling module "sway/workspaces", Unable to connect to the SYSTEM Bus!...
[warning] module sway/mode: Disabling module "sway/mode", Unable to connect to the SYSTEM Bus!...
[warning] module sway/scratchpad: Disabling module "sway/scratchpad", Unable to connect to the SYSTEM Bus!...
[warning] module custom/media: Disabling module "custom/media", Unable to connect to the SYSTEM Bus!...
[warning] module sway/window: Disabling module "sway/window", Unable to connect to the SYSTEM Bus!...
[warning] module cpu: Disabling module "cpu", Unable to connect to the SYSTEM Bus!...
[warning] module memory: Disabling module "memory", Unable to connect to the SYSTEM Bus!...
[warning] module temperature: Disabling module "temperature", Unable to connect to the SYSTEM Bus!...
[warning] module sway/language: Disabling module "sway/language", Unable to connect to the SYSTEM Bus!...
[warning] module battery: Disabling module "battery", Unable to connect to the SYSTEM Bus!...
[warning] module battery#bat2: Disabling module "battery#bat2", Unable to connect to the SYSTEM Bus!...
2023-07-05 17:38:53 +00:00
|
|
|
#include <spdlog/spdlog.h>
|
2023-06-07 08:17:42 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
class PrepareForSleep {
|
|
|
|
private:
|
|
|
|
PrepareForSleep() {
|
2023-10-22 07:44:46 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
login1_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
|
2023-06-07 08:17:42 +00:00
|
|
|
if (!login1_connection) {
|
fix(util): don't abort modules from SleeperThread after 3c9cbc99d736
[warning] module sway/workspaces: Disabling module "sway/workspaces", Unable to connect to the SYSTEM Bus!...
[warning] module sway/mode: Disabling module "sway/mode", Unable to connect to the SYSTEM Bus!...
[warning] module sway/scratchpad: Disabling module "sway/scratchpad", Unable to connect to the SYSTEM Bus!...
[warning] module custom/media: Disabling module "custom/media", Unable to connect to the SYSTEM Bus!...
[warning] module sway/window: Disabling module "sway/window", Unable to connect to the SYSTEM Bus!...
[warning] module cpu: Disabling module "cpu", Unable to connect to the SYSTEM Bus!...
[warning] module memory: Disabling module "memory", Unable to connect to the SYSTEM Bus!...
[warning] module temperature: Disabling module "temperature", Unable to connect to the SYSTEM Bus!...
[warning] module sway/language: Disabling module "sway/language", Unable to connect to the SYSTEM Bus!...
[warning] module battery: Disabling module "battery", Unable to connect to the SYSTEM Bus!...
[warning] module battery#bat2: Disabling module "battery#bat2", Unable to connect to the SYSTEM Bus!...
2023-07-05 17:38:53 +00:00
|
|
|
spdlog::warn("Unable to connect to the SYSTEM Bus!...");
|
2023-06-07 08:17:42 +00:00
|
|
|
} else {
|
|
|
|
login1_id = g_dbus_connection_signal_subscribe(
|
|
|
|
login1_connection, "org.freedesktop.login1", "org.freedesktop.login1.Manager",
|
|
|
|
"PrepareForSleep", "/org/freedesktop/login1", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
|
|
|
|
prepareForSleep_cb, this, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prepareForSleep_cb(GDBusConnection *system_bus, const gchar *sender_name,
|
|
|
|
const gchar *object_path, const gchar *interface_name,
|
|
|
|
const gchar *signal_name, GVariant *parameters,
|
|
|
|
gpointer user_data) {
|
|
|
|
if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(b)"))) {
|
|
|
|
gboolean sleeping;
|
|
|
|
g_variant_get(parameters, "(b)", &sleeping);
|
|
|
|
|
|
|
|
PrepareForSleep *self = static_cast<PrepareForSleep *>(user_data);
|
|
|
|
self->signal.emit(sleeping);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static PrepareForSleep &GetInstance() {
|
|
|
|
static PrepareForSleep instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
waybar::SafeSignal<bool> signal;
|
|
|
|
|
|
|
|
private:
|
|
|
|
guint login1_id;
|
|
|
|
GDBusConnection *login1_connection;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
waybar::SafeSignal<bool> &waybar::util::prepare_for_sleep() {
|
|
|
|
return PrepareForSleep::GetInstance().signal;
|
|
|
|
}
|