summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2002-10-20 17:49:54 +0000
committerHavoc Pennington <hp@redhat.com>2002-10-20 17:49:54 +0000
commit58144125e0fe2b43bcb6aad75f258c8042b70feb (patch)
treed9008a50edad4eaf1a6e2e8c3deb7f899d998ba6 /test
downloadstartup-notification-58144125e0fe2b43bcb6aad75f258c8042b70feb.tar.gz
initial copy of liblf with files renamed to libsn
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am31
-rw-r--r--test/test-boilerplate.h122
-rw-r--r--test/test-launchee.c88
-rw-r--r--test/test-launcher.c126
-rw-r--r--test/test-monitor.c185
-rw-r--r--test/test-send-xmessage.c64
-rw-r--r--test/test-watch-xmessages.c118
7 files changed, 734 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..ab8fa4a
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,31 @@
+
+INCLUDES=$(LIBLF_CFLAGS) -I$(top_srcdir)
+
+noinst_PROGRAMS= \
+ test-launcher \
+ test-launchee \
+ test-monitor \
+ test-send-xmessage \
+ test-watch-xmessages
+
+test_launcher_SOURCES= test-launcher.c
+
+test_launcher_LDADD= $(LIBLF_LIBS) $(top_builddir)/liblf/liblf-1.la
+
+test_launchee_SOURCES= test-launchee.c
+
+test_launchee_LDADD= $(LIBLF_LIBS) $(top_builddir)/liblf/liblf-1.la
+
+test_monitor_SOURCES= test-monitor.c
+
+test_monitor_LDADD= $(LIBLF_LIBS) $(top_builddir)/liblf/liblf-1.la
+
+test_send_xmessage_SOURCES= test-send-xmessage.c
+
+test_send_xmessage_LDADD= $(LIBLF_LIBS) $(top_builddir)/liblf/liblf-1.la
+
+test_watch_xmessages_SOURCES= test-watch-xmessages.c
+
+test_watch_xmessages_LDADD= $(LIBLF_LIBS) $(top_builddir)/liblf/liblf-1.la
+
+EXTRA_DIST=test-boilerplate.h \ No newline at end of file
diff --git a/test/test-boilerplate.h b/test/test-boilerplate.h
new file mode 100644
index 0000000..90e1fbd
--- /dev/null
+++ b/test/test-boilerplate.h
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2002 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <signal.h>
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef NULL
+#define NULL ((void*) 0)
+#endif
+
+#ifdef HAVE_BACKTRACE
+#include <execinfo.h>
+static void
+print_backtrace (void)
+{
+ void *bt[500];
+ int bt_size;
+ int i;
+ char **syms;
+
+ bt_size = backtrace (bt, 500);
+
+ syms = backtrace_symbols (bt, bt_size);
+
+ i = 0;
+ while (i < bt_size)
+ {
+ fprintf (stderr, " %s\n", syms[i]);
+ ++i;
+ }
+
+ free (syms);
+}
+#else
+static void
+print_backtrace (void)
+{
+ fprintf (stderr, "Not compiled with backtrace support\n");
+}
+#endif
+
+static int error_trap_depth = 0;
+
+static int
+x_error_handler (Display *xdisplay,
+ XErrorEvent *error)
+{
+ char buf[64];
+
+ XGetErrorText (xdisplay, error->error_code, buf, 63);
+
+ if (error_trap_depth == 0)
+ {
+ print_backtrace ();
+
+ fprintf (stderr, "Unexpected X error: %s serial %ld error_code %d request_code %d minor_code %d)\n",
+ buf,
+ error->serial,
+ error->error_code,
+ error->request_code,
+ error->minor_code);
+
+ exit (1);
+ }
+
+ return 1; /* return value is meaningless */
+}
+
+static void
+error_trap_push (LfDisplay *display,
+ Display *xdisplay)
+{
+ ++error_trap_depth;
+}
+
+static void
+error_trap_pop (LfDisplay *display,
+ Display *xdisplay)
+{
+ if (error_trap_depth == 0)
+ {
+ fprintf (stderr, "Error trap underflow!\n");
+ exit (1);
+ }
+
+ XSync (xdisplay, False); /* get all errors out of the queue */
+ --error_trap_depth;
+}
diff --git a/test/test-launchee.c b/test/test-launchee.c
new file mode 100644
index 0000000..ef77b1c
--- /dev/null
+++ b/test/test-launchee.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2002 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <config.h>
+#include <liblf/lf.h>
+
+#include "test-boilerplate.h"
+
+int
+main (int argc, char **argv)
+{
+ Display *xdisplay;
+ LfDisplay *display;
+ LfLauncheeContext *context;
+ int i;
+
+ xdisplay = XOpenDisplay (NULL);
+ if (xdisplay == NULL)
+ {
+ fprintf (stderr, "Could not open display\n");
+ return 1;
+ }
+
+ if (getenv ("LIBLF_SYNC") != NULL)
+ XSynchronize (xdisplay, True);
+
+ XSetErrorHandler (x_error_handler);
+
+ display = lf_display_new (xdisplay,
+ error_trap_push,
+ error_trap_pop);
+
+ context = lf_launchee_context_new_from_environment (display);
+
+ if (context == NULL)
+ {
+ fprintf (stderr, "Failed to get launch feedback info from DESKTOP_LAUNCH_ID/DESKTOP_LAUNCH_WINDOW\n");
+ exit (1);
+ }
+
+ printf ("Launchee started with window 0x%lx ID \"%s\"\n",
+ lf_launchee_context_get_launch_window (context),
+ lf_launchee_context_get_launch_id (context));
+
+ /* simulate startup time */
+ i = 0;
+ while (i < 4)
+ {
+ sleep (1);
+ lf_launchee_context_pulse (context);
+ ++i;
+ }
+
+ printf ("Launchee startup complete\n");
+ lf_launchee_context_complete (context);
+
+ while (TRUE)
+ {
+ XEvent xevent;
+
+ XNextEvent (xdisplay, &xevent);
+
+ lf_display_process_event (display, &xevent);
+ }
+
+ return 0;
+}
diff --git a/test/test-launcher.c b/test/test-launcher.c
new file mode 100644
index 0000000..3a006e0
--- /dev/null
+++ b/test/test-launcher.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2002 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <config.h>
+#include <liblf/lf.h>
+
+#include "test-boilerplate.h"
+
+static pid_t child_pid = 0;
+
+static void
+launcher_event_func (LfLauncherEvent *event,
+ void *user_data)
+{
+ LfLauncherContext *context;
+
+ context = lf_launcher_event_get_context (event);
+
+ switch (lf_launcher_event_get_type (event))
+ {
+ case LF_LAUNCHER_EVENT_COMPLETED:
+ printf ("Completed!\n");
+ break;
+ case LF_LAUNCHER_EVENT_CANCELED:
+ printf ("Canceled!\n");
+ kill (child_pid, SIGTERM);
+ lf_launcher_context_complete (context);
+ break;
+ case LF_LAUNCHER_EVENT_PULSE:
+ printf (" pulse.\n");
+ break;
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ Display *xdisplay;
+ LfDisplay *display;
+ LfLauncherContext *context;
+
+ if (argc < 2)
+ {
+ fprintf (stderr, "must specify command line to launch\n");
+ exit (1);
+ }
+
+ xdisplay = XOpenDisplay (NULL);
+ if (xdisplay == NULL)
+ {
+ fprintf (stderr, "Could not open display\n");
+ return 1;
+ }
+
+ if (getenv ("LIBLF_SYNC") != NULL)
+ XSynchronize (xdisplay, True);
+
+ XSetErrorHandler (x_error_handler);
+
+ display = lf_display_new (xdisplay,
+ error_trap_push,
+ error_trap_pop);
+
+ context = lf_launcher_context_new (display,
+ launcher_event_func,
+ NULL, NULL);
+
+ lf_launcher_context_set_launch_name (context, "Test Launch");
+ lf_launcher_context_set_launch_description (context, "Launching a test program for liblf");
+ lf_launcher_context_set_supports_cancel (context, TRUE);
+ lf_launcher_context_set_binary_name (context, argv[1]);
+
+ lf_launcher_context_initiate (context,
+ "test-launcher",
+ argv[1],
+ CurrentTime); /* CurrentTime bad */
+
+ switch ((child_pid = fork ()))
+ {
+ case -1:
+ fprintf (stderr, "Fork failed: %s\n", strerror (errno));
+ break;
+ case 0:
+ lf_launcher_context_setup_child_process (context);
+ execv (argv[1], argv + 1);
+ fprintf (stderr, "Failed to exec %s: %s\n", argv[1], strerror (errno));
+ _exit (1);
+ break;
+ }
+
+ lf_launcher_context_set_pid (context, child_pid);
+
+ while (TRUE)
+ {
+ XEvent xevent;
+
+ XNextEvent (xdisplay, &xevent);
+
+ lf_display_process_event (display, &xevent);
+ }
+
+ lf_launcher_context_unref (context);
+
+ return 0;
+}
diff --git a/test/test-monitor.c b/test/test-monitor.c
new file mode 100644
index 0000000..59d4524
--- /dev/null
+++ b/test/test-monitor.c
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2002 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <config.h>
+#include <liblf/lf.h>
+
+#include "test-boilerplate.h"
+
+static void
+monitor_event_func (LfMonitorEvent *event,
+ void *user_data)
+{
+ LfMonitorContext *context;
+ LfLaunchSequence *sequence;
+
+ context = lf_monitor_event_get_context (event);
+ sequence = lf_monitor_event_get_launch_sequence (event);
+
+ switch (lf_monitor_event_get_type (event))
+ {
+ case LF_MONITOR_EVENT_INITIATED:
+ {
+ int x, y, w, h;
+ const char *s;
+
+ printf ("Initiated sequence %s\n",
+ lf_launch_sequence_get_id (sequence));
+ printf (" launch window 0x%lx\n",
+ lf_launch_sequence_get_window (sequence));
+
+ s = lf_launch_sequence_get_name (sequence);
+ printf (" name %s\n", s ? s : "(unset)");
+
+ s = lf_launch_sequence_get_description (sequence);
+ printf (" description %s\n", s ? s : "(unset)");
+
+ printf (" workspace %d\n",
+ lf_launch_sequence_get_workspace (sequence));
+
+ printf (" %s cancel\n",
+ lf_launch_sequence_get_supports_cancel (sequence) ?
+ "supports" : "does not support");
+
+ if (lf_launch_sequence_get_geometry (sequence,
+ &x, &y, &w, &h))
+ printf (" geometry %d,%d %d x %d window 0x%lx\n",
+ x, y, w, h,
+ lf_launch_sequence_get_geometry_window (sequence));
+ else
+ printf (" no geometry set\n");
+
+ printf (" pid %d\n",
+ lf_launch_sequence_get_pid (sequence));
+
+ s = lf_launch_sequence_get_binary_name (sequence);
+ printf (" binary name %s\n", s ? s : "(unset)");
+ s = lf_launch_sequence_get_icon_name (sequence);
+ printf (" icon name %s\n", s ? s : "(unset)");
+ s = lf_launch_sequence_get_hostname (sequence);
+ printf (" hostname %s\n", s ? s : "(unset)");
+
+ s = lf_launch_sequence_get_legacy_resource_class (sequence);
+ printf (" legacy class %s\n", s ? s : "(unset)");
+ s = lf_launch_sequence_get_legacy_resource_name (sequence);
+ printf (" legacy name %s\n", s ? s : "(unset)");
+ s = lf_launch_sequence_get_legacy_window_title (sequence);
+ printf (" legacy title %s\n", s ? s : "(unset)");
+ }
+ break;
+
+ case LF_MONITOR_EVENT_COMPLETED:
+ printf ("Completed sequence %s\n",
+ lf_launch_sequence_get_id (sequence));
+ break;
+
+ case LF_MONITOR_EVENT_CANCELED:
+ printf ("Canceled sequence %s\n",
+ lf_launch_sequence_get_id (sequence));
+ break;
+
+ case LF_MONITOR_EVENT_PULSE:
+ printf ("Pulse for sequence %s\n",
+ lf_launch_sequence_get_id (sequence));
+ break;
+
+ case LF_MONITOR_EVENT_GEOMETRY_CHANGED:
+ {
+ int x, y, w, h;
+
+ printf ("Geometry changed for sequence %s\n",
+ lf_launch_sequence_get_id (sequence));
+ if (lf_launch_sequence_get_geometry (sequence,
+ &x, &y, &w, &h))
+ printf (" geometry %d,%d %d x %d window 0x%lx\n",
+ x, y, w, h,
+ lf_launch_sequence_get_geometry_window (sequence));
+ else
+ printf (" no geometry set\n");
+ }
+ break;
+ case LF_MONITOR_EVENT_PID_CHANGED:
+ {
+ printf ("PID for sequence %s is now %d\n",
+ lf_launch_sequence_get_id (sequence),
+ lf_launch_sequence_get_pid (sequence));
+ }
+ break;
+ case LF_MONITOR_EVENT_WORKSPACE_CHANGED:
+ {
+ printf ("Workspace for sequence %s is now %d\n",
+ lf_launch_sequence_get_id (sequence),
+ lf_launch_sequence_get_workspace (sequence));
+ }
+ break;
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ Display *xdisplay;
+ LfDisplay *display;
+ LfMonitorContext *context;
+
+ xdisplay = XOpenDisplay (NULL);
+ if (xdisplay == NULL)
+ {
+ fprintf (stderr, "Could not open display\n");
+ return 1;
+ }
+
+ if (getenv ("LIBLF_SYNC") != NULL)
+ XSynchronize (xdisplay, True);
+
+ XSetErrorHandler (x_error_handler);
+
+ /* We have to select for property events on at least one
+ * root window (but not all as INITIATE messages go to
+ * all root windows)
+ */
+ XSelectInput (xdisplay, DefaultRootWindow (xdisplay),
+ PropertyChangeMask);
+
+ display = lf_display_new (xdisplay,
+ error_trap_push,
+ error_trap_pop);
+
+ context = lf_monitor_context_new (display,
+ monitor_event_func,
+ NULL, NULL);
+
+ while (TRUE)
+ {
+ XEvent xevent;
+
+ XNextEvent (xdisplay, &xevent);
+
+ lf_display_process_event (display, &xevent);
+ }
+
+ lf_monitor_context_unref (context);
+
+ return 0;
+}
diff --git a/test/test-send-xmessage.c b/test/test-send-xmessage.c
new file mode 100644
index 0000000..3052a60
--- /dev/null
+++ b/test/test-send-xmessage.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2002 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <config.h>
+#include <liblf/lf.h>
+#include <liblf/lf-xmessages.h>
+
+#include "test-boilerplate.h"
+
+int
+main (int argc, char **argv)
+{
+ Display *xdisplay;
+ LfDisplay *display;
+
+ if (argc != 3)
+ {
+ fprintf (stderr, "Must specify message type and message content as first and second args\n");
+ return 1;
+ }
+
+ xdisplay = XOpenDisplay (NULL);
+ if (xdisplay == NULL)
+ {
+ fprintf (stderr, "Could not open display\n");
+ return 1;
+ }
+
+ if (getenv ("LIBLF_SYNC") != NULL)
+ XSynchronize (xdisplay, True);
+
+ XSetErrorHandler (x_error_handler);
+
+ display = lf_display_new (xdisplay,
+ error_trap_push,
+ error_trap_pop);
+
+ lf_internal_broadcast_xmessage (display,
+ argv[1],
+ argv[2]);
+
+ return 0;
+}
diff --git a/test/test-watch-xmessages.c b/test/test-watch-xmessages.c
new file mode 100644
index 0000000..150af5c
--- /dev/null
+++ b/test/test-watch-xmessages.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2002 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <config.h>
+#include <liblf/lf.h>
+#include <liblf/lf-xmessages.h>
+#include <liblf/lf-internals.h>
+
+#include "test-boilerplate.h"
+
+static void
+message_func (LfDisplay *display,
+ const char *message_type,
+ const char *message,
+ void *user_data)
+{
+ char *prefix;
+ char **names;
+ char **values;
+ int i;
+
+#if 0
+ printf ("raw %s: %s\n",
+ message_type, message);
+#endif
+
+ prefix = NULL;
+ names = NULL;
+ values = NULL;
+
+ if (lf_internal_unserialize_message (message,
+ &prefix, &names, &values))
+ {
+ printf (" %s:\n", prefix);
+
+ i = 0;
+ while (names && names[i])
+ {
+ printf (" '%s' = '%s'\n", names[i], values[i]);
+
+ ++i;
+ }
+
+ lf_internal_strfreev (names);
+ lf_internal_strfreev (values);
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ Display *xdisplay;
+ LfDisplay *display;
+
+ if (argc != 2)
+ {
+ fprintf (stderr, "argument must be type of events to watch\n");
+ return 1;
+ }
+
+ xdisplay = XOpenDisplay (NULL);
+ if (xdisplay == NULL)
+ {
+ fprintf (stderr, "Could not open display\n");
+ return 1;
+ }
+
+ if (getenv ("LIBLF_SYNC") != NULL)
+ XSynchronize (xdisplay, True);
+
+ XSetErrorHandler (x_error_handler);
+
+ /* We have to select for property events on one root window
+ */
+ XSelectInput (xdisplay, DefaultRootWindow (xdisplay),
+ PropertyChangeMask);
+
+ display = lf_display_new (xdisplay,
+ error_trap_push,
+ error_trap_pop);
+
+ lf_internal_add_xmessage_func (display,
+ argv[1],
+ message_func,
+ NULL, NULL);
+
+ while (TRUE)
+ {
+ XEvent xevent;
+
+ XNextEvent (xdisplay, &xevent);
+
+ lf_display_process_event (display, &xevent);
+ }
+
+ return 0;
+}