Created
June 9, 2015 22:20
-
-
Save heftig/914cd6c05cbf6d37218a to your computer and use it in GitHub Desktop.
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
#include "screensaver-gdbus.h" | |
static void | |
active_changed_cb (FooDBusScreenSaver *proxy, gboolean active, gpointer user_data) | |
{ | |
g_print ("Signal: %s\n", active ? "Active" : "Inactive"); | |
} | |
static void | |
get_active_cb (GObject *object, GAsyncResult *result, gpointer user_data) | |
{ | |
FooDBusScreenSaver *proxy = FOO_DBUS_SCREEN_SAVER (object); | |
gboolean active; | |
g_autoptr (GError) error = NULL; | |
if (!foo_dbus_screen_saver_call_get_active_finish (proxy, &active, result, &error)) { | |
g_error ("Failed to call active: %s", error->message); | |
} | |
g_print ("GetActive: %s\n", active ? "Active" : "Inactive"); | |
} | |
static gboolean | |
timeout_cb (gpointer user_data) | |
{ | |
FooDBusScreenSaver *proxy = user_data; | |
foo_dbus_screen_saver_call_get_active (proxy, NULL, get_active_cb, NULL); | |
return TRUE; | |
} | |
static void | |
proxy_cb (GObject *object, GAsyncResult *result, gpointer user_data) | |
{ | |
FooDBusScreenSaver *proxy; | |
g_autoptr (GError) error = NULL; | |
proxy = foo_dbus_screen_saver_proxy_new_for_bus_finish (result, &error); | |
if (!proxy) { | |
g_error ("Failed to create proxy: %s", error->message); | |
} | |
g_signal_connect (proxy, "active-changed", G_CALLBACK (active_changed_cb), NULL); | |
g_timeout_add_seconds_full (G_PRIORITY_LOW, 1, timeout_cb, proxy, g_object_unref); | |
} | |
int | |
main (int argc, char *argv[]) | |
{ | |
g_autoptr (GMainLoop) mainloop = g_main_loop_new (NULL, TRUE); | |
foo_dbus_screen_saver_proxy_new_for_bus (G_BUS_TYPE_SESSION, 0, | |
"org.gnome.ScreenSaver", "/org/gnome/ScreenSaver", NULL, proxy_cb, NULL); | |
g_main_loop_run (mainloop); | |
return 0; | |
} |
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
foo: screensaver-gdbus.c foo.c | |
$(CC) -Wall -Wextra -Wno-unused-parameter $(CFLAGS) -o $@ `pkg-config --cflags --libs glib-2.0 gio-2.0 gio-unix-2.0` $^ | |
%-gdbus.c %-gdbus.h: %-dbus.xml | |
gdbus-codegen --interface-prefix org.gnome. --generate-c-code $*-gdbus --c-namespace Foo_DBus $< | |
screensaver-dbus.xml: | |
gdbus introspect -e -d org.gnome.ScreenSaver -o /org/gnome/ScreenSaver -x > $@ | |
clean: | |
rm -f foo screensaver-dbus.xml *-gdbus.? | |
.PHONY: clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment