source: trunk/third/startup-notification/test/test-watch-xmessages.c @ 18723

Revision 18723, 3.1 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18722, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * Copyright (C) 2002 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#include <config.h>
26#include <libsn/sn.h>
27#include <libsn/sn-xmessages.h>
28#include <libsn/sn-internals.h>
29
30#include "test-boilerplate.h"
31
32static void
33message_func (SnDisplay       *display,
34              const char      *message_type,
35              const char      *message,
36              void            *user_data)
37{
38  char *prefix;
39  char **names;
40  char **values;
41  int i;
42
43#if 0
44  printf ("raw %s: %s\n",
45          message_type, message);
46#endif
47 
48  prefix = NULL;
49  names = NULL;
50  values = NULL;
51
52  if (sn_internal_unserialize_message (message,
53                                       &prefix, &names, &values))
54    {
55      printf (" %s:\n", prefix);
56
57      i = 0;
58      while (names && names[i])
59        {
60          printf ("   '%s' = '%s'\n", names[i], values[i]);
61         
62          ++i;
63        }
64
65      sn_internal_strfreev (names);
66      sn_internal_strfreev (values);
67    }
68}
69
70int
71main (int argc, char **argv)
72{
73  Display *xdisplay;
74  SnDisplay *display;
75
76  if (argc != 3)
77    {
78      fprintf (stderr, "arguments must be type and begin type of events to watch\n");
79      return 1;
80    }
81 
82  xdisplay = XOpenDisplay (NULL);
83  if (xdisplay == NULL)
84    {
85      fprintf (stderr, "Could not open display\n");
86      return 1;
87    }
88
89  if (getenv ("LIBSN_SYNC") != NULL)
90    XSynchronize (xdisplay, True);
91 
92  XSetErrorHandler (x_error_handler);
93
94  /* We have to select for property events on one root window
95   */
96  XSelectInput (xdisplay, DefaultRootWindow (xdisplay),
97                PropertyChangeMask);
98 
99  display = sn_display_new (xdisplay,
100                            error_trap_push,
101                            error_trap_pop);
102
103  sn_internal_add_xmessage_func (display, DefaultScreen (xdisplay),
104                                 argv[1], argv[2],
105                                 message_func,
106                                 NULL, NULL);
107 
108  while (TRUE)
109    {
110      XEvent xevent;
111
112      XNextEvent (xdisplay, &xevent);
113
114      sn_display_process_event (display, &xevent);
115    }
116 
117  return 0;
118}
Note: See TracBrowser for help on using the repository browser.