text: Rename text_model to text_input

Also rename text_model_factory to text_input_manager.

Signed-off-by: Jan Arne Petersen <jpetersen@openismus.com>
dev
Jan Arne Petersen 12 years ago committed by Kristian Høgsberg
parent 7ef8effca5
commit 78d00e45cc
  1. 142
      clients/editor.c
  2. 10
      clients/keyboard.c
  3. 61
      protocol/text.xml
  4. 242
      src/text-backend.c
  5. 106
      tests/text-test.c

@ -57,7 +57,7 @@ struct text_entry {
int32_t cursor; int32_t cursor;
int32_t anchor; int32_t anchor;
} pending_commit; } pending_commit;
struct text_model *model; struct text_input *text_input;
PangoLayout *layout; PangoLayout *layout;
struct { struct {
xkb_mod_mask_t shift_mask; xkb_mod_mask_t shift_mask;
@ -69,7 +69,7 @@ struct text_entry {
}; };
struct editor { struct editor {
struct text_model_factory *text_model_factory; struct text_input_manager *text_input_manager;
struct display *display; struct display *display;
struct window *window; struct window *window;
struct widget *widget; struct widget *widget;
@ -129,8 +129,8 @@ static void text_entry_reset_preedit(struct text_entry *entry);
static void text_entry_commit_and_reset(struct text_entry *entry); static void text_entry_commit_and_reset(struct text_entry *entry);
static void static void
text_model_commit_string(void *data, text_input_commit_string(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
const char *text) const char *text)
{ {
@ -149,8 +149,8 @@ text_model_commit_string(void *data,
} }
static void static void
text_model_preedit_string(void *data, text_input_preedit_string(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
const char *text, const char *text,
const char *commit) const char *commit)
@ -169,8 +169,8 @@ text_model_preedit_string(void *data,
} }
static void static void
text_model_delete_surrounding_text(void *data, text_input_delete_surrounding_text(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
int32_t index, int32_t index,
uint32_t length) uint32_t length)
@ -201,8 +201,8 @@ text_model_delete_surrounding_text(void *data,
} }
static void static void
text_model_cursor_position(void *data, text_input_cursor_position(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
int32_t index, int32_t index,
int32_t anchor) int32_t anchor)
@ -214,8 +214,8 @@ text_model_cursor_position(void *data,
} }
static void static void
text_model_preedit_styling(void *data, text_input_preedit_styling(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
uint32_t index, uint32_t index,
uint32_t length, uint32_t length,
@ -229,24 +229,24 @@ text_model_preedit_styling(void *data,
entry->preedit_info.attr_list = pango_attr_list_new(); entry->preedit_info.attr_list = pango_attr_list_new();
switch (style) { switch (style) {
case TEXT_MODEL_PREEDIT_STYLE_DEFAULT: case TEXT_INPUT_PREEDIT_STYLE_DEFAULT:
case TEXT_MODEL_PREEDIT_STYLE_UNDERLINE: case TEXT_INPUT_PREEDIT_STYLE_UNDERLINE:
attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
break; break;
case TEXT_MODEL_PREEDIT_STYLE_INCORRECT: case TEXT_INPUT_PREEDIT_STYLE_INCORRECT:
attr1 = pango_attr_underline_new(PANGO_UNDERLINE_ERROR); attr1 = pango_attr_underline_new(PANGO_UNDERLINE_ERROR);
attr2 = pango_attr_underline_color_new(65535, 0, 0); attr2 = pango_attr_underline_color_new(65535, 0, 0);
break; break;
case TEXT_MODEL_PREEDIT_STYLE_SELECTION: case TEXT_INPUT_PREEDIT_STYLE_SELECTION:
attr1 = pango_attr_background_new(0.3 * 65535, 0.3 * 65535, 65535); attr1 = pango_attr_background_new(0.3 * 65535, 0.3 * 65535, 65535);
attr2 = pango_attr_foreground_new(65535, 65535, 65535); attr2 = pango_attr_foreground_new(65535, 65535, 65535);
break; break;
case TEXT_MODEL_PREEDIT_STYLE_HIGHLIGHT: case TEXT_INPUT_PREEDIT_STYLE_HIGHLIGHT:
case TEXT_MODEL_PREEDIT_STYLE_ACTIVE: case TEXT_INPUT_PREEDIT_STYLE_ACTIVE:
attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
attr2 = pango_attr_weight_new(PANGO_WEIGHT_BOLD); attr2 = pango_attr_weight_new(PANGO_WEIGHT_BOLD);
break; break;
case TEXT_MODEL_PREEDIT_STYLE_INACTIVE: case TEXT_INPUT_PREEDIT_STYLE_INACTIVE:
attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
attr2 = pango_attr_foreground_new(0.3 * 65535, 0.3 * 65535, 0.3 * 65535); attr2 = pango_attr_foreground_new(0.3 * 65535, 0.3 * 65535, 0.3 * 65535);
break; break;
@ -266,8 +266,8 @@ text_model_preedit_styling(void *data,
} }
static void static void
text_model_preedit_cursor(void *data, text_input_preedit_cursor(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
int32_t index) int32_t index)
{ {
@ -277,8 +277,8 @@ text_model_preedit_cursor(void *data,
} }
static void static void
text_model_modifiers_map(void *data, text_input_modifiers_map(void *data,
struct text_model *text_model, struct text_input *text_input,
struct wl_array *map) struct wl_array *map)
{ {
struct text_entry *entry = data; struct text_entry *entry = data;
@ -287,8 +287,8 @@ text_model_modifiers_map(void *data,
} }
static void static void
text_model_keysym(void *data, text_input_keysym(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
uint32_t time, uint32_t time,
uint32_t key, uint32_t key,
@ -356,8 +356,8 @@ text_model_keysym(void *data,
} }
static void static void
text_model_enter(void *data, text_input_enter(void *data,
struct text_model *text_model, struct text_input *text_input,
struct wl_surface *surface) struct wl_surface *surface)
{ {
struct text_entry *entry = data; struct text_entry *entry = data;
@ -371,8 +371,8 @@ text_model_enter(void *data,
} }
static void static void
text_model_leave(void *data, text_input_leave(void *data,
struct text_model *text_model) struct text_input *text_input)
{ {
struct text_entry *entry = data; struct text_entry *entry = data;
@ -380,21 +380,21 @@ text_model_leave(void *data,
entry->active = 0; entry->active = 0;
text_model_hide_input_panel(text_model); text_input_hide_input_panel(text_input);
widget_schedule_redraw(entry->widget); widget_schedule_redraw(entry->widget);
} }
static void static void
text_model_input_panel_state(void *data, text_input_input_panel_state(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t state) uint32_t state)
{ {
} }
static void static void
text_model_language(void *data, text_input_language(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
const char *language) const char *language)
{ {
@ -402,8 +402,8 @@ text_model_language(void *data,
} }
static void static void
text_model_text_direction(void *data, text_input_text_direction(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
uint32_t direction) uint32_t direction)
{ {
@ -413,13 +413,13 @@ text_model_text_direction(void *data,
switch (direction) { switch (direction) {
case TEXT_MODEL_TEXT_DIRECTION_LTR: case TEXT_INPUT_TEXT_DIRECTION_LTR:
pango_direction = PANGO_DIRECTION_LTR; pango_direction = PANGO_DIRECTION_LTR;
break; break;
case TEXT_MODEL_TEXT_DIRECTION_RTL: case TEXT_INPUT_TEXT_DIRECTION_RTL:
pango_direction = PANGO_DIRECTION_RTL; pango_direction = PANGO_DIRECTION_RTL;
break; break;
case TEXT_MODEL_TEXT_DIRECTION_AUTO: case TEXT_INPUT_TEXT_DIRECTION_AUTO:
default: default:
pango_direction = PANGO_DIRECTION_NEUTRAL; pango_direction = PANGO_DIRECTION_NEUTRAL;
} }
@ -427,20 +427,20 @@ text_model_text_direction(void *data,
pango_context_set_base_dir(context, pango_direction); pango_context_set_base_dir(context, pango_direction);
} }
static const struct text_model_listener text_model_listener = { static const struct text_input_listener text_input_listener = {
text_model_enter, text_input_enter,
text_model_leave, text_input_leave,
text_model_modifiers_map, text_input_modifiers_map,
text_model_input_panel_state, text_input_input_panel_state,
text_model_preedit_string, text_input_preedit_string,
text_model_preedit_styling, text_input_preedit_styling,
text_model_preedit_cursor, text_input_preedit_cursor,
text_model_commit_string, text_input_commit_string,
text_model_cursor_position, text_input_cursor_position,
text_model_delete_surrounding_text, text_input_delete_surrounding_text,
text_model_keysym, text_input_keysym,
text_model_language, text_input_language,
text_model_text_direction text_input_text_direction
}; };
static struct text_entry* static struct text_entry*
@ -456,8 +456,8 @@ text_entry_create(struct editor *editor, const char *text)
entry->active = 0; entry->active = 0;
entry->cursor = strlen(text); entry->cursor = strlen(text);
entry->anchor = entry->cursor; entry->anchor = entry->cursor;
entry->model = text_model_factory_create_text_model(editor->text_model_factory); entry->text_input = text_input_manager_create_text_input(editor->text_input_manager);
text_model_add_listener(entry->model, &text_model_listener, entry); text_input_add_listener(entry->text_input, &text_input_listener, entry);
widget_set_redraw_handler(entry->widget, text_entry_redraw_handler); widget_set_redraw_handler(entry->widget, text_entry_redraw_handler);
widget_set_button_handler(entry->widget, text_entry_button_handler); widget_set_button_handler(entry->widget, text_entry_button_handler);
@ -469,7 +469,7 @@ static void
text_entry_destroy(struct text_entry *entry) text_entry_destroy(struct text_entry *entry)
{ {
widget_destroy(entry->widget); widget_destroy(entry->widget);
text_model_destroy(entry->model); text_input_destroy(entry->text_input);
g_clear_object(&entry->layout); g_clear_object(&entry->layout);
free(entry->text); free(entry->text);
free(entry); free(entry);
@ -537,17 +537,17 @@ text_entry_activate(struct text_entry *entry,
struct wl_surface *surface = window_get_wl_surface(entry->window); struct wl_surface *surface = window_get_wl_surface(entry->window);
if (entry->click_to_show && entry->active) { if (entry->click_to_show && entry->active) {
text_model_show_input_panel(entry->model); text_input_show_input_panel(entry->text_input);
return; return;
} }
if (!entry->click_to_show) if (!entry->click_to_show)
text_model_show_input_panel(entry->model); text_input_show_input_panel(entry->text_input);
entry->serial++; entry->serial++;
text_model_activate(entry->model, text_input_activate(entry->text_input,
entry->serial, entry->serial,
seat, seat,
surface); surface);
@ -557,7 +557,7 @@ static void
text_entry_deactivate(struct text_entry *entry, text_entry_deactivate(struct text_entry *entry,
struct wl_seat *seat) struct wl_seat *seat)
{ {
text_model_deactivate(entry->model, text_input_deactivate(entry->text_input,
seat); seat);
} }
@ -627,20 +627,20 @@ text_entry_update_layout(struct text_entry *entry)
static void static void
text_entry_update(struct text_entry *entry) text_entry_update(struct text_entry *entry)
{ {
text_model_set_content_type(entry->model, text_input_set_content_type(entry->text_input,
TEXT_MODEL_CONTENT_HINT_NONE, TEXT_INPUT_CONTENT_HINT_NONE,
entry->content_purpose); entry->content_purpose);
text_model_set_surrounding_text(entry->model, text_input_set_surrounding_text(entry->text_input,
entry->text, entry->text,
entry->cursor, entry->cursor,
entry->anchor); entry->anchor);
if (entry->preferred_language) if (entry->preferred_language)
text_model_set_preferred_language(entry->model, text_input_set_preferred_language(entry->text_input,
entry->preferred_language); entry->preferred_language);
text_model_commit_state(entry->model); text_input_commit_state(entry->text_input);
} }
static void static void
@ -702,7 +702,7 @@ text_entry_commit_and_reset(struct text_entry *entry)
} }
entry->serial++; entry->serial++;
text_model_reset(entry->model, entry->serial); text_input_reset(entry->text_input, entry->serial);
} }
static void static void
@ -746,7 +746,7 @@ text_entry_try_invoke_preedit_action(struct text_entry *entry,
} }
if (state == WL_POINTER_BUTTON_STATE_RELEASED) if (state == WL_POINTER_BUTTON_STATE_RELEASED)
text_model_invoke_action(entry->model, text_input_invoke_action(entry->text_input,
button, button,
cursor - entry->cursor); cursor - entry->cursor);
@ -1073,10 +1073,10 @@ global_handler(struct display *display, uint32_t name,
{ {
struct editor *editor = data; struct editor *editor = data;
if (!strcmp(interface, "text_model_factory")) { if (!strcmp(interface, "text_input_manager")) {
editor->text_model_factory = editor->text_input_manager =
display_bind(display, name, display_bind(display, name,
&text_model_factory_interface, 1); &text_input_manager_interface, 1);
} }
} }
@ -1122,7 +1122,7 @@ main(int argc, char *argv[])
if (preferred_language) if (preferred_language)
editor.entry->preferred_language = strdup(preferred_language); editor.entry->preferred_language = strdup(preferred_language);
editor.editor = text_entry_create(&editor, "Numeric"); editor.editor = text_entry_create(&editor, "Numeric");
editor.editor->content_purpose = TEXT_MODEL_CONTENT_PURPOSE_NUMBER; editor.editor->content_purpose = TEXT_INPUT_CONTENT_PURPOSE_NUMBER;
editor.editor->click_to_show = click_to_show; editor.editor->click_to_show = click_to_show;
window_set_title(editor.window, "Text Editor"); window_set_title(editor.window, "Text Editor");

@ -211,7 +211,7 @@ static const struct layout normal_layout = {
12, 12,
4, 4,
"en", "en",
TEXT_MODEL_TEXT_DIRECTION_LTR TEXT_INPUT_TEXT_DIRECTION_LTR
}; };
static const struct layout numeric_layout = { static const struct layout numeric_layout = {
@ -220,7 +220,7 @@ static const struct layout numeric_layout = {
12, 12,
2, 2,
"en", "en",
TEXT_MODEL_TEXT_DIRECTION_LTR TEXT_INPUT_TEXT_DIRECTION_LTR
}; };
static const struct layout arabic_layout = { static const struct layout arabic_layout = {
@ -229,7 +229,7 @@ static const struct layout arabic_layout = {
13, 13,
4, 4,
"ar", "ar",
TEXT_MODEL_TEXT_DIRECTION_RTL TEXT_INPUT_TEXT_DIRECTION_RTL
}; };
static const char *style_labels[] = { static const char *style_labels[] = {
@ -314,8 +314,8 @@ static const struct layout *
get_current_layout(struct virtual_keyboard *keyboard) get_current_layout(struct virtual_keyboard *keyboard)
{ {
switch (keyboard->content_purpose) { switch (keyboard->content_purpose) {
case TEXT_MODEL_CONTENT_PURPOSE_DIGITS: case TEXT_INPUT_CONTENT_PURPOSE_DIGITS:
case TEXT_MODEL_CONTENT_PURPOSE_NUMBER: case TEXT_INPUT_CONTENT_PURPOSE_NUMBER:
return &numeric_layout; return &numeric_layout;
default: default:
if (keyboard->preferred_language && if (keyboard->preferred_language &&

@ -26,24 +26,27 @@
THIS SOFTWARE. THIS SOFTWARE.
</copyright> </copyright>
<interface name="text_model" version="1"> <interface name="text_input" version="1">
<description summary="text model"> <description summary="text input">
A model for text input. Adds support for text input and input methods to An object used for text input. Adds support for text input and input
applications. A text_model object is created from a text_model_factory and methods to applications. A text-input object is created from a
corresponds typically to a text entry in an application. Requests are used text_input_manager and corresponds typically to a text entry in an
to activate/deactivate the model and set information like surrounding and application.
selected text or the content type. The information about entered text is Requests are used to activate/deactivate the text-input object and set
sent to the model via the pre-edit and commit events. Using this interface state information like surrounding and selected text or the content type.
removes the need for applications to directly process hardware key events The information about entered text is sent to the text-input object via
and compose text out of them. the pre-edit and commit events. Using this interface removes the need
for applications to directly process hardware key events and compose text
out of them.
</description> </description>
<request name="activate"> <request name="activate">
<description summary="request activation"> <description summary="request activation">
Requests the model to be activated (typically when the text entry gets Requests the text-input object to be activated (typically when the
focus). The seat argument is a wl_seat which maintains the focus for text entry gets focus).
this activation. The surface argument is a wl_surface assigned to the The seat argument is a wl_seat which maintains the focus for this
model and tracked for focus lost. The activated event is emitted on activation. The surface argument is a wl_surface assigned to the
successful activation. text-input object and tracked for focus lost. The enter event
is emitted on successful activation.
</description> </description>
<arg name="serial" type="uint"/> <arg name="serial" type="uint"/>
<arg name="seat" type="object" interface="wl_seat"/> <arg name="seat" type="object" interface="wl_seat"/>
@ -51,9 +54,9 @@
</request> </request>
<request name="deactivate"> <request name="deactivate">
<description summary="request deactivation"> <description summary="request deactivation">
Requests the model to be deactivated (typically when the text entry Requests the text-input object to be deactivated (typically when the
lost focus). The seat argument is a wl_seat which was used for text entry lost focus). The seat argument is a wl_seat which was used
activation. for activation.
</description> </description>
<arg name="seat" type="object" interface="wl_seat"/> <arg name="seat" type="object" interface="wl_seat"/>
</request> </request>
@ -166,15 +169,15 @@
</request> </request>
<event name="enter"> <event name="enter">
<description summary="enter event"> <description summary="enter event">
Notify the model when it is activated. Typically in response to an Notify the text-input object when it received focus. Typically in
activate request. response to an activate request.
</description> </description>
<arg name="surface" type="object" interface="wl_surface"/> <arg name="surface" type="object" interface="wl_surface"/>
</event> </event>
<event name="leave"> <event name="leave">
<description summary="leave event"> <description summary="leave event">
Notify the model when it is deactivated. Either in response to a Notify the text-input object when it lost focus. Either in response
deactivate request or when the assigned surface lost focus or was to a deactivate request or when the assigned surface lost focus or was
destroyed. destroyed.
</description> </description>
</event> </event>
@ -312,15 +315,15 @@
</event> </event>
</interface> </interface>
<interface name="text_model_factory" version="1"> <interface name="text_input_manager" version="1">
<description summary="text model factory"> <description summary="text input manager">
A factory for text models. This object is a global singleton. A factory for text-input objects. This object is a global singleton.
</description> </description>
<request name="create_text_model"> <request name="create_text_input">
<description summary="create text model"> <description summary="create text input">
Creates a new text model object. Creates a new text-input object.
</description> </description>
<arg name="id" type="new_id" interface="text_model"/> <arg name="id" type="new_id" interface="text_input"/>
</request> </request>
</interface> </interface>
</protocol> </protocol>

@ -32,7 +32,7 @@ struct input_method;
struct input_method_context; struct input_method_context;
struct text_backend; struct text_backend;
struct text_model { struct text_input {
struct wl_resource resource; struct wl_resource resource;
struct weston_compositor *ec; struct weston_compositor *ec;
@ -44,8 +44,8 @@ struct text_model {
uint32_t input_panel_visible; uint32_t input_panel_visible;
}; };
struct text_model_factory { struct text_input_manager {
struct wl_global *text_model_factory_global; struct wl_global *text_input_manager_global;
struct wl_listener destroy_listener; struct wl_listener destroy_listener;
struct weston_compositor *ec; struct weston_compositor *ec;
@ -57,7 +57,7 @@ struct input_method {
struct wl_listener destroy_listener; struct wl_listener destroy_listener;
struct weston_seat *seat; struct weston_seat *seat;
struct text_model *model; struct text_input *model;
struct wl_list link; struct wl_list link;
@ -73,7 +73,7 @@ struct input_method {
struct input_method_context { struct input_method_context {
struct wl_resource resource; struct wl_resource resource;
struct text_model *model; struct text_input *model;
struct input_method *input_method; struct input_method *input_method;
struct wl_list link; struct wl_list link;
@ -95,7 +95,7 @@ struct text_backend {
struct wl_listener destroy_listener; struct wl_listener destroy_listener;
}; };
static void input_method_context_create(struct text_model *model, static void input_method_context_create(struct text_input *model,
struct input_method *input_method, struct input_method *input_method,
uint32_t serial); uint32_t serial);
static void input_method_context_end_keyboard_grab(struct input_method_context *context); static void input_method_context_end_keyboard_grab(struct input_method_context *context);
@ -103,12 +103,12 @@ static void input_method_context_end_keyboard_grab(struct input_method_context *
static void input_method_init_seat(struct weston_seat *seat); static void input_method_init_seat(struct weston_seat *seat);
static void static void
deactivate_text_model(struct text_model *text_model, deactivate_text_input(struct text_input *text_input,
struct input_method *input_method) struct input_method *input_method)
{ {
struct weston_compositor *ec = text_model->ec; struct weston_compositor *ec = text_input->ec;
if (input_method->model == text_model) { if (input_method->model == text_input) {
if (input_method->context && input_method->input_method_binding) { if (input_method->context && input_method->input_method_binding) {
input_method_context_end_keyboard_grab(input_method->context); input_method_context_end_keyboard_grab(input_method->context);
input_method_send_deactivate(input_method->input_method_binding, input_method_send_deactivate(input_method->input_method_binding,
@ -119,34 +119,34 @@ deactivate_text_model(struct text_model *text_model,
input_method->model = NULL; input_method->model = NULL;
input_method->context = NULL; input_method->context = NULL;
wl_signal_emit(&ec->hide_input_panel_signal, ec); wl_signal_emit(&ec->hide_input_panel_signal, ec);
text_model_send_leave(&text_model->resource); text_input_send_leave(&text_input->resource);
} }
} }
static void static void
destroy_text_model(struct wl_resource *resource) destroy_text_input(struct wl_resource *resource)
{ {
struct text_model *text_model = struct text_input *text_input =
container_of(resource, struct text_model, resource); container_of(resource, struct text_input, resource);
struct input_method *input_method, *next; struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) wl_list_for_each_safe(input_method, next, &text_input->input_methods, link)
deactivate_text_model(text_model, input_method); deactivate_text_input(text_input, input_method);
free(text_model); free(text_input);
} }
static void static void
text_model_set_surrounding_text(struct wl_client *client, text_input_set_surrounding_text(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
const char *text, const char *text,
uint32_t cursor, uint32_t cursor,
uint32_t anchor) uint32_t anchor)
{ {
struct text_model *text_model = resource->data; struct text_input *text_input = resource->data;
struct input_method *input_method, *next; struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) { wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
if (!input_method->context) if (!input_method->context)
continue; continue;
input_method_context_send_surrounding_text(&input_method->context->resource, input_method_context_send_surrounding_text(&input_method->context->resource,
@ -157,61 +157,61 @@ text_model_set_surrounding_text(struct wl_client *client,
} }
static void static void
text_model_activate(struct wl_client *client, text_input_activate(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
uint32_t serial, uint32_t serial,
struct wl_resource *seat, struct wl_resource *seat,
struct wl_resource *surface) struct wl_resource *surface)
{ {
struct text_model *text_model = resource->data; struct text_input *text_input = resource->data;
struct weston_seat *weston_seat = seat->data; struct weston_seat *weston_seat = seat->data;
struct input_method *input_method = weston_seat->input_method; struct input_method *input_method = weston_seat->input_method;
struct text_model *old = weston_seat->input_method->model; struct text_input *old = weston_seat->input_method->model;
struct weston_compositor *ec = text_model->ec; struct weston_compositor *ec = text_input->ec;
if (old == text_model) if (old == text_input)
return; return;
if (old) { if (old) {
deactivate_text_model(old, deactivate_text_input(old,
weston_seat->input_method); weston_seat->input_method);
} }
input_method->model = text_model; input_method->model = text_input;
wl_list_insert(&text_model->input_methods, &input_method->link); wl_list_insert(&text_input->input_methods, &input_method->link);
input_method_init_seat(weston_seat); input_method_init_seat(weston_seat);
text_model->surface = surface->data; text_input->surface = surface->data;
input_method_context_create(text_model, input_method, serial); input_method_context_create(text_input, input_method, serial);
if (text_model->input_panel_visible) if (text_input->input_panel_visible)
wl_signal_emit(&ec->show_input_panel_signal, ec); wl_signal_emit(&ec->show_input_panel_signal, ec);
text_model_send_enter(&text_model->resource, &text_model->surface->resource); text_input_send_enter(&text_input->resource, &text_input->surface->resource);
} }
static void static void
text_model_deactivate(struct wl_client *client, text_input_deactivate(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
struct wl_resource *seat) struct wl_resource *seat)
{ {
struct text_model *text_model = resource->data; struct text_input *text_input = resource->data;
struct weston_seat *weston_seat = seat->data; struct weston_seat *weston_seat = seat->data;
deactivate_text_model(text_model, deactivate_text_input(text_input,
weston_seat->input_method); weston_seat->input_method);
} }
static void static void
text_model_reset(struct wl_client *client, text_input_reset(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
uint32_t serial) uint32_t serial)
{ {
struct text_model *text_model = resource->data; struct text_input *text_input = resource->data;
struct input_method *input_method, *next; struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) { wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
if (!input_method->context) if (!input_method->context)
continue; continue;
input_method_context_send_reset(&input_method->context->resource, serial); input_method_context_send_reset(&input_method->context->resource, serial);
@ -219,7 +219,7 @@ text_model_reset(struct wl_client *client,
} }
static void static void
text_model_set_cursor_rectangle(struct wl_client *client, text_input_set_cursor_rectangle(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
int32_t x, int32_t x,
int32_t y, int32_t y,
@ -229,15 +229,15 @@ text_model_set_cursor_rectangle(struct wl_client *client,
} }
static void static void
text_model_set_content_type(struct wl_client *client, text_input_set_content_type(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
uint32_t hint, uint32_t hint,
uint32_t purpose) uint32_t purpose)
{ {
struct text_model *text_model = resource->data; struct text_input *text_input = resource->data;
struct input_method *input_method, *next; struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) { wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
if (!input_method->context) if (!input_method->context)
continue; continue;
input_method_context_send_content_type(&input_method->context->resource, hint, purpose); input_method_context_send_content_type(&input_method->context->resource, hint, purpose);
@ -245,15 +245,15 @@ text_model_set_content_type(struct wl_client *client,
} }
static void static void
text_model_invoke_action(struct wl_client *client, text_input_invoke_action(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
uint32_t button, uint32_t button,
uint32_t index) uint32_t index)
{ {
struct text_model *text_model = resource->data; struct text_input *text_input = resource->data;
struct input_method *input_method, *next; struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) { wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
if (!input_method->context) if (!input_method->context)
continue; continue;
input_method_context_send_invoke_action(&input_method->context->resource, button, index); input_method_context_send_invoke_action(&input_method->context->resource, button, index);
@ -261,13 +261,13 @@ text_model_invoke_action(struct wl_client *client,
} }
static void static void
text_model_commit_state(struct wl_client *client, text_input_commit_state(struct wl_client *client,
struct wl_resource *resource) struct wl_resource *resource)
{ {
struct text_model *text_model = resource->data; struct text_input *text_input = resource->data;
struct input_method *input_method, *next; struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) { wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
if (!input_method->context) if (!input_method->context)
continue; continue;
input_method_context_send_commit(&input_method->context->resource); input_method_context_send_commit(&input_method->context->resource);
@ -275,40 +275,40 @@ text_model_commit_state(struct wl_client *client,
} }
static void static void
text_model_show_input_panel(struct wl_client *client, text_input_show_input_panel(struct wl_client *client,
struct wl_resource *resource) struct wl_resource *resource)
{ {
struct text_model *text_model = resource->data; struct text_input *text_input = resource->data;
struct weston_compositor *ec = text_model->ec; struct weston_compositor *ec = text_input->ec;
text_model->input_panel_visible = 1; text_input->input_panel_visible = 1;
if (!wl_list_empty(&text_model->input_methods)) if (!wl_list_empty(&text_input->input_methods))
wl_signal_emit(&ec->show_input_panel_signal, ec); wl_signal_emit(&ec->show_input_panel_signal, ec);
} }
static void static void
text_model_hide_input_panel(struct wl_client *client, text_input_hide_input_panel(struct wl_client *client,
struct wl_resource *resource) struct wl_resource *resource)
{ {
struct text_model *text_model = resource->data; struct text_input *text_input = resource->data;
struct weston_compositor *ec = text_model->ec; struct weston_compositor *ec = text_input->ec;
text_model->input_panel_visible = 0; text_input->input_panel_visible = 0;
if (!wl_list_empty(&text_model->input_methods)) if (!wl_list_empty(&text_input->input_methods))
wl_signal_emit(&ec->hide_input_panel_signal, ec); wl_signal_emit(&ec->hide_input_panel_signal, ec);
} }
static void static void
text_model_set_preferred_language(struct wl_client *client, text_input_set_preferred_language(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
const char *language) const char *language)
{ {
struct text_model *text_model = resource->data; struct text_input *text_input = resource->data;
struct input_method *input_method, *next; struct input_method *input_method, *next;
wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) { wl_list_for_each_safe(input_method, next, &text_input->input_methods, link) {
if (!input_method->context) if (!input_method->context)
continue; continue;
input_method_context_send_preferred_language(&input_method->context->resource, input_method_context_send_preferred_language(&input_method->context->resource,
@ -316,91 +316,91 @@ text_model_set_preferred_language(struct wl_client *client,
} }
} }
static const struct text_model_interface text_model_implementation = { static const struct text_input_interface text_input_implementation = {
text_model_activate, text_input_activate,
text_model_deactivate, text_input_deactivate,
text_model_show_input_panel, text_input_show_input_panel,
text_model_hide_input_panel, text_input_hide_input_panel,
text_model_reset, text_input_reset,
text_model_set_surrounding_text, text_input_set_surrounding_text,
text_model_set_content_type, text_input_set_content_type,
text_model_set_cursor_rectangle, text_input_set_cursor_rectangle,
text_model_set_preferred_language, text_input_set_preferred_language,
text_model_commit_state, text_input_commit_state,
text_model_invoke_action text_input_invoke_action
}; };
static void text_model_factory_create_text_model(struct wl_client *client, static void text_input_manager_create_text_input(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
uint32_t id) uint32_t id)
{ {
struct text_model_factory *text_model_factory = resource->data; struct text_input_manager *text_input_manager = resource->data;
struct text_model *text_model; struct text_input *text_input;
text_model = calloc(1, sizeof *text_model); text_input = calloc(1, sizeof *text_input);
text_model->resource.object.id = id; text_input->resource.object.id = id;
text_model->resource.object.interface = &text_model_interface; text_input->resource.object.interface = &text_input_interface;
text_model->resource.object.implementation = text_input->resource.object.implementation =
(void (**)(void)) &text_model_implementation; (void (**)(void)) &text_input_implementation;
text_model->resource.data = text_model; text_input->resource.data = text_input;
text_model->resource.destroy = destroy_text_model; text_input->resource.destroy = destroy_text_input;
text_model->ec = text_model_factory->ec; text_input->ec = text_input_manager->ec;
wl_list_init(&text_model->input_methods); wl_list_init(&text_input->input_methods);
wl_client_add_resource(client, &text_model->resource); wl_client_add_resource(client, &text_input->resource);
}; };
static const struct text_model_factory_interface text_model_factory_implementation = { static const struct text_input_manager_interface text_input_manager_implementation = {
text_model_factory_create_text_model text_input_manager_create_text_input
}; };
static void static void
bind_text_model_factory(struct wl_client *client, bind_text_input_manager(struct wl_client *client,
void *data, void *data,
uint32_t version, uint32_t version,
uint32_t id) uint32_t id)
{ {
struct text_model_factory *text_model_factory = data; struct text_input_manager *text_input_manager = data;
/* No checking for duplicate binding necessary. /* No checking for duplicate binding necessary.
* No events have to be sent, so we don't need the return value. */ * No events have to be sent, so we don't need the return value. */
wl_client_add_object(client, &text_model_factory_interface, wl_client_add_object(client, &text_input_manager_interface,
&text_model_factory_implementation, &text_input_manager_implementation,
id, text_model_factory); id, text_input_manager);
} }
static void static void
text_model_factory_notifier_destroy(struct wl_listener *listener, void *data) text_input_manager_notifier_destroy(struct wl_listener *listener, void *data)
{ {
struct text_model_factory *text_model_factory = struct text_input_manager *text_input_manager =
container_of(listener, struct text_model_factory, destroy_listener); container_of(listener, struct text_input_manager, destroy_listener);
wl_display_remove_global(text_model_factory->ec->wl_display, wl_display_remove_global(text_input_manager->ec->wl_display,
text_model_factory->text_model_factory_global); text_input_manager->text_input_manager_global);
free(text_model_factory); free(text_input_manager);
} }
static void static void
text_model_factory_create(struct weston_compositor *ec) text_input_manager_create(struct weston_compositor *ec)
{ {
struct text_model_factory *text_model_factory; struct text_input_manager *text_input_manager;
text_model_factory = calloc(1, sizeof *text_model_factory); text_input_manager = calloc(1, sizeof *text_input_manager);
text_model_factory->ec = ec; text_input_manager->ec = ec;
text_model_factory->text_model_factory_global = text_input_manager->text_input_manager_global =
wl_display_add_global(ec->wl_display, wl_display_add_global(ec->wl_display,
&text_model_factory_interface, &text_input_manager_interface,
text_model_factory, bind_text_model_factory); text_input_manager, bind_text_input_manager);
text_model_factory->destroy_listener.notify = text_model_factory_notifier_destroy; text_input_manager->destroy_listener.notify = text_input_manager_notifier_destroy;
wl_signal_add(&ec->destroy_signal, &text_model_factory->destroy_listener); wl_signal_add(&ec->destroy_signal, &text_input_manager->destroy_listener);
} }
static void static void
@ -418,7 +418,7 @@ input_method_context_commit_string(struct wl_client *client,
{ {
struct input_method_context *context = resource->data; struct input_method_context *context = resource->data;
text_model_send_commit_string(&context->model->resource, serial, text); text_input_send_commit_string(&context->model->resource, serial, text);
} }
static void static void
@ -430,7 +430,7 @@ input_method_context_preedit_string(struct wl_client *client,
{ {
struct input_method_context *context = resource->data; struct input_method_context *context = resource->data;
text_model_send_preedit_string(&context->model->resource, serial, text, commit); text_input_send_preedit_string(&context->model->resource, serial, text, commit);
} }
static void static void
@ -443,7 +443,7 @@ input_method_context_preedit_styling(struct wl_client *client,
{ {
struct input_method_context *context = resource->data; struct input_method_context *context = resource->data;
text_model_send_preedit_styling(&context->model->resource, serial, index, length, style); text_input_send_preedit_styling(&context->model->resource, serial, index, length, style);
} }
static void static void
@ -454,7 +454,7 @@ input_method_context_preedit_cursor(struct wl_client *client,
{ {
struct input_method_context *context = resource->data; struct input_method_context *context = resource->data;
text_model_send_preedit_cursor(&context->model->resource, serial, cursor); text_input_send_preedit_cursor(&context->model->resource, serial, cursor);
} }
static void static void
@ -466,7 +466,7 @@ input_method_context_delete_surrounding_text(struct wl_client *client,
{ {
struct input_method_context *context = resource->data; struct input_method_context *context = resource->data;
text_model_send_delete_surrounding_text(&context->model->resource, serial, index, length); text_input_send_delete_surrounding_text(&context->model->resource, serial, index, length);
} }
static void static void
@ -478,7 +478,7 @@ input_method_context_cursor_position(struct wl_client *client,
{ {
struct input_method_context *context = resource->data; struct input_method_context *context = resource->data;
text_model_send_cursor_position(&context->model->resource, serial, index, anchor); text_input_send_cursor_position(&context->model->resource, serial, index, anchor);
} }
static void static void
@ -488,7 +488,7 @@ input_method_context_modifiers_map(struct wl_client *client,
{ {
struct input_method_context *context = resource->data; struct input_method_context *context = resource->data;
text_model_send_modifiers_map(&context->model->resource, map); text_input_send_modifiers_map(&context->model->resource, map);
} }
static void static void
@ -502,7 +502,7 @@ input_method_context_keysym(struct wl_client *client,
{ {
struct input_method_context *context = resource->data; struct input_method_context *context = resource->data;
text_model_send_keysym(&context->model->resource, serial, time, text_input_send_keysym(&context->model->resource, serial, time,
sym, state, modifiers); sym, state, modifiers);
} }
@ -626,7 +626,7 @@ input_method_context_language(struct wl_client *client,
{ {
struct input_method_context *context = resource->data; struct input_method_context *context = resource->data;
text_model_send_language(&context->model->resource, serial, language); text_input_send_language(&context->model->resource, serial, language);
} }
static void static void
@ -637,7 +637,7 @@ input_method_context_text_direction(struct wl_client *client,
{ {
struct input_method_context *context = resource->data; struct input_method_context *context = resource->data;
text_model_send_text_direction(&context->model->resource, serial, direction); text_input_send_text_direction(&context->model->resource, serial, direction);
} }
@ -671,7 +671,7 @@ destroy_input_method_context(struct wl_resource *resource)
} }
static void static void
input_method_context_create(struct text_model *model, input_method_context_create(struct text_input *model,
struct input_method *input_method, struct input_method *input_method,
uint32_t serial) uint32_t serial)
{ {
@ -764,7 +764,7 @@ input_method_notifier_destroy(struct wl_listener *listener, void *data)
container_of(listener, struct input_method, destroy_listener); container_of(listener, struct input_method, destroy_listener);
if (input_method->model) if (input_method->model)
deactivate_text_model(input_method->model, input_method); deactivate_text_input(input_method->model, input_method);
wl_display_remove_global(input_method->seat->compositor->wl_display, wl_display_remove_global(input_method->seat->compositor->wl_display,
input_method->input_method_global); input_method->input_method_global);
@ -784,7 +784,7 @@ handle_keyboard_focus(struct wl_listener *listener, void *data)
return; return;
if (!surface || input_method->model->surface != surface) if (!surface || input_method->model->surface != surface)
deactivate_text_model(input_method->model, deactivate_text_input(input_method->model,
input_method); input_method);
} }
@ -923,7 +923,7 @@ text_backend_init(struct weston_compositor *ec)
text_backend_configuration(text_backend); text_backend_configuration(text_backend);
text_model_factory_create(ec); text_input_manager_create(ec);
return 0; return 0;
} }

@ -26,22 +26,22 @@
#include "weston-test-client-helper.h" #include "weston-test-client-helper.h"
#include "../clients/text-client-protocol.h" #include "../clients/text-client-protocol.h"
struct text_model_state { struct text_input_state {
int activated; int activated;
int deactivated; int deactivated;
}; };
static void static void
text_model_commit_string(void *data, text_input_commit_string(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
const char *text) const char *text)
{ {
} }
static void static void
text_model_preedit_string(void *data, text_input_preedit_string(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
const char *text, const char *text,
const char *commit) const char *commit)
@ -49,8 +49,8 @@ text_model_preedit_string(void *data,
} }
static void static void
text_model_delete_surrounding_text(void *data, text_input_delete_surrounding_text(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
int32_t index, int32_t index,
uint32_t length) uint32_t length)
@ -58,8 +58,8 @@ text_model_delete_surrounding_text(void *data,
} }
static void static void
text_model_cursor_position(void *data, text_input_cursor_position(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
int32_t index, int32_t index,
int32_t anchor) int32_t anchor)
@ -67,8 +67,8 @@ text_model_cursor_position(void *data,
} }
static void static void
text_model_preedit_styling(void *data, text_input_preedit_styling(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
uint32_t index, uint32_t index,
uint32_t length, uint32_t length,
@ -77,23 +77,23 @@ text_model_preedit_styling(void *data,
} }
static void static void
text_model_preedit_cursor(void *data, text_input_preedit_cursor(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
int32_t index) int32_t index)
{ {
} }
static void static void
text_model_modifiers_map(void *data, text_input_modifiers_map(void *data,
struct text_model *text_model, struct text_input *text_input,
struct wl_array *map) struct wl_array *map)
{ {
} }
static void static void
text_model_keysym(void *data, text_input_keysym(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
uint32_t time, uint32_t time,
uint32_t sym, uint32_t sym,
@ -103,12 +103,12 @@ text_model_keysym(void *data,
} }
static void static void
text_model_enter(void *data, text_input_enter(void *data,
struct text_model *text_model, struct text_input *text_input,
struct wl_surface *surface) struct wl_surface *surface)
{ {
struct text_model_state *state = data; struct text_input_state *state = data;
fprintf(stderr, "%s\n", __FUNCTION__); fprintf(stderr, "%s\n", __FUNCTION__);
@ -116,77 +116,77 @@ text_model_enter(void *data,
} }
static void static void
text_model_leave(void *data, text_input_leave(void *data,
struct text_model *text_model) struct text_input *text_input)
{ {
struct text_model_state *state = data; struct text_input_state *state = data;
state->deactivated += 1; state->deactivated += 1;
} }
static void static void
text_model_input_panel_state(void *data, text_input_input_panel_state(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t state) uint32_t state)
{ {
} }
static void static void
text_model_language(void *data, text_input_language(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
const char *language) const char *language)
{ {
} }
static void static void
text_model_text_direction(void *data, text_input_text_direction(void *data,
struct text_model *text_model, struct text_input *text_input,
uint32_t serial, uint32_t serial,
uint32_t direction) uint32_t direction)
{ {
} }
static const struct text_model_listener text_model_listener = { static const struct text_input_listener text_input_listener = {
text_model_enter, text_input_enter,
text_model_leave, text_input_leave,
text_model_modifiers_map, text_input_modifiers_map,
text_model_input_panel_state, text_input_input_panel_state,
text_model_preedit_string, text_input_preedit_string,
text_model_preedit_styling, text_input_preedit_styling,
text_model_preedit_cursor, text_input_preedit_cursor,
text_model_commit_string, text_input_commit_string,
text_model_cursor_position, text_input_cursor_position,
text_model_delete_surrounding_text, text_input_delete_surrounding_text,
text_model_keysym, text_input_keysym,
text_model_language, text_input_language,
text_model_text_direction text_input_text_direction
}; };
TEST(text_test) TEST(text_test)
{ {
struct client *client; struct client *client;
struct global *global; struct global *global;
struct text_model_factory *factory; struct text_input_manager *factory;
struct text_model *text_model; struct text_input *text_input;
struct text_model_state state; struct text_input_state state;
client = client_create(100, 100, 100, 100); client = client_create(100, 100, 100, 100);
assert(client); assert(client);
factory = NULL; factory = NULL;
wl_list_for_each(global, &client->global_list, link) { wl_list_for_each(global, &client->global_list, link) {
if (strcmp(global->interface, "text_model_factory") == 0) if (strcmp(global->interface, "text_input_manager") == 0)
factory = wl_registry_bind(client->wl_registry, factory = wl_registry_bind(client->wl_registry,
global->name, global->name,
&text_model_factory_interface, 1); &text_input_manager_interface, 1);
} }
assert(factory); assert(factory);
memset(&state, 0, sizeof state); memset(&state, 0, sizeof state);
text_model = text_model_factory_create_text_model(factory); text_input = text_input_manager_create_text_input(factory);
text_model_add_listener(text_model, &text_model_listener, &state); text_input_add_listener(text_input, &text_input_listener, &state);
/* Make sure our test surface has keyboard focus. */ /* Make sure our test surface has keyboard focus. */
wl_test_activate_surface(client->test->wl_test, wl_test_activate_surface(client->test->wl_test,
@ -195,18 +195,18 @@ TEST(text_test)
assert(client->input->keyboard->focus == client->surface); assert(client->input->keyboard->focus == client->surface);
/* Activate test model and make sure we get enter event. */ /* Activate test model and make sure we get enter event. */
text_model_activate(text_model, 0, client->input->wl_seat, text_input_activate(text_input, 0, client->input->wl_seat,
client->surface->wl_surface); client->surface->wl_surface);
client_roundtrip(client); client_roundtrip(client);
assert(state.activated == 1 && state.deactivated == 0); assert(state.activated == 1 && state.deactivated == 0);
/* Deactivate test model and make sure we get leave event. */ /* Deactivate test model and make sure we get leave event. */
text_model_deactivate(text_model, client->input->wl_seat); text_input_deactivate(text_input, client->input->wl_seat);
client_roundtrip(client); client_roundtrip(client);
assert(state.activated == 1 && state.deactivated == 1); assert(state.activated == 1 && state.deactivated == 1);
/* Activate test model again. */ /* Activate test model again. */
text_model_activate(text_model, 0, client->input->wl_seat, text_input_activate(text_input, 0, client->input->wl_seat,
client->surface->wl_surface); client->surface->wl_surface);
client_roundtrip(client); client_roundtrip(client);
assert(state.activated == 2 && state.deactivated == 1); assert(state.activated == 2 && state.deactivated == 1);

Loading…
Cancel
Save