blob: d0383828ec77baf7417e5fbc3b0eb37426db6fb2 [file] [log] [blame]
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +01001/*
2 * Copyright © 2012 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
Kristian Høgsberg1199b162012-11-27 13:41:48 -050026#include <unistd.h>
27#include <sys/mman.h>
28
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +010029
30#include <linux/input.h>
31
32#include "window.h"
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +010033#include "input-method-client-protocol.h"
34
35enum compose_state {
36 state_normal,
37 state_compose
38};
39
40struct compose_seq {
41 uint32_t keys[4];
42
43 const char *text;
44};
45
Kristian Høgsberg504e8f12012-11-27 14:28:19 -050046struct simple_im;
47
48typedef void (*keyboard_input_key_handler_t)(struct simple_im *keyboard,
49 uint32_t serial,
50 uint32_t time, uint32_t key, uint32_t unicode,
51 enum wl_keyboard_key_state state);
52
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +010053struct simple_im {
54 struct input_method *input_method;
55 struct input_method_context *context;
Kristian Høgsbergde318ab2012-11-27 14:07:22 -050056 struct wl_display *display;
57 struct wl_registry *registry;
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +010058 struct wl_keyboard *keyboard;
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +010059 enum compose_state compose_state;
60 struct compose_seq compose_seq;
Kristian Høgsberg504e8f12012-11-27 14:28:19 -050061
62 struct xkb_context *xkb_context;
63
64 uint32_t modifiers;
65
66 struct xkb_keymap *keymap;
67 struct xkb_state *state;
68 xkb_mod_mask_t control_mask;
69 xkb_mod_mask_t alt_mask;
70 xkb_mod_mask_t shift_mask;
71
72 keyboard_input_key_handler_t key_handler;
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +010073
74 uint32_t serial;
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +010075};
76
77static const struct compose_seq compose_seqs[] = {
78 { { XKB_KEY_quotedbl, XKB_KEY_A, 0 }, "Ä" },
79 { { XKB_KEY_quotedbl, XKB_KEY_O, 0 }, "Ö" },
80 { { XKB_KEY_quotedbl, XKB_KEY_U, 0 }, "Ü" },
81 { { XKB_KEY_quotedbl, XKB_KEY_a, 0 }, "ä" },
82 { { XKB_KEY_quotedbl, XKB_KEY_o, 0 }, "ö" },
83 { { XKB_KEY_quotedbl, XKB_KEY_u, 0 }, "ü" },
84 { { XKB_KEY_apostrophe, XKB_KEY_A, 0 }, "Á" },
85 { { XKB_KEY_apostrophe, XKB_KEY_a, 0 }, "á" },
Kristian Høgsbergb88b68f2012-11-27 15:11:04 -050086 { { XKB_KEY_slash, XKB_KEY_O, 0 }, "Ø" },
87 { { XKB_KEY_slash, XKB_KEY_o, 0 }, "ø" },
88 { { XKB_KEY_less, XKB_KEY_3, 0 }, "♥" },
89 { { XKB_KEY_A, XKB_KEY_A, 0 }, "Å" },
90 { { XKB_KEY_A, XKB_KEY_E, 0 }, "Æ" },
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +010091 { { XKB_KEY_O, XKB_KEY_C, 0 }, "©" },
92 { { XKB_KEY_O, XKB_KEY_R, 0 }, "®" },
93 { { XKB_KEY_s, XKB_KEY_s, 0 }, "ß" },
Kristian Høgsbergb88b68f2012-11-27 15:11:04 -050094 { { XKB_KEY_a, XKB_KEY_e, 0 }, "æ" },
95 { { XKB_KEY_a, XKB_KEY_a, 0 }, "å" },
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +010096};
97
98static const uint32_t ignore_keys_on_compose[] = {
99 XKB_KEY_Shift_L,
100 XKB_KEY_Shift_R
101};
102
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100103static void
104input_method_context_surrounding_text(void *data,
105 struct input_method_context *context,
106 const char *text,
107 uint32_t cursor,
108 uint32_t anchor)
109{
110 fprintf(stderr, "Surrounding text updated: %s\n", text);
111}
112
113static void
114input_method_context_reset(void *data,
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100115 struct input_method_context *context,
116 uint32_t serial)
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100117{
118 struct simple_im *keyboard = data;
119
120 fprintf(stderr, "Reset pre-edit buffer\n");
121
122 keyboard->compose_state = state_normal;
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100123
124 keyboard->serial = serial;
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100125}
126
Jan Arne Petersenab2b0142013-01-16 21:26:49 +0100127static void
128input_method_context_content_type(void *data,
129 struct input_method_context *context,
130 uint32_t hint,
131 uint32_t purpose)
132{
133}
134
135static void
136input_method_context_invoke_action(void *data,
137 struct input_method_context *context,
138 uint32_t button,
139 uint32_t index)
140{
141}
142
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100143static const struct input_method_context_listener input_method_context_listener = {
144 input_method_context_surrounding_text,
Jan Arne Petersenab2b0142013-01-16 21:26:49 +0100145 input_method_context_reset,
146 input_method_context_content_type,
147 input_method_context_invoke_action
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100148};
149
150static void
151input_method_keyboard_keymap(void *data,
152 struct wl_keyboard *wl_keyboard,
153 uint32_t format,
154 int32_t fd,
155 uint32_t size)
156{
157 struct simple_im *keyboard = data;
Kristian Høgsbergaec12b82012-11-27 14:21:34 -0500158 char *map_str;
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100159
Kristian Høgsbergaec12b82012-11-27 14:21:34 -0500160 if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
161 close(fd);
162 return;
163 }
164
165 map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
166 if (map_str == MAP_FAILED) {
167 close(fd);
168 return;
169 }
170
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500171 keyboard->keymap =
172 xkb_map_new_from_string(keyboard->xkb_context,
Kristian Høgsbergaec12b82012-11-27 14:21:34 -0500173 map_str,
174 XKB_KEYMAP_FORMAT_TEXT_V1,
175 0);
176
177 munmap(map_str, size);
178 close(fd);
179
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500180 if (!keyboard->keymap) {
Kristian Høgsbergaec12b82012-11-27 14:21:34 -0500181 fprintf(stderr, "failed to compile keymap\n");
182 return;
183 }
184
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500185 keyboard->state = xkb_state_new(keyboard->keymap);
186 if (!keyboard->state) {
Kristian Høgsbergaec12b82012-11-27 14:21:34 -0500187 fprintf(stderr, "failed to create XKB state\n");
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500188 xkb_map_unref(keyboard->keymap);
Kristian Høgsbergaec12b82012-11-27 14:21:34 -0500189 return;
190 }
191
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500192 keyboard->control_mask =
193 1 << xkb_map_mod_get_index(keyboard->keymap, "Control");
194 keyboard->alt_mask =
195 1 << xkb_map_mod_get_index(keyboard->keymap, "Mod1");
196 keyboard->shift_mask =
197 1 << xkb_map_mod_get_index(keyboard->keymap, "Shift");
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100198}
199
200static void
201input_method_keyboard_key(void *data,
202 struct wl_keyboard *wl_keyboard,
203 uint32_t serial,
204 uint32_t time,
205 uint32_t key,
206 uint32_t state_w)
207{
208 struct simple_im *keyboard = data;
Kristian Høgsberg6aae6142012-11-27 14:20:31 -0500209 uint32_t code;
210 uint32_t num_syms;
211 const xkb_keysym_t *syms;
212 xkb_keysym_t sym;
213 enum wl_keyboard_key_state state = state_w;
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100214
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500215 if (!keyboard->state)
Kristian Høgsberg6aae6142012-11-27 14:20:31 -0500216 return;
217
218 code = key + 8;
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500219 num_syms = xkb_key_get_syms(keyboard->state, code, &syms);
Kristian Høgsberg6aae6142012-11-27 14:20:31 -0500220
221 sym = XKB_KEY_NoSymbol;
222 if (num_syms == 1)
223 sym = syms[0];
224
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500225 if (keyboard->key_handler)
226 (*keyboard->key_handler)(keyboard, serial, time, key, sym,
227 state);
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100228}
229
230static void
231input_method_keyboard_modifiers(void *data,
232 struct wl_keyboard *wl_keyboard,
233 uint32_t serial,
234 uint32_t mods_depressed,
235 uint32_t mods_latched,
236 uint32_t mods_locked,
237 uint32_t group)
238{
239 struct simple_im *keyboard = data;
240 struct input_method_context *context = keyboard->context;
Kristian Høgsberg3a3704d2012-11-27 14:18:40 -0500241 xkb_mod_mask_t mask;
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100242
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500243 xkb_state_update_mask(keyboard->state, mods_depressed,
Kristian Høgsberg3a3704d2012-11-27 14:18:40 -0500244 mods_latched, mods_locked, 0, 0, group);
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500245 mask = xkb_state_serialize_mods(keyboard->state,
Kristian Høgsberg3a3704d2012-11-27 14:18:40 -0500246 XKB_STATE_DEPRESSED |
247 XKB_STATE_LATCHED);
248
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500249 keyboard->modifiers = 0;
250 if (mask & keyboard->control_mask)
251 keyboard->modifiers |= MOD_CONTROL_MASK;
252 if (mask & keyboard->alt_mask)
253 keyboard->modifiers |= MOD_ALT_MASK;
254 if (mask & keyboard->shift_mask)
255 keyboard->modifiers |= MOD_SHIFT_MASK;
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100256
257 input_method_context_modifiers(context, serial,
258 mods_depressed, mods_depressed,
259 mods_latched, group);
260}
261
262static const struct wl_keyboard_listener input_method_keyboard_listener = {
263 input_method_keyboard_keymap,
264 NULL, /* enter */
265 NULL, /* leave */
266 input_method_keyboard_key,
267 input_method_keyboard_modifiers
268};
269
270static void
271input_method_activate(void *data,
272 struct input_method *input_method,
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100273 struct input_method_context *context,
274 uint32_t serial)
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100275{
276 struct simple_im *keyboard = data;
277
278 if (keyboard->context)
279 input_method_context_destroy(keyboard->context);
280
281 keyboard->compose_state = state_normal;
282
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100283 keyboard->serial = serial;
284
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100285 keyboard->context = context;
286 input_method_context_add_listener(context,
287 &input_method_context_listener,
288 keyboard);
289 keyboard->keyboard = input_method_context_grab_keyboard(context);
290 wl_keyboard_add_listener(keyboard->keyboard,
291 &input_method_keyboard_listener,
292 keyboard);
293}
294
295static void
296input_method_deactivate(void *data,
297 struct input_method *input_method,
298 struct input_method_context *context)
299{
300 struct simple_im *keyboard = data;
301
302 if (!keyboard->context)
303 return;
304
305 input_method_context_destroy(keyboard->context);
306 keyboard->context = NULL;
307}
308
309static const struct input_method_listener input_method_listener = {
310 input_method_activate,
311 input_method_deactivate
312};
313
314static void
Kristian Høgsbergde318ab2012-11-27 14:07:22 -0500315registry_handle_global(void *data, struct wl_registry *registry,
316 uint32_t name, const char *interface, uint32_t version)
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100317{
318 struct simple_im *keyboard = data;
319
320 if (!strcmp(interface, "input_method")) {
321 keyboard->input_method =
Kristian Høgsbergde318ab2012-11-27 14:07:22 -0500322 wl_registry_bind(registry, name,
323 &input_method_interface, 1);
324 input_method_add_listener(keyboard->input_method,
325 &input_method_listener, keyboard);
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100326 }
327}
328
Pekka Paalanen0eab05d2013-01-22 14:53:55 +0200329static void
330registry_handle_global_remove(void *data, struct wl_registry *registry,
331 uint32_t name)
332{
333}
334
Kristian Høgsbergde318ab2012-11-27 14:07:22 -0500335static const struct wl_registry_listener registry_listener = {
Pekka Paalanen0eab05d2013-01-22 14:53:55 +0200336 registry_handle_global,
337 registry_handle_global_remove
Kristian Høgsbergde318ab2012-11-27 14:07:22 -0500338};
339
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100340static int
341compare_compose_keys(const void *c1, const void *c2)
342{
343 const struct compose_seq *cs1 = c1;
344 const struct compose_seq *cs2 = c2;
345 int i;
346
347 for (i = 0; cs1->keys[i] != 0 && cs2->keys[i] != 0; i++) {
348 if (cs1->keys[i] != cs2->keys[i])
349 return cs1->keys[i] - cs2->keys[i];
350 }
351
352 if (cs1->keys[i] == cs2->keys[i]
353 || cs1->keys[i] == 0)
354 return 0;
355
356 return cs1->keys[i] - cs2->keys[i];
357}
358
359static void
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500360simple_im_key_handler(struct simple_im *keyboard,
Kristian Høgsberg79bfde22012-11-27 13:57:27 -0500361 uint32_t serial, uint32_t time, uint32_t key, uint32_t sym,
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500362 enum wl_keyboard_key_state state)
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100363{
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100364 struct input_method_context *context = keyboard->context;
365 char text[64];
366
367 if (sym == XKB_KEY_Multi_key &&
368 state == WL_KEYBOARD_KEY_STATE_RELEASED &&
369 keyboard->compose_state == state_normal) {
370 keyboard->compose_state = state_compose;
371 memset(&keyboard->compose_seq, 0, sizeof(struct compose_seq));
372 return;
373 }
374
375 if (keyboard->compose_state == state_compose) {
376 uint32_t i = 0;
377 struct compose_seq *cs;
378
379 if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
380 return;
381
382 for (i = 0; i < sizeof(ignore_keys_on_compose) / sizeof(ignore_keys_on_compose[0]); i++) {
383 if (sym == ignore_keys_on_compose[i]) {
Kristian Høgsberg79bfde22012-11-27 13:57:27 -0500384 input_method_context_key(context, serial, time, key, state);
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100385 return;
386 }
387 }
388
389 for (i = 0; keyboard->compose_seq.keys[i] != 0; i++);
390
391 keyboard->compose_seq.keys[i] = sym;
392
393 cs = bsearch (&keyboard->compose_seq, compose_seqs,
394 sizeof(compose_seqs) / sizeof(compose_seqs[0]),
395 sizeof(compose_seqs[0]), compare_compose_keys);
396
397 if (cs) {
398 if (cs->keys[i + 1] == 0) {
Jan Arne Petersen46535312013-01-16 21:26:38 +0100399 input_method_context_preedit_cursor(keyboard->context,
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100400 keyboard->serial,
Jan Arne Petersen46535312013-01-16 21:26:38 +0100401 0);
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100402 input_method_context_preedit_string(keyboard->context,
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100403 keyboard->serial,
Jan Arne Petersen46535312013-01-16 21:26:38 +0100404 "", "");
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100405 input_method_context_commit_string(keyboard->context,
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100406 keyboard->serial,
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100407 cs->text,
408 strlen(cs->text));
409 keyboard->compose_state = state_normal;
410 } else {
411 uint32_t j = 0, idx = 0;
412
413 for (; j <= i; j++) {
414 idx += xkb_keysym_to_utf8(cs->keys[j], text + idx, sizeof(text) - idx);
415 }
416
Jan Arne Petersen46535312013-01-16 21:26:38 +0100417 input_method_context_preedit_cursor(keyboard->context,
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100418 keyboard->serial,
Jan Arne Petersen46535312013-01-16 21:26:38 +0100419 strlen(text));
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100420 input_method_context_preedit_string(keyboard->context,
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100421 keyboard->serial,
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100422 text,
Jan Arne Petersen46535312013-01-16 21:26:38 +0100423 text);
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100424 }
425 } else {
426 uint32_t j = 0, idx = 0;
427
428 for (; j <= i; j++) {
429 idx += xkb_keysym_to_utf8(keyboard->compose_seq.keys[j], text + idx, sizeof(text) - idx);
430 }
Jan Arne Petersen46535312013-01-16 21:26:38 +0100431 input_method_context_preedit_cursor(keyboard->context,
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100432 keyboard->serial,
Jan Arne Petersen46535312013-01-16 21:26:38 +0100433 0);
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100434 input_method_context_preedit_string(keyboard->context,
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100435 keyboard->serial,
Jan Arne Petersen46535312013-01-16 21:26:38 +0100436 "", "");
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100437 input_method_context_commit_string(keyboard->context,
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100438 keyboard->serial,
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100439 text,
440 strlen(text));
441 keyboard->compose_state = state_normal;
442 }
443 return;
444 }
445
446 if (xkb_keysym_to_utf8(sym, text, sizeof(text)) <= 0) {
Kristian Høgsberg79bfde22012-11-27 13:57:27 -0500447 input_method_context_key(context, serial, time, key, state);
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100448 return;
449 }
450
451 if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
452 return;
453
454 input_method_context_commit_string(keyboard->context,
Jan Arne Petersenc7d2a982013-01-16 21:26:39 +0100455 keyboard->serial,
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100456 text,
457 strlen(text));
458}
459
460int
461main(int argc, char *argv[])
462{
463 struct simple_im simple_im;
Kristian Høgsbergde318ab2012-11-27 14:07:22 -0500464 int ret = 0;
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100465
466 memset(&simple_im, 0, sizeof(simple_im));
467
Kristian Høgsbergde318ab2012-11-27 14:07:22 -0500468 simple_im.display = wl_display_connect(NULL);
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100469 if (simple_im.display == NULL) {
Kristian Høgsbergde318ab2012-11-27 14:07:22 -0500470 fprintf(stderr, "failed to connect to server: %m\n");
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100471 return -1;
472 }
473
Kristian Høgsbergde318ab2012-11-27 14:07:22 -0500474 simple_im.registry = wl_display_get_registry(simple_im.display);
475 wl_registry_add_listener(simple_im.registry,
476 &registry_listener, &simple_im);
477 wl_display_roundtrip(simple_im.display);
478 if (simple_im.input_method == NULL) {
479 fprintf(stderr, "No input_method global\n");
480 exit(1);
481 }
482
Kristian Høgsberg8c036162012-11-27 13:47:16 -0500483 simple_im.xkb_context = xkb_context_new(0);
484 if (simple_im.xkb_context == NULL) {
485 fprintf(stderr, "Failed to create XKB context\n");
486 return -1;
487 }
488
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100489 simple_im.context = NULL;
Kristian Høgsberg504e8f12012-11-27 14:28:19 -0500490 simple_im.key_handler = simple_im_key_handler;
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100491
Kristian Høgsbergde318ab2012-11-27 14:07:22 -0500492 while (ret != -1)
493 ret = wl_display_dispatch(simple_im.display);
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100494
Kristian Høgsbergde318ab2012-11-27 14:07:22 -0500495 if (ret == -1) {
496 fprintf(stderr, "Dispatch error: %m\n");
497 exit(1);
498 }
Jan Arne Petersene9fba2b2012-11-18 19:06:50 +0100499
500 return 0;
501}