Dbus signal after wake from suspend

I am trying to get an indication, in my program, that the system has woken up after a suspend.
I execute …

 g_dbus_connection_signal_subscribe( conSystemBus,
	"/org/freedesktop/login1", NULL,
	G_DBUS_SIGNAL_FLAGS_NONE, on_DBUSresume, (gpointer) pGlobal, NULL);

and my callback is called when the system goes to sleep and when it wakes up.

static void
on_DBUSresume(GDBusConnection *connection,
        const gchar *sender_name, const gchar *object_path,
        const gchar *interface_name, const gchar *signal_name,
        GVariant *parameters, gpointer udata)
	tGlobal *pGlobal= (tGlobal *)udata;
	gboolean bState = g_variant_get_boolean(parameters);

	// FWIU this boolean should be TRUE for sleeping and FALSE for wake
	// but it always seems FALSE
	if( !bState ) {
		// doing the voodoo I do ...

From what I understand, the parameter should be TRUE when going to suspend and FALSE when waking; however, I get FALSE on both occasions.
Am I doing something wrong, or is my understanding of this signal incorrect. If so how can I get an indication of wake?


Are you not getting an error like this?:

g_variant_get_boolean: assertion 'g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)' failed

At least with the high-level API, the signal parameters are wrapped in a tuple. You can use something like this to unpack it:

g_variant_get (parameters, "(b)", &entering);

Here’s the complete example I used for testing:

#include <gio/gio.h>

void prepare_for_sleep (GDBusProxy *proxy,
                        char       *sender_name,
                        char       *signal_name,
                        GVariant   *parameters,
                        gpointer    user_data)
  gboolean entering;
  g_variant_get (parameters, "(b)", &entering);

  g_print ("PrepareForSleep: %d\n", entering);

void main ()
  GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,

  g_signal_connect (proxy, "g-signal::PrepareForSleep", G_CALLBACK (prepare_for_sleep), NULL);
  GMainLoop *loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (loop);
1 Like

Great, that worked. thanks!
There was no run-time error (or any indication whatsoever that this failed).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.