Debian Codegraph @

test/test-watch-xmessages-xcb.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * Copyright (C) 2002 Red Hat, Inc.
3 * Copyright (C) 2009 Julien Danjou <[email protected]>
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26 #include <config.h>
27 #include <libsn/sn.h>
28 #include <libsn/sn-xmessages.h>
29 #include <libsn/sn-internals.h>
30
31 #include <xcb/xcb_aux.h>
32
33 #include "test-boilerplate.h"
34
35 static void
36 message_func (SnDisplay *display,
37 const char *message_type,
38 const char *message,
39 void *user_data)
40 {
41 char *prefix;
42 char **names;
43 char **values;
44 int i;
45
46 #if 0
47 printf ("raw %s: %s\n",
48 message_type, message);
49 #endif
50
51 prefix = NULL;
52 names = NULL;
53 values = NULL;
54
55 if (sn_internal_unserialize_message (message,
56 &prefix, &names, &values))
57 {
58 printf (" %s:\n", prefix);
59
60 i = 0;
61 while (names && names[i])
62 {
63 printf (" '%s' = '%s'\n", names[i], values[i]);
64
65 ++i;
66 }
67
68 sn_internal_strfreev (names);
69 sn_internal_strfreev (values);
70 }
71 }
72
73 int
74 main (int argc, char **argv)
75 {
76 xcb_connection_t *xconnection;
77 SnDisplay *display;
78
79 if (argc != 3)
80 {
•81 fprintf (stderr, "arguments must be type and begin type (as names) of events to watch\n");
82 return 1;
83 }
84
85 int screen;
86 xconnection = xcb_connect (NULL, &screen);
87 if (xconnection == NULL)
88 {
89 fprintf (stderr, "Could not open display\n");
90 return 1;
91 }
92
93 /* We have to select for property events on one root window
94 */
95 xcb_screen_t *s = xcb_aux_get_screen (xconnection, screen);
96 const uint32_t select_input_val[] = { XCB_EVENT_MASK_PROPERTY_CHANGE };
97 xcb_change_window_attributes (xconnection, s->root, XCB_CW_EVENT_MASK,
98 select_input_val);
99
100 display = sn_xcb_display_new (xconnection, NULL, NULL);
101
102 sn_internal_add_xmessage_func (display, screen,
103 argv[1], argv[2],
104 message_func,
105 NULL, NULL);
106
107 while (TRUE)
108 {
109 xcb_generic_event_t *xevent = xcb_wait_for_event (xconnection);
110
111 sn_xcb_display_process_event (display, xevent);
112
113 free (xevent);
114 }
115
116 return 0;
117 }