2 * Copyright © 2012 Intel Corporation
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
29 #include <wayland-client.h>
30 #include "../clients/text-client-protocol.h"
33 struct wl_display *display;
34 struct wl_compositor *compositor;
36 struct wl_surface *surface;
39 struct text_model_factory *factory;
40 struct text_model *text_model;
42 unsigned int activated;
43 unsigned int deactivated;
47 text_model_commit_string(void *data,
48 struct text_model *text_model,
55 text_model_preedit_string(void *data,
56 struct text_model *text_model,
63 text_model_preedit_styling(void *data,
64 struct text_model *text_model)
69 text_model_key(void *data,
70 struct text_model *text_model)
75 text_model_selection_replacement(void *data,
76 struct text_model *text_model)
81 text_model_direction(void *data,
82 struct text_model *text_model)
87 text_model_locale(void *data,
88 struct text_model *text_model)
93 text_model_activated(void *data,
94 struct text_model *text_model)
96 struct display *display = data;
98 fprintf(stderr, "%s\n", __FUNCTION__);
100 display->activated += 1;
104 text_model_deactivated(void *data,
105 struct text_model *text_model)
107 struct display *display = data;
109 display->deactivated += 1;
112 static const struct text_model_listener text_model_listener = {
113 text_model_commit_string,
114 text_model_preedit_string,
115 text_model_preedit_styling,
117 text_model_selection_replacement,
118 text_model_direction,
120 text_model_activated,
121 text_model_deactivated
125 handle_global(struct wl_display *_display, uint32_t id,
126 const char *interface, uint32_t version, void *data)
128 struct display *display = data;
130 if (strcmp(interface, "wl_compositor") == 0) {
131 display->compositor =
132 wl_display_bind(display->display,
133 id, &wl_compositor_interface);
134 } else if (strcmp(interface, "wl_seat") == 0) {
135 display->seat = wl_display_bind(display->display, id,
137 } else if (strcmp(interface, "text_model_factory") == 0) {
138 display->factory = wl_display_bind(display->display, id,
139 &text_model_factory_interface);
144 create_surface(int fd, struct display *display)
149 display->surface = wl_compositor_create_surface(display->compositor);
150 wl_display_flush(display->display);
152 len = snprintf(buf, sizeof buf, "surface %d\n",
153 wl_proxy_get_id((struct wl_proxy *) display->surface));
154 assert(write(fd, buf, len) == len);
158 create_text_model(int fd, struct display *display)
163 display->text_model = text_model_factory_create_text_model(display->factory);
164 text_model_add_listener(display->text_model, &text_model_listener, display);
165 wl_display_flush(display->display);
167 len = snprintf(buf, sizeof buf, "text_model %d\n",
168 wl_proxy_get_id((struct wl_proxy *) display->text_model));
169 assert(write(fd, buf, len) == len);
173 write_state(int fd, struct display *display)
178 wl_display_flush(display->display);
179 len = snprintf(buf, sizeof buf, "activated %u deactivated %u\n",
180 display->activated, display->deactivated);
181 assert(write(fd, buf, len) == len);
182 wl_display_roundtrip(display->display);
186 activate_text_model(int fd, struct display *display)
188 write_state(fd, display);
190 text_model_activate(display->text_model, display->seat, display->surface);
192 wl_display_flush(display->display);
193 wl_display_roundtrip(display->display);
197 deactivate_text_model(int fd, struct display *display)
199 write_state(fd, display);
201 text_model_deactivate(display->text_model, display->seat);
203 wl_display_flush(display->display);
204 wl_display_roundtrip(display->display);
207 int main(int argc, char *argv[])
209 struct display *display;
213 display = malloc(sizeof *display);
216 display->display = wl_display_connect(NULL);
217 assert(display->display);
219 display->activated = 0;
220 display->deactivated = 0;
222 wl_display_add_global_listener(display->display,
223 handle_global, display);
224 wl_display_iterate(display->display, WL_DISPLAY_READABLE);
225 wl_display_roundtrip(display->display);
228 p = getenv("TEST_SOCKET");
230 fd = strtol(p, NULL, 0);
233 ret = read(fd, buf, sizeof buf);
235 fprintf(stderr, "read error: fd %d, %m\n", fd);
239 fprintf(stderr, "test-client: got %.*s\n", ret - 1, buf);
241 if (strncmp(buf, "bye\n", ret) == 0) {
243 } else if (strncmp(buf, "create-surface\n", ret) == 0) {
244 create_surface(fd, display);
245 } else if (strncmp(buf, "create-text-model\n", ret) == 0) {
246 create_text_model(fd, display);
247 } else if (strncmp(buf, "activate-text-model\n", ret) == 0) {
248 activate_text_model(fd, display);
249 } else if (strncmp(buf, "deactivate-text-model\n", ret) == 0) {
250 deactivate_text_model(fd, display);
251 } else if (strncmp(buf, "assert-state\n", ret) == 0) {
252 write_state(fd, display);
254 fprintf(stderr, "unknown command %.*s\n", ret, buf);