From ece6b5af51460c21f5bdd1fae4e7c2ea9f707e2f Mon Sep 17 00:00:00 2001 From: Jan Arne Petersen Date: Thu, 18 Apr 2013 16:47:15 +0200 Subject: [PATCH] text: Add language and text-direction to protocol Signed-off-by: Jan Arne Petersen --- clients/editor.c | 20 +++++++++++++- clients/keyboard.c | 54 ++++++++++++++++++++++---------------- clients/weston-simple-im.c | 54 ++++++++++++++++++++++---------------- protocol/input-method.xml | 11 ++++++++ protocol/text.xml | 36 +++++++++++++++++++++++++ src/text-backend.c | 46 ++++++++++++++++++++++++++++++-- tests/text-test.c | 20 +++++++++++++- 7 files changed, 191 insertions(+), 50 deletions(-) diff --git a/clients/editor.c b/clients/editor.c index 0de25000..e037c2f9 100644 --- a/clients/editor.c +++ b/clients/editor.c @@ -391,6 +391,22 @@ text_model_input_panel_state(void *data, { } +static void +text_model_language(void *data, + struct text_model *text_model, + uint32_t serial, + const char *language) +{ +} + +static void +text_model_text_direction(void *data, + struct text_model *text_model, + uint32_t serial, + uint32_t direction) +{ +} + static const struct text_model_listener text_model_listener = { text_model_commit_string, text_model_preedit_string, @@ -402,7 +418,9 @@ static const struct text_model_listener text_model_listener = { text_model_keysym, text_model_enter, text_model_leave, - text_model_input_panel_state + text_model_input_panel_state, + text_model_language, + text_model_text_direction }; static struct text_entry* diff --git a/clients/keyboard.c b/clients/keyboard.c index ad34b855..b23de42a 100644 --- a/clients/keyboard.c +++ b/clients/keyboard.c @@ -492,11 +492,11 @@ button_handler(struct widget *widget, } static void -input_method_context_surrounding_text(void *data, - struct input_method_context *context, - const char *text, - uint32_t cursor, - uint32_t anchor) +handle_surrounding_text(void *data, + struct input_method_context *context, + const char *text, + uint32_t cursor, + uint32_t anchor) { struct virtual_keyboard *keyboard = data; @@ -505,9 +505,9 @@ input_method_context_surrounding_text(void *data, } static void -input_method_context_reset(void *data, - struct input_method_context *context, - uint32_t serial) +handle_reset(void *data, + struct input_method_context *context, + uint32_t serial) { struct virtual_keyboard *keyboard = data; @@ -529,10 +529,10 @@ input_method_context_reset(void *data, } static void -input_method_context_content_type(void *data, - struct input_method_context *context, - uint32_t hint, - uint32_t purpose) +handle_content_type(void *data, + struct input_method_context *context, + uint32_t hint, + uint32_t purpose) { struct virtual_keyboard *keyboard = data; @@ -541,10 +541,10 @@ input_method_context_content_type(void *data, } static void -input_method_context_invoke_action(void *data, - struct input_method_context *context, - uint32_t button, - uint32_t index) +handle_invoke_action(void *data, + struct input_method_context *context, + uint32_t button, + uint32_t index) { struct virtual_keyboard *keyboard = data; @@ -555,8 +555,8 @@ input_method_context_invoke_action(void *data, } static void -input_method_context_commit(void *data, - struct input_method_context *context) +handle_commit(void *data, + struct input_method_context *context) { struct virtual_keyboard *keyboard = data; const struct layout *layout; @@ -573,12 +573,20 @@ input_method_context_commit(void *data, widget_schedule_redraw(keyboard->widget); } +static void +handle_preferred_language(void *data, + struct input_method_context *context, + const char *language) +{ +} + static const struct input_method_context_listener input_method_context_listener = { - input_method_context_surrounding_text, - input_method_context_reset, - input_method_context_content_type, - input_method_context_invoke_action, - input_method_context_commit + handle_surrounding_text, + handle_reset, + handle_content_type, + handle_invoke_action, + handle_commit, + handle_preferred_language }; static void diff --git a/clients/weston-simple-im.c b/clients/weston-simple-im.c index e955d3c2..9d31e3b0 100644 --- a/clients/weston-simple-im.c +++ b/clients/weston-simple-im.c @@ -101,19 +101,19 @@ static const uint32_t ignore_keys_on_compose[] = { }; static void -input_method_context_surrounding_text(void *data, - struct input_method_context *context, - const char *text, - uint32_t cursor, - uint32_t anchor) +handle_surrounding_text(void *data, + struct input_method_context *context, + const char *text, + uint32_t cursor, + uint32_t anchor) { fprintf(stderr, "Surrounding text updated: %s\n", text); } static void -input_method_context_reset(void *data, - struct input_method_context *context, - uint32_t serial) +handle_reset(void *data, + struct input_method_context *context, + uint32_t serial) { struct simple_im *keyboard = data; @@ -125,33 +125,41 @@ input_method_context_reset(void *data, } static void -input_method_context_content_type(void *data, - struct input_method_context *context, - uint32_t hint, - uint32_t purpose) +handle_content_type(void *data, + struct input_method_context *context, + uint32_t hint, + uint32_t purpose) { } static void -input_method_context_invoke_action(void *data, - struct input_method_context *context, - uint32_t button, - uint32_t index) +handle_invoke_action(void *data, + struct input_method_context *context, + uint32_t button, + uint32_t index) { } static void -input_method_context_commit(void *data, - struct input_method_context *context) +handle_commit(void *data, + struct input_method_context *context) +{ +} + +static void +handle_preferred_language(void *data, + struct input_method_context *context, + const char *language) { } static const struct input_method_context_listener input_method_context_listener = { - input_method_context_surrounding_text, - input_method_context_reset, - input_method_context_content_type, - input_method_context_invoke_action, - input_method_context_commit + handle_surrounding_text, + handle_reset, + handle_content_type, + handle_invoke_action, + handle_commit, + handle_preferred_language }; static void diff --git a/protocol/input-method.xml b/protocol/input-method.xml index a59201b6..59ac2448 100644 --- a/protocol/input-method.xml +++ b/protocol/input-method.xml @@ -113,6 +113,14 @@ + + + + + + + + The plain surrounding text around the input position. Cursor is the @@ -136,6 +144,9 @@ + + + diff --git a/protocol/text.xml b/protocol/text.xml index 28d12eda..3334769e 100644 --- a/protocol/text.xml +++ b/protocol/text.xml @@ -150,6 +150,18 @@ Requests input panels (virtual keyboard) to hide. + + + Sets a specific language. This allows for example a virtual keyboard to + show a language specific layout. The "language" argument is a RFC-3066 + format language tag. + + It could be used for example in a word processor to indicate language of + currently edited document or in an instant message application which tracks + languages of contacts. + + + Notify when text should be inserted into the editor widget. The text @@ -272,6 +284,30 @@ + + + Sets the language of the input text. The "language" argument is a RFC-3066 + format language tag. + + + + + + + + + + + + Sets the text direction of input text. + + It is mainly needed for showing input cursor on correct side of the + editor when there is no input yet done and making sure neutral + direction text is laid out properly. + + + + diff --git a/src/text-backend.c b/src/text-backend.c index a92aebed..7741123a 100644 --- a/src/text-backend.c +++ b/src/text-backend.c @@ -300,6 +300,22 @@ text_model_hide_input_panel(struct wl_client *client, wl_signal_emit(&ec->hide_input_panel_signal, ec); } +static void +text_model_set_preferred_language(struct wl_client *client, + struct wl_resource *resource, + const char *language) +{ + struct text_model *text_model = resource->data; + struct input_method *input_method, *next; + + wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) { + if (!input_method->context) + continue; + input_method_context_send_preferred_language(&input_method->context->resource, + language); + } +} + static const struct text_model_interface text_model_implementation = { text_model_set_surrounding_text, text_model_activate, @@ -310,7 +326,8 @@ static const struct text_model_interface text_model_implementation = { text_model_invoke_action, text_model_commit, text_model_show_input_panel, - text_model_hide_input_panel + text_model_hide_input_panel, + text_model_set_preferred_language }; static void text_model_factory_create_text_model(struct wl_client *client, @@ -601,6 +618,29 @@ input_method_context_modifiers(struct wl_client *client, group); } +static void +input_method_context_language(struct wl_client *client, + struct wl_resource *resource, + uint32_t serial, + const char *language) +{ + struct input_method_context *context = resource->data; + + text_model_send_language(&context->model->resource, serial, language); +} + +static void +input_method_context_text_direction(struct wl_client *client, + struct wl_resource *resource, + uint32_t serial, + uint32_t direction) +{ + struct input_method_context *context = resource->data; + + text_model_send_text_direction(&context->model->resource, serial, direction); +} + + static const struct input_method_context_interface input_method_context_implementation = { input_method_context_destroy, input_method_context_commit_string, @@ -613,7 +653,9 @@ static const struct input_method_context_interface input_method_context_implemen input_method_context_keysym, input_method_context_grab_keyboard, input_method_context_key, - input_method_context_modifiers + input_method_context_modifiers, + input_method_context_language, + input_method_context_text_direction }; static void diff --git a/tests/text-test.c b/tests/text-test.c index f5c02ff8..41bf7506 100644 --- a/tests/text-test.c +++ b/tests/text-test.c @@ -131,6 +131,22 @@ text_model_input_panel_state(void *data, { } +static void +text_model_language(void *data, + struct text_model *text_model, + uint32_t serial, + const char *language) +{ +} + +static void +text_model_text_direction(void *data, + struct text_model *text_model, + uint32_t serial, + uint32_t direction) +{ +} + static const struct text_model_listener text_model_listener = { text_model_commit_string, text_model_preedit_string, @@ -142,7 +158,9 @@ static const struct text_model_listener text_model_listener = { text_model_keysym, text_model_enter, text_model_leave, - text_model_input_panel_state + text_model_input_panel_state, + text_model_language, + text_model_text_direction }; TEST(text_test)