summaryrefslogtreecommitdiff
path: root/libgnome-desktop/test-idle-monitor.c
blob: 713f12cfb871a743da4a7aa5fed92c46d9eabfae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <gtk/gtk.h>
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include "libgnome-desktop/gnome-idle-monitor.h"

#define IDLE_TIME 1000 * 5 /* 5 seconds */

static void
active_watch_func (GnomeIdleMonitor *monitor,
		   guint             id,
		   gpointer          user_data)
{
	g_message ("Active watch func called (watch id %d)", id);
}

static void
ensure_active_watch (GnomeIdleMonitor *monitor)
{
	guint watch_id;

	watch_id = gnome_idle_monitor_add_user_active_watch (monitor,
							     active_watch_func,
							     NULL,
							     NULL);
	g_message ("Added active watch ID %d", watch_id);
}

static void
idle_watch_func (GnomeIdleMonitor      *monitor,
		 guint                  id,
		 gpointer               user_data)
{
	g_message ("Idle watch func called (watch id %d)", id);
	ensure_active_watch (monitor);
}

int main (int argc, char **argv)
{
	GnomeIdleMonitor *monitor;
	guint watch_id;

	gtk_init (&argc, &argv);

	monitor = gnome_idle_monitor_new ();
	watch_id = gnome_idle_monitor_add_idle_watch (monitor,
						      IDLE_TIME,
						      idle_watch_func,
						      NULL,
						      NULL);
	g_message ("Added idle watch ID %d",
		   watch_id);

	ensure_active_watch (monitor);

	gtk_main ();

	return 0;
}