Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 1 | /* |
| 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øgsberg | 1199b16 | 2012-11-27 13:41:48 -0500 | [diff] [blame] | 26 | #include <unistd.h> |
| 27 | #include <sys/mman.h> |
| 28 | |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 29 | |
| 30 | #include <linux/input.h> |
| 31 | |
| 32 | #include "window.h" |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 33 | #include "input-method-client-protocol.h" |
| 34 | |
| 35 | enum compose_state { |
| 36 | state_normal, |
| 37 | state_compose |
| 38 | }; |
| 39 | |
| 40 | struct compose_seq { |
| 41 | uint32_t keys[4]; |
| 42 | |
| 43 | const char *text; |
| 44 | }; |
| 45 | |
| 46 | struct simple_im { |
| 47 | struct input_method *input_method; |
| 48 | struct input_method_context *context; |
Kristian Høgsberg | 8c03616 | 2012-11-27 13:47:16 -0500 | [diff] [blame] | 49 | struct xkb_context *xkb_context; |
Kristian Høgsberg | de318ab | 2012-11-27 14:07:22 -0500 | [diff] [blame^] | 50 | struct wl_display *display; |
| 51 | struct wl_registry *registry; |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 52 | struct wl_keyboard *keyboard; |
| 53 | struct keyboard_input *keyboard_input; |
| 54 | enum compose_state compose_state; |
| 55 | struct compose_seq compose_seq; |
| 56 | }; |
| 57 | |
| 58 | static const struct compose_seq compose_seqs[] = { |
| 59 | { { XKB_KEY_quotedbl, XKB_KEY_A, 0 }, "Ä" }, |
| 60 | { { XKB_KEY_quotedbl, XKB_KEY_O, 0 }, "Ö" }, |
| 61 | { { XKB_KEY_quotedbl, XKB_KEY_U, 0 }, "Ü" }, |
| 62 | { { XKB_KEY_quotedbl, XKB_KEY_a, 0 }, "ä" }, |
| 63 | { { XKB_KEY_quotedbl, XKB_KEY_o, 0 }, "ö" }, |
| 64 | { { XKB_KEY_quotedbl, XKB_KEY_u, 0 }, "ü" }, |
| 65 | { { XKB_KEY_apostrophe, XKB_KEY_A, 0 }, "Á" }, |
| 66 | { { XKB_KEY_apostrophe, XKB_KEY_a, 0 }, "á" }, |
| 67 | { { XKB_KEY_O, XKB_KEY_C, 0 }, "©" }, |
| 68 | { { XKB_KEY_O, XKB_KEY_R, 0 }, "®" }, |
| 69 | { { XKB_KEY_s, XKB_KEY_s, 0 }, "ß" }, |
| 70 | }; |
| 71 | |
| 72 | static const uint32_t ignore_keys_on_compose[] = { |
| 73 | XKB_KEY_Shift_L, |
| 74 | XKB_KEY_Shift_R |
| 75 | }; |
| 76 | |
Kristian Høgsberg | 1199b16 | 2012-11-27 13:41:48 -0500 | [diff] [blame] | 77 | typedef void (*keyboard_input_key_handler_t)(struct keyboard_input *keyboard_input, |
Kristian Høgsberg | 79bfde2 | 2012-11-27 13:57:27 -0500 | [diff] [blame] | 78 | uint32_t serial, |
Kristian Høgsberg | 1199b16 | 2012-11-27 13:41:48 -0500 | [diff] [blame] | 79 | uint32_t time, uint32_t key, uint32_t unicode, |
| 80 | enum wl_keyboard_key_state state, void *data); |
| 81 | |
| 82 | struct keyboard_input { |
| 83 | struct xkb_context *xkb_context; |
| 84 | |
| 85 | uint32_t modifiers; |
| 86 | |
| 87 | struct xkb_keymap *keymap; |
| 88 | struct xkb_state *state; |
| 89 | xkb_mod_mask_t control_mask; |
| 90 | xkb_mod_mask_t alt_mask; |
| 91 | xkb_mod_mask_t shift_mask; |
| 92 | |
| 93 | void *user_data; |
| 94 | keyboard_input_key_handler_t key_handler; |
| 95 | }; |
| 96 | |
| 97 | static struct keyboard_input* |
| 98 | keyboard_input_create(struct xkb_context *xkb_context) |
| 99 | { |
| 100 | struct keyboard_input *keyboard_input; |
| 101 | |
| 102 | keyboard_input = calloc(1, sizeof *keyboard_input); |
| 103 | keyboard_input->xkb_context = xkb_context; |
| 104 | |
| 105 | return keyboard_input; |
| 106 | } |
| 107 | |
| 108 | static void |
| 109 | keyboard_input_handle_keymap(struct keyboard_input *keyboard_input, |
| 110 | uint32_t format, int fd, uint32_t size) |
| 111 | { |
| 112 | char *map_str; |
| 113 | |
| 114 | if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { |
| 115 | close(fd); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); |
| 120 | if (map_str == MAP_FAILED) { |
| 121 | close(fd); |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | keyboard_input->keymap = xkb_map_new_from_string(keyboard_input->xkb_context, |
| 126 | map_str, |
| 127 | XKB_KEYMAP_FORMAT_TEXT_V1, |
| 128 | 0); |
| 129 | |
| 130 | munmap(map_str, size); |
| 131 | close(fd); |
| 132 | |
| 133 | if (!keyboard_input->keymap) { |
| 134 | fprintf(stderr, "failed to compile keymap\n"); |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | keyboard_input->state = xkb_state_new(keyboard_input->keymap); |
| 139 | if (!keyboard_input->state) { |
| 140 | fprintf(stderr, "failed to create XKB state\n"); |
| 141 | xkb_map_unref(keyboard_input->keymap); |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | keyboard_input->control_mask = |
| 146 | 1 << xkb_map_mod_get_index(keyboard_input->keymap, "Control"); |
| 147 | keyboard_input->alt_mask = |
| 148 | 1 << xkb_map_mod_get_index(keyboard_input->keymap, "Mod1"); |
| 149 | keyboard_input->shift_mask = |
| 150 | 1 << xkb_map_mod_get_index(keyboard_input->keymap, "Shift"); |
| 151 | } |
| 152 | |
| 153 | static void |
| 154 | keyboard_input_handle_key(struct keyboard_input *keyboard_input, |
| 155 | uint32_t serial, uint32_t time, |
| 156 | uint32_t key, uint32_t state_w) |
| 157 | { |
| 158 | uint32_t code; |
| 159 | uint32_t num_syms; |
| 160 | const xkb_keysym_t *syms; |
| 161 | xkb_keysym_t sym; |
| 162 | enum wl_keyboard_key_state state = state_w; |
| 163 | |
| 164 | if (!keyboard_input->state) |
| 165 | return; |
| 166 | |
| 167 | code = key + 8; |
| 168 | num_syms = xkb_key_get_syms(keyboard_input->state, code, &syms); |
| 169 | |
| 170 | sym = XKB_KEY_NoSymbol; |
| 171 | if (num_syms == 1) |
| 172 | sym = syms[0]; |
| 173 | |
| 174 | if (keyboard_input->key_handler) |
Kristian Høgsberg | 79bfde2 | 2012-11-27 13:57:27 -0500 | [diff] [blame] | 175 | (*keyboard_input->key_handler)(keyboard_input, serial, time, key, sym, |
Kristian Høgsberg | 1199b16 | 2012-11-27 13:41:48 -0500 | [diff] [blame] | 176 | state, keyboard_input->user_data); |
| 177 | } |
| 178 | |
| 179 | static void |
| 180 | keyboard_input_handle_modifiers(struct keyboard_input *keyboard_input, |
| 181 | uint32_t serial, uint32_t mods_depressed, |
| 182 | uint32_t mods_latched, uint32_t mods_locked, |
| 183 | uint32_t group) |
| 184 | { |
| 185 | xkb_mod_mask_t mask; |
| 186 | |
| 187 | xkb_state_update_mask(keyboard_input->state, mods_depressed, mods_latched, |
| 188 | mods_locked, 0, 0, group); |
| 189 | mask = xkb_state_serialize_mods(keyboard_input->state, |
| 190 | XKB_STATE_DEPRESSED | |
| 191 | XKB_STATE_LATCHED); |
| 192 | |
| 193 | keyboard_input->modifiers = 0; |
| 194 | if (mask & keyboard_input->control_mask) |
| 195 | keyboard_input->modifiers |= MOD_CONTROL_MASK; |
| 196 | if (mask & keyboard_input->alt_mask) |
| 197 | keyboard_input->modifiers |= MOD_ALT_MASK; |
| 198 | if (mask & keyboard_input->shift_mask) |
| 199 | keyboard_input->modifiers |= MOD_SHIFT_MASK; |
| 200 | |
| 201 | } |
| 202 | |
| 203 | static void |
| 204 | keyboard_input_set_user_data(struct keyboard_input *keyboard_input, void *data) |
| 205 | { |
| 206 | keyboard_input->user_data = data; |
| 207 | } |
| 208 | |
| 209 | static void |
| 210 | keyboard_input_set_key_handler(struct keyboard_input *keyboard_input, |
| 211 | keyboard_input_key_handler_t handler) |
| 212 | { |
| 213 | keyboard_input->key_handler = handler; |
| 214 | } |
| 215 | |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 216 | static void |
| 217 | input_method_context_surrounding_text(void *data, |
| 218 | struct input_method_context *context, |
| 219 | const char *text, |
| 220 | uint32_t cursor, |
| 221 | uint32_t anchor) |
| 222 | { |
| 223 | fprintf(stderr, "Surrounding text updated: %s\n", text); |
| 224 | } |
| 225 | |
| 226 | static void |
| 227 | input_method_context_reset(void *data, |
| 228 | struct input_method_context *context) |
| 229 | { |
| 230 | struct simple_im *keyboard = data; |
| 231 | |
| 232 | fprintf(stderr, "Reset pre-edit buffer\n"); |
| 233 | |
| 234 | keyboard->compose_state = state_normal; |
| 235 | } |
| 236 | |
| 237 | static const struct input_method_context_listener input_method_context_listener = { |
| 238 | input_method_context_surrounding_text, |
| 239 | input_method_context_reset |
| 240 | }; |
| 241 | |
| 242 | static void |
| 243 | input_method_keyboard_keymap(void *data, |
| 244 | struct wl_keyboard *wl_keyboard, |
| 245 | uint32_t format, |
| 246 | int32_t fd, |
| 247 | uint32_t size) |
| 248 | { |
| 249 | struct simple_im *keyboard = data; |
| 250 | |
| 251 | keyboard_input_handle_keymap(keyboard->keyboard_input, format, fd, size); |
| 252 | } |
| 253 | |
| 254 | static void |
| 255 | input_method_keyboard_key(void *data, |
| 256 | struct wl_keyboard *wl_keyboard, |
| 257 | uint32_t serial, |
| 258 | uint32_t time, |
| 259 | uint32_t key, |
| 260 | uint32_t state_w) |
| 261 | { |
| 262 | struct simple_im *keyboard = data; |
| 263 | |
| 264 | keyboard_input_handle_key(keyboard->keyboard_input, serial, |
| 265 | time, key, state_w); |
| 266 | } |
| 267 | |
| 268 | static void |
| 269 | input_method_keyboard_modifiers(void *data, |
| 270 | struct wl_keyboard *wl_keyboard, |
| 271 | uint32_t serial, |
| 272 | uint32_t mods_depressed, |
| 273 | uint32_t mods_latched, |
| 274 | uint32_t mods_locked, |
| 275 | uint32_t group) |
| 276 | { |
| 277 | struct simple_im *keyboard = data; |
| 278 | struct input_method_context *context = keyboard->context; |
| 279 | |
| 280 | keyboard_input_handle_modifiers(keyboard->keyboard_input, serial, |
| 281 | mods_depressed, mods_latched, mods_locked, group); |
| 282 | |
| 283 | input_method_context_modifiers(context, serial, |
| 284 | mods_depressed, mods_depressed, |
| 285 | mods_latched, group); |
| 286 | } |
| 287 | |
| 288 | static const struct wl_keyboard_listener input_method_keyboard_listener = { |
| 289 | input_method_keyboard_keymap, |
| 290 | NULL, /* enter */ |
| 291 | NULL, /* leave */ |
| 292 | input_method_keyboard_key, |
| 293 | input_method_keyboard_modifiers |
| 294 | }; |
| 295 | |
| 296 | static void |
| 297 | input_method_activate(void *data, |
| 298 | struct input_method *input_method, |
| 299 | struct input_method_context *context) |
| 300 | { |
| 301 | struct simple_im *keyboard = data; |
| 302 | |
| 303 | if (keyboard->context) |
| 304 | input_method_context_destroy(keyboard->context); |
| 305 | |
| 306 | keyboard->compose_state = state_normal; |
| 307 | |
| 308 | keyboard->context = context; |
| 309 | input_method_context_add_listener(context, |
| 310 | &input_method_context_listener, |
| 311 | keyboard); |
| 312 | keyboard->keyboard = input_method_context_grab_keyboard(context); |
| 313 | wl_keyboard_add_listener(keyboard->keyboard, |
| 314 | &input_method_keyboard_listener, |
| 315 | keyboard); |
| 316 | } |
| 317 | |
| 318 | static void |
| 319 | input_method_deactivate(void *data, |
| 320 | struct input_method *input_method, |
| 321 | struct input_method_context *context) |
| 322 | { |
| 323 | struct simple_im *keyboard = data; |
| 324 | |
| 325 | if (!keyboard->context) |
| 326 | return; |
| 327 | |
| 328 | input_method_context_destroy(keyboard->context); |
| 329 | keyboard->context = NULL; |
| 330 | } |
| 331 | |
| 332 | static const struct input_method_listener input_method_listener = { |
| 333 | input_method_activate, |
| 334 | input_method_deactivate |
| 335 | }; |
| 336 | |
| 337 | static void |
Kristian Høgsberg | de318ab | 2012-11-27 14:07:22 -0500 | [diff] [blame^] | 338 | registry_handle_global(void *data, struct wl_registry *registry, |
| 339 | uint32_t name, const char *interface, uint32_t version) |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 340 | { |
| 341 | struct simple_im *keyboard = data; |
| 342 | |
| 343 | if (!strcmp(interface, "input_method")) { |
| 344 | keyboard->input_method = |
Kristian Høgsberg | de318ab | 2012-11-27 14:07:22 -0500 | [diff] [blame^] | 345 | wl_registry_bind(registry, name, |
| 346 | &input_method_interface, 1); |
| 347 | input_method_add_listener(keyboard->input_method, |
| 348 | &input_method_listener, keyboard); |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
Kristian Høgsberg | de318ab | 2012-11-27 14:07:22 -0500 | [diff] [blame^] | 352 | static const struct wl_registry_listener registry_listener = { |
| 353 | registry_handle_global |
| 354 | }; |
| 355 | |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 356 | static int |
| 357 | compare_compose_keys(const void *c1, const void *c2) |
| 358 | { |
| 359 | const struct compose_seq *cs1 = c1; |
| 360 | const struct compose_seq *cs2 = c2; |
| 361 | int i; |
| 362 | |
| 363 | for (i = 0; cs1->keys[i] != 0 && cs2->keys[i] != 0; i++) { |
| 364 | if (cs1->keys[i] != cs2->keys[i]) |
| 365 | return cs1->keys[i] - cs2->keys[i]; |
| 366 | } |
| 367 | |
| 368 | if (cs1->keys[i] == cs2->keys[i] |
| 369 | || cs1->keys[i] == 0) |
| 370 | return 0; |
| 371 | |
| 372 | return cs1->keys[i] - cs2->keys[i]; |
| 373 | } |
| 374 | |
| 375 | static void |
| 376 | simple_im_key_handler(struct keyboard_input *keyboard_input, |
Kristian Høgsberg | 79bfde2 | 2012-11-27 13:57:27 -0500 | [diff] [blame] | 377 | uint32_t serial, uint32_t time, uint32_t key, uint32_t sym, |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 378 | enum wl_keyboard_key_state state, void *data) |
| 379 | { |
| 380 | struct simple_im *keyboard = data; |
| 381 | struct input_method_context *context = keyboard->context; |
| 382 | char text[64]; |
| 383 | |
| 384 | if (sym == XKB_KEY_Multi_key && |
| 385 | state == WL_KEYBOARD_KEY_STATE_RELEASED && |
| 386 | keyboard->compose_state == state_normal) { |
| 387 | keyboard->compose_state = state_compose; |
| 388 | memset(&keyboard->compose_seq, 0, sizeof(struct compose_seq)); |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | if (keyboard->compose_state == state_compose) { |
| 393 | uint32_t i = 0; |
| 394 | struct compose_seq *cs; |
| 395 | |
| 396 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 397 | return; |
| 398 | |
| 399 | for (i = 0; i < sizeof(ignore_keys_on_compose) / sizeof(ignore_keys_on_compose[0]); i++) { |
| 400 | if (sym == ignore_keys_on_compose[i]) { |
Kristian Høgsberg | 79bfde2 | 2012-11-27 13:57:27 -0500 | [diff] [blame] | 401 | input_method_context_key(context, serial, time, key, state); |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 402 | return; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | for (i = 0; keyboard->compose_seq.keys[i] != 0; i++); |
| 407 | |
| 408 | keyboard->compose_seq.keys[i] = sym; |
| 409 | |
| 410 | cs = bsearch (&keyboard->compose_seq, compose_seqs, |
| 411 | sizeof(compose_seqs) / sizeof(compose_seqs[0]), |
| 412 | sizeof(compose_seqs[0]), compare_compose_keys); |
| 413 | |
| 414 | if (cs) { |
| 415 | if (cs->keys[i + 1] == 0) { |
| 416 | input_method_context_preedit_string(keyboard->context, |
| 417 | "", 0); |
| 418 | input_method_context_commit_string(keyboard->context, |
| 419 | cs->text, |
| 420 | strlen(cs->text)); |
| 421 | keyboard->compose_state = state_normal; |
| 422 | } else { |
| 423 | uint32_t j = 0, idx = 0; |
| 424 | |
| 425 | for (; j <= i; j++) { |
| 426 | idx += xkb_keysym_to_utf8(cs->keys[j], text + idx, sizeof(text) - idx); |
| 427 | } |
| 428 | |
| 429 | input_method_context_preedit_string(keyboard->context, |
| 430 | text, |
| 431 | strlen(text)); |
| 432 | } |
| 433 | } else { |
| 434 | uint32_t j = 0, idx = 0; |
| 435 | |
| 436 | for (; j <= i; j++) { |
| 437 | idx += xkb_keysym_to_utf8(keyboard->compose_seq.keys[j], text + idx, sizeof(text) - idx); |
| 438 | } |
| 439 | input_method_context_preedit_string(keyboard->context, |
| 440 | "", 0); |
| 441 | input_method_context_commit_string(keyboard->context, |
| 442 | text, |
| 443 | strlen(text)); |
| 444 | keyboard->compose_state = state_normal; |
| 445 | } |
| 446 | return; |
| 447 | } |
| 448 | |
| 449 | if (xkb_keysym_to_utf8(sym, text, sizeof(text)) <= 0) { |
Kristian Høgsberg | 79bfde2 | 2012-11-27 13:57:27 -0500 | [diff] [blame] | 450 | input_method_context_key(context, serial, time, key, state); |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 451 | return; |
| 452 | } |
| 453 | |
| 454 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 455 | return; |
| 456 | |
| 457 | input_method_context_commit_string(keyboard->context, |
| 458 | text, |
| 459 | strlen(text)); |
| 460 | } |
| 461 | |
| 462 | int |
| 463 | main(int argc, char *argv[]) |
| 464 | { |
| 465 | struct simple_im simple_im; |
Kristian Høgsberg | de318ab | 2012-11-27 14:07:22 -0500 | [diff] [blame^] | 466 | int ret = 0; |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 467 | |
| 468 | memset(&simple_im, 0, sizeof(simple_im)); |
| 469 | |
Kristian Høgsberg | de318ab | 2012-11-27 14:07:22 -0500 | [diff] [blame^] | 470 | simple_im.display = wl_display_connect(NULL); |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 471 | if (simple_im.display == NULL) { |
Kristian Høgsberg | de318ab | 2012-11-27 14:07:22 -0500 | [diff] [blame^] | 472 | fprintf(stderr, "failed to connect to server: %m\n"); |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 473 | return -1; |
| 474 | } |
| 475 | |
Kristian Høgsberg | de318ab | 2012-11-27 14:07:22 -0500 | [diff] [blame^] | 476 | simple_im.registry = wl_display_get_registry(simple_im.display); |
| 477 | wl_registry_add_listener(simple_im.registry, |
| 478 | ®istry_listener, &simple_im); |
| 479 | wl_display_roundtrip(simple_im.display); |
| 480 | if (simple_im.input_method == NULL) { |
| 481 | fprintf(stderr, "No input_method global\n"); |
| 482 | exit(1); |
| 483 | } |
| 484 | |
Kristian Høgsberg | 8c03616 | 2012-11-27 13:47:16 -0500 | [diff] [blame] | 485 | simple_im.xkb_context = xkb_context_new(0); |
| 486 | if (simple_im.xkb_context == NULL) { |
| 487 | fprintf(stderr, "Failed to create XKB context\n"); |
| 488 | return -1; |
| 489 | } |
| 490 | |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 491 | simple_im.context = NULL; |
Kristian Høgsberg | 8c03616 | 2012-11-27 13:47:16 -0500 | [diff] [blame] | 492 | simple_im.keyboard_input = keyboard_input_create(simple_im.xkb_context); |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 493 | keyboard_input_set_user_data(simple_im.keyboard_input, &simple_im); |
| 494 | keyboard_input_set_key_handler(simple_im.keyboard_input, simple_im_key_handler); |
| 495 | |
Kristian Høgsberg | de318ab | 2012-11-27 14:07:22 -0500 | [diff] [blame^] | 496 | while (ret != -1) |
| 497 | ret = wl_display_dispatch(simple_im.display); |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 498 | |
Kristian Høgsberg | de318ab | 2012-11-27 14:07:22 -0500 | [diff] [blame^] | 499 | if (ret == -1) { |
| 500 | fprintf(stderr, "Dispatch error: %m\n"); |
| 501 | exit(1); |
| 502 | } |
Jan Arne Petersen | e9fba2b | 2012-11-18 19:06:50 +0100 | [diff] [blame] | 503 | |
| 504 | return 0; |
| 505 | } |