From: Jan Arne Petersen <jpeter...@openismus.com> Add key event to the text_model interface and a key request to the input_method_context interface. Implement it in the example editor client and the example keyboard.
Signed-off-by: Jan Arne Petersen <jpeter...@openismus.com> --- clients/editor.c | 25 ++++++++++++++++++++++++- clients/keyboard.c | 4 ++++ protocol/input-method.xml | 4 ++++ protocol/text.xml | 5 ++++- src/text-backend.c | 14 +++++++++++++- tests/test-text-client.c | 6 ++++-- 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/clients/editor.c b/clients/editor.c index 0ed217f..2baf6af 100644 --- a/clients/editor.c +++ b/clients/editor.c @@ -284,8 +284,31 @@ text_model_preedit_styling(void *data, static void text_model_key(void *data, - struct text_model *text_model) + struct text_model *text_model, + uint32_t key, + uint32_t state) { + const char *state_label; + const char *key_label; + + if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { + state_label = "pressed"; + } else { + state_label = "released"; + } + + switch (key) { + case XKB_KEY_Tab: + key_label = "Tab"; + break; + case XKB_KEY_KP_Enter: + key_label = "Enter"; + break; + default: + key_label = "Unknown"; + } + + fprintf(stderr, "%s key was %s.\n", key_label, state_label); } static void diff --git a/clients/keyboard.c b/clients/keyboard.c index 588ef78..0cbf531 100644 --- a/clients/keyboard.c +++ b/clients/keyboard.c @@ -228,6 +228,8 @@ keyboard_handle_key(struct keyboard *keyboard, const struct key *key) } break; case keytype_enter: + input_method_context_key(keyboard->keyboard->context, + XKB_KEY_KP_Enter, WL_KEYBOARD_KEY_STATE_PRESSED); break; case keytype_space: keyboard->keyboard->preedit_string = strcat(keyboard->keyboard->preedit_string, @@ -250,6 +252,8 @@ keyboard_handle_key(struct keyboard *keyboard, const struct key *key) case keytype_symbols: break; case keytype_tab: + input_method_context_key(keyboard->keyboard->context, + XKB_KEY_Tab, WL_KEYBOARD_KEY_STATE_PRESSED); break; } } diff --git a/protocol/input-method.xml b/protocol/input-method.xml index 10ca32a..100fa46 100644 --- a/protocol/input-method.xml +++ b/protocol/input-method.xml @@ -53,6 +53,10 @@ <arg name="index" type="int"/> <arg name="length" type="uint"/> </request> + <request name="key"> + <arg name="key" type="uint"/> + <arg name="state" type="uint"/> + </request> <event name="surrounding_text"> <description summary="surrounding text event"> The plain surrounding text around the input position. Cursor is the diff --git a/protocol/text.xml b/protocol/text.xml index 3d7d8f5..62746d3 100644 --- a/protocol/text.xml +++ b/protocol/text.xml @@ -89,7 +89,10 @@ <arg name="length" type="uint"/> </event> <event name="preedit_styling"/> - <event name="key"/> + <event name="key"> + <arg name="key" type="uint"/> + <arg name="state" type="uint"/> + </event> <event name="selection_replacement"/> <event name="direction"/> <event name="locale"/> diff --git a/src/text-backend.c b/src/text-backend.c index b2f9094..0a93b6b 100644 --- a/src/text-backend.c +++ b/src/text-backend.c @@ -316,11 +316,23 @@ input_method_context_delete_surrounding_text(struct wl_client *client, text_model_send_delete_surrounding_text(&context->model->resource, index, length); } +static void +input_method_context_key(struct wl_client *client, + struct wl_resource *resource, + uint32_t key, + uint32_t state) +{ + struct input_method_context *context = resource->data; + + text_model_send_key(&context->model->resource, key, state); +} + static const struct input_method_context_interface input_method_context_implementation = { input_method_context_destroy, input_method_context_commit_string, input_method_context_preedit_string, - input_method_context_delete_surrounding_text + input_method_context_delete_surrounding_text, + input_method_context_key }; static void diff --git a/tests/test-text-client.c b/tests/test-text-client.c index 3b390f6..897909a 100644 --- a/tests/test-text-client.c +++ b/tests/test-text-client.c @@ -75,10 +75,12 @@ text_model_preedit_styling(void *data, static void text_model_key(void *data, - struct text_model *text_model) + struct text_model *text_model, + uint32_t key, + uint32_t state) { } - + static void text_model_selection_replacement(void *data, struct text_model *text_model) -- 1.7.11.4 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel