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_delete_surrounding_text(void *data,
64 struct text_model *text_model,
71 text_model_preedit_styling(void *data,
72 struct text_model *text_model)
77 text_model_key(void *data,
78 struct text_model *text_model)
83 text_model_selection_replacement(void *data,
84 struct text_model *text_model)
89 text_model_direction(void *data,
90 struct text_model *text_model)
95 text_model_locale(void *data,
96 struct text_model *text_model)
101 text_model_activated(void *data,
102 struct text_model *text_model)
104 struct display *display = data;
106 fprintf(stderr, "%s\n", __FUNCTION__);
108 display->activated += 1;
112 text_model_deactivated(void *data,
113 struct text_model *text_model)
115 struct display *display = data;
117 display->deactivated += 1;
120 static const struct text_model_listener text_model_listener = {
121 text_model_commit_string,
122 text_model_preedit_string,
123 text_model_delete_surrounding_text,
124 text_model_preedit_styling,
126 text_model_selection_replacement,
127 text_model_direction,
129 text_model_activated,
130 text_model_deactivated
134 handle_global(struct wl_display *_display, uint32_t id,
135 const char *interface, uint32_t version, void *data)
137 struct display *display = data;
139 if (strcmp(interface, "wl_compositor") == 0) {
140 display->compositor =
141 wl_display_bind(display->display,
142 id, &wl_compositor_interface);
143 } else if (strcmp(interface, "wl_seat") == 0) {
144 display->seat = wl_display_bind(display->display, id,
146 } else if (strcmp(interface, "text_model_factory") == 0) {
147 display->factory = wl_display_bind(display->display, id,
148 &text_model_factory_interface);
153 create_surface(int fd, struct display *display)
158 display->surface = wl_compositor_create_surface(display->compositor);
159 wl_display_flush(display->display);
161 len = snprintf(buf, sizeof buf, "surface %d\n",
162 wl_proxy_get_id((struct wl_proxy *) display->surface));
163 assert(write(fd, buf, len) == len);
167 create_text_model(int fd, struct display *display)
172 display->text_model = text_model_factory_create_text_model(display->factory);
173 text_model_add_listener(display->text_model, &text_model_listener, display);
174 wl_display_flush(display->display);
176 len = snprintf(buf, sizeof buf, "text_model %d\n",
177 wl_proxy_get_id((struct wl_proxy *) display->text_model));
178 assert(write(fd, buf, len) == len);
182 write_state(int fd, struct display *display)
187 wl_display_flush(display->display);
188 len = snprintf(buf, sizeof buf, "activated %u deactivated %u\n",
189 display->activated, display->deactivated);
190 assert(write(fd, buf, len) == len);
191 wl_display_roundtrip(display->display);
195 activate_text_model(int fd, struct display *display)
197 write_state(fd, display);
199 text_model_activate(display->text_model, display->seat, display->surface);
201 wl_display_flush(display->display);
202 wl_display_roundtrip(display->display);
206 deactivate_text_model(int fd, struct display *display)
208 write_state(fd, display);
210 text_model_deactivate(display->text_model, display->seat);
212 wl_display_flush(display->display);
213 wl_display_roundtrip(display->display);
216 int main(int argc, char *argv[])
218 struct display *display;
222 display = malloc(sizeof *display);
225 display->display = wl_display_connect(NULL);
226 assert(display->display);
228 display->activated = 0;
229 display->deactivated = 0;
231 wl_display_add_global_listener(display->display,
232 handle_global, display);
233 wl_display_iterate(display->display, WL_DISPLAY_READABLE);
234 wl_display_roundtrip(display->display);
237 p = getenv("TEST_SOCKET");
239 fd = strtol(p, NULL, 0);
242 ret = read(fd, buf, sizeof buf);
244 fprintf(stderr, "read error: fd %d, %m\n", fd);
248 fprintf(stderr, "test-client: got %.*s\n", ret - 1, buf);
250 if (strncmp(buf, "bye\n", ret) == 0) {
252 } else if (strncmp(buf, "create-surface\n", ret) == 0) {
253 create_surface(fd, display);
254 } else if (strncmp(buf, "create-text-model\n", ret) == 0) {
255 create_text_model(fd, display);
256 } else if (strncmp(buf, "activate-text-model\n", ret) == 0) {
257 activate_text_model(fd, display);
258 } else if (strncmp(buf, "deactivate-text-model\n", ret) == 0) {
259 deactivate_text_model(fd, display);
260 } else if (strncmp(buf, "assert-state\n", ret) == 0) {
261 write_state(fd, display);
263 fprintf(stderr, "unknown command %.*s\n", ret, buf);