summaryrefslogtreecommitdiff
path: root/doc/example-lazy-initialization.c
diff options
context:
space:
mode:
authorVincent Untz <vuntz@gnome.org>2011-02-18 18:11:24 +0100
committerVincent Untz <vuntz@gnome.org>2011-02-18 18:11:24 +0100
commit923f6fb7b25dabbe83d846acea09bb68e021fc1a (patch)
treea0db4d766db0b4dc2c234d304ac1e1a9464dcb4d /doc/example-lazy-initialization.c
parentdae2284998cdf1aba6c921403ec612ed282ea564 (diff)
downloadlibwnck-923f6fb7b25dabbe83d846acea09bb68e021fc1a.tar.gz
doc: Add some high-level documentation
This includes hints as to when to use the library, common pitfalls and two simple examples. https://bugzilla.gnome.org/show_bug.cgi?id=344137
Diffstat (limited to 'doc/example-lazy-initialization.c')
-rw-r--r--doc/example-lazy-initialization.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/doc/example-lazy-initialization.c b/doc/example-lazy-initialization.c
new file mode 100644
index 0000000..dca0598
--- /dev/null
+++ b/doc/example-lazy-initialization.c
@@ -0,0 +1,51 @@
+#include <libwnck/libwnck.h>
+
+static void
+on_window_opened (WnckScreen *screen,
+ WnckWindow *window,
+ gpointer data)
+{
+ /* Note: when this event is emitted while screen is initialized, there is no
+ * active window yet. */
+
+ g_print ("%s\n", wnck_window_get_name (window));
+}
+
+static void
+on_active_window_changed (WnckScreen *screen,
+ WnckWindow *previously_active_window,
+ gpointer data)
+{
+ WnckWindow *active_window;
+
+ active_window = wnck_screen_get_active_window (screen);
+
+ if (active_window)
+ g_print ("active: %s\n", wnck_window_get_name (active_window));
+ else
+ g_print ("no active window\n");
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ GMainLoop *loop;
+ WnckScreen *screen;
+
+ gdk_init (&argc, &argv);
+
+ loop = g_main_loop_new (NULL, FALSE);
+ screen = wnck_screen_get_default ();
+
+ g_signal_connect (screen, "window-opened",
+ G_CALLBACK (on_window_opened), NULL);
+ g_signal_connect (screen, "active-window-changed",
+ G_CALLBACK (on_active_window_changed), NULL);
+
+ g_main_loop_run (loop);
+
+ g_main_loop_unref (loop);
+
+ return 0;
+}