Debian Codegraph @

test/test-monitor.c

raw symbols SCIP
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
28 #include "test-boilerplate.h"
29
30 static void
31 monitor_event_func (SnMonitorEvent *event,
32 void *user_data)
33 {
34 SnMonitorContext *context;
35 SnStartupSequence *sequence;
36
37 context = sn_monitor_event_get_context (event);
38 sequence = sn_monitor_event_get_startup_sequence (event);
39
40 switch (sn_monitor_event_get_type (event))
41 {
42 case SN_MONITOR_EVENT_INITIATED:
43 case SN_MONITOR_EVENT_CHANGED:
44 {
45 const char *s;
46
47 if (sn_monitor_event_get_type (event) == SN_MONITOR_EVENT_INITIATED)
48 {
49 printf ("Initiated sequence %s\n",
50 sn_startup_sequence_get_id (sequence));
51 }
52 else
53 {
54 printf ("Changed sequence %s\n",
55 sn_startup_sequence_get_id (sequence));
56 }
57
58 s = sn_startup_sequence_get_id (sequence);
59 printf (" id %s\n", s ? s : "(unset)");
60
61 s = sn_startup_sequence_get_name (sequence);
62 printf (" name %s\n", s ? s : "(unset)");
63
64 s = sn_startup_sequence_get_description (sequence);
65 printf (" description %s\n", s ? s : "(unset)");
66
67 printf (" workspace %d\n",
68 sn_startup_sequence_get_workspace (sequence));
69
70 s = sn_startup_sequence_get_binary_name (sequence);
71 printf (" binary name %s\n", s ? s : "(unset)");
72 s = sn_startup_sequence_get_icon_name (sequence);
73 printf (" icon name %s\n", s ? s : "(unset)");
74
75 s = sn_startup_sequence_get_wmclass (sequence);
76 printf (" wm class %s\n", s ? s : "(unset)");
77 }
78 break;
79
80 case SN_MONITOR_EVENT_COMPLETED:
81 printf ("Completed sequence %s\n",
82 sn_startup_sequence_get_id (sequence));
83 break;
84
85 case SN_MONITOR_EVENT_CANCELED:
86 printf ("Canceled sequence %s\n",
87 sn_startup_sequence_get_id (sequence));
88 break;
89 }
90 }
91
92 int
93 main (int argc, char **argv)
94 {
95 Display *xdisplay;
96 SnDisplay *display;
97 SnMonitorContext *context;
98
99 xdisplay = XOpenDisplay (NULL);
100 if (xdisplay == NULL)
101 {
102 fprintf (stderr, "Could not open display\n");
103 return 1;
104 }
105
106 if (getenv ("LIBSN_SYNC") != NULL)
107 XSynchronize (xdisplay, True);
108
109 XSetErrorHandler (x_error_handler);
110
111 /* We have to select for property events on at least one
112 * root window (but not all as INITIATE messages go to
113 * all root windows)
114 */
115 XSelectInput (xdisplay, DefaultRootWindow (xdisplay),
116 PropertyChangeMask);
117
118 display = sn_display_new (xdisplay,
119 error_trap_push,
120 error_trap_pop);
121
122 context = sn_monitor_context_new (display, DefaultScreen (xdisplay),
123 monitor_event_func,
124 NULL, NULL);
125
126 while (TRUE)
127 {
128 XEvent xevent;
129
130 XNextEvent (xdisplay, &xevent);
131
132 sn_display_process_event (display, &xevent);
133 }
134
135 sn_monitor_context_unref (context);
136
137 return 0;
138 }