[gnome-desktop] idle-monitor: Add test application
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop] idle-monitor: Add test application
- Date: Mon, 12 Nov 2012 18:19:32 +0000 (UTC)
commit 4c8d0bc7b22dea06d97573b5ed9c4f32d6ebac49
Author: Bastien Nocera <hadess hadess net>
Date: Mon Nov 12 19:13:06 2012 +0100
idle-monitor: Add test application
libgnome-desktop/Makefile.am | 4 +-
libgnome-desktop/test-idle-monitor.c | 100 ++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+), 1 deletions(-)
---
diff --git a/libgnome-desktop/Makefile.am b/libgnome-desktop/Makefile.am
index df060b3..fc24a9b 100644
--- a/libgnome-desktop/Makefile.am
+++ b/libgnome-desktop/Makefile.am
@@ -133,7 +133,7 @@ gnome_rr_debug_LDADD = \
$(lib_LTLIBRARIES) \
$(XLIB_LIBS)
-noinst_PROGRAMS = test-xkb-info test-pnp-ids test-wall-clock test-desktop-thumbnail
+noinst_PROGRAMS = test-xkb-info test-pnp-ids test-wall-clock test-desktop-thumbnail test-idle-monitor
test_xkb_info_LDADD = \
$(GNOME_DESKTOP_LIBS) \
$(lib_LTLIBRARIES) \
@@ -145,4 +145,6 @@ test_wall_clock_LDADD = $(test_xkb_info_LDADD)
test_desktop_thumbnail_LDADD = $(test_xkb_info_LDADD)
+test_idle_monitor_LDADD = $(test_xkb_info_LDADD)
+
-include $(top_srcdir)/git.mk
diff --git a/libgnome-desktop/test-idle-monitor.c b/libgnome-desktop/test-idle-monitor.c
new file mode 100644
index 0000000..aa68e56
--- /dev/null
+++ b/libgnome-desktop/test-idle-monitor.c
@@ -0,0 +1,100 @@
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#define GNOME_DESKTOP_USE_UNSTABLE_API
+#include "libgnome-desktop/gnome-idle-monitor.h"
+
+GHashTable *monitors = NULL; /* key = device id, value = GnomeIdleMonitor */
+
+static void
+watch_func (GnomeIdleMonitor *monitor,
+ guint id,
+ gpointer user_data)
+{
+ GdkDevice *device;
+ int device_id;
+
+ g_object_get (monitor, "device", &device, NULL);
+ device_id = gdk_x11_device_get_id (device);
+ g_message ("Watch func called for device %s (id: %d, watch id %d)",
+ gdk_device_get_name (device),
+ device_id,
+ id);
+ g_object_unref (device);
+}
+
+static void
+device_added_cb (GdkDeviceManager *manager,
+ GdkDevice *device,
+ gpointer user_data)
+{
+ GnomeIdleMonitor *monitor;
+ guint watch_id;
+ int device_id;
+
+ device_id = gdk_x11_device_get_id (device);
+ monitor = gnome_idle_monitor_new_for_device (device);
+ watch_id = gnome_idle_monitor_add_watch (monitor,
+ 10,
+ watch_func,
+ NULL,
+ NULL);
+ g_message ("Added watch ID %d for device %s (%d)",
+ watch_id,
+ gdk_device_get_name (device),
+ device_id);
+ g_hash_table_insert (monitors,
+ GINT_TO_POINTER (device_id),
+ monitor);
+}
+
+static void
+device_removed_cb (GdkDeviceManager *manager,
+ GdkDevice *device,
+ gpointer user_data)
+{
+ g_hash_table_remove (monitors,
+ GINT_TO_POINTER (gdk_x11_device_get_id (device)));
+ g_message ("Removed watch for device %s (%d)",
+ gdk_device_get_name (device),
+ gdk_x11_device_get_id (device));
+}
+
+static void
+device_changed_cb (GdkDeviceManager *manager,
+ GdkDevice *device,
+ gpointer user_data)
+{
+ if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_FLOATING)
+ device_removed_cb (manager, device, NULL);
+ else
+ device_added_cb (manager, device, NULL);
+}
+
+int main (int argc, char **argv)
+{
+ GdkDeviceManager *manager;
+ GList *devices, *l;
+
+ gtk_init (&argc, &argv);
+
+ monitors = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ NULL, g_object_unref);
+
+ manager = gdk_display_get_device_manager (gdk_display_get_default ());
+ g_signal_connect (manager, "device-added",
+ G_CALLBACK (device_added_cb), NULL);
+ g_signal_connect (manager, "device-removed",
+ G_CALLBACK (device_removed_cb), NULL);
+ g_signal_connect (manager, "device-changed",
+ G_CALLBACK (device_changed_cb), NULL);
+ devices = gdk_device_manager_list_devices (manager, GDK_DEVICE_TYPE_SLAVE);
+ for (l = devices; l != NULL; l = l->next) {
+ GdkDevice *device = l->data;
+
+ device_added_cb (manager, device, NULL);
+ }
+
+ gtk_main ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]