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,
85 text_model_selection_replacement(void *data,
86 struct text_model *text_model)
91 text_model_direction(void *data,
92 struct text_model *text_model)
97 text_model_locale(void *data,
98 struct text_model *text_model)
103 text_model_activated(void *data,
104 struct text_model *text_model)
106 struct display *display = data;
108 fprintf(stderr, "%s\n", __FUNCTION__);
110 display->activated += 1;
114 text_model_deactivated(void *data,
115 struct text_model *text_model)
117 struct display *display = data;
119 display->deactivated += 1;
122 static const struct text_model_listener text_model_listener = {
123 text_model_commit_string,
124 text_model_preedit_string,
125 text_model_delete_surrounding_text,
126 text_model_preedit_styling,
128 text_model_selection_replacement,
129 text_model_direction,
131 text_model_activated,
132 text_model_deactivated
136 handle_global(struct wl_display *_display, uint32_t id,
137 const char *interface, uint32_t version, void *data)
139 struct display *display = data;
141 if (strcmp(interface, "wl_compositor") == 0) {
142 display->compositor =
143 wl_display_bind(display->display,
144 id, &wl_compositor_interface);
145 } else if (strcmp(interface, "wl_seat") == 0) {
146 display->seat = wl_display_bind(display->display, id,
148 } else if (strcmp(interface, "text_model_factory") == 0) {
149 display->factory = wl_display_bind(display->display, id,
150 &text_model_factory_interface);
155 create_surface(int fd, struct display *display)
160 display->surface = wl_compositor_create_surface(display->compositor);
161 wl_display_flush(display->display);
163 len = snprintf(buf, sizeof buf, "surface %d\n",
164 wl_proxy_get_id((struct wl_proxy *) display->surface));
165 assert(write(fd, buf, len) == len);
169 create_text_model(int fd, struct display *display)
174 display->text_model = text_model_factory_create_text_model(display->factory);
175 text_model_add_listener(display->text_model, &text_model_listener, display);
176 wl_display_flush(display->display);
178 len = snprintf(buf, sizeof buf, "text_model %d\n",
179 wl_proxy_get_id((struct wl_proxy *) display->text_model));
180 assert(write(fd, buf, len) == len);
184 write_state(int fd, struct display *display)
189 wl_display_flush(display->display);
190 len = snprintf(buf, sizeof buf, "activated %u deactivated %u\n",
191 display->activated, display->deactivated);
192 assert(write(fd, buf, len) == len);
193 wl_display_roundtrip(display->display);
197 activate_text_model(int fd, struct display *display)
199 write_state(fd, display);
201 text_model_activate(display->text_model, display->seat, display->surface);
203 wl_display_flush(display->display);
204 wl_display_roundtrip(display->display);
208 deactivate_text_model(int fd, struct display *display)
210 write_state(fd, display);
212 text_model_deactivate(display->text_model, display->seat);
214 wl_display_flush(display->display);
215 wl_display_roundtrip(display->display);
218 int main(int argc, char *argv[])
220 struct display *display;
224 display = malloc(sizeof *display);
227 display->display = wl_display_connect(NULL);
228 assert(display->display);
230 display->activated = 0;
231 display->deactivated = 0;
233 wl_display_add_global_listener(display->display,
234 handle_global, display);
235 wl_display_iterate(display->display, WL_DISPLAY_READABLE);
236 wl_display_roundtrip(display->display);
239 p = getenv("TEST_SOCKET");
241 fd = strtol(p, NULL, 0);
244 ret = read(fd, buf, sizeof buf);
246 fprintf(stderr, "read error: fd %d, %m\n", fd);
250 fprintf(stderr, "test-client: got %.*s\n", ret - 1, buf);
252 if (strncmp(buf, "bye\n", ret) == 0) {
254 } else if (strncmp(buf, "create-surface\n", ret) == 0) {
255 create_surface(fd, display);
256 } else if (strncmp(buf, "create-text-model\n", ret) == 0) {
257 create_text_model(fd, display);
258 } else if (strncmp(buf, "activate-text-model\n", ret) == 0) {
259 activate_text_model(fd, display);
260 } else if (strncmp(buf, "deactivate-text-model\n", ret) == 0) {
261 deactivate_text_model(fd, display);
262 } else if (strncmp(buf, "assert-state\n", ret) == 0) {
263 write_state(fd, display);
265 fprintf(stderr, "unknown command %.*s\n", ret, buf);