Also rename text_model_factory to text_input_manager.
Signed-off-by: Jan Arne Petersen <jpetersen@openismus.com>
int32_t cursor;
int32_t anchor;
} pending_commit;
- struct text_model *model;
+ struct text_input *text_input;
PangoLayout *layout;
struct {
xkb_mod_mask_t shift_mask;
};
struct editor {
- struct text_model_factory *text_model_factory;
+ struct text_input_manager *text_input_manager;
struct display *display;
struct window *window;
struct widget *widget;
static void text_entry_commit_and_reset(struct text_entry *entry);
static void
-text_model_commit_string(void *data,
- struct text_model *text_model,
+text_input_commit_string(void *data,
+ struct text_input *text_input,
uint32_t serial,
const char *text)
{
}
static void
-text_model_preedit_string(void *data,
- struct text_model *text_model,
+text_input_preedit_string(void *data,
+ struct text_input *text_input,
uint32_t serial,
const char *text,
const char *commit)
}
static void
-text_model_delete_surrounding_text(void *data,
- struct text_model *text_model,
+text_input_delete_surrounding_text(void *data,
+ struct text_input *text_input,
uint32_t serial,
int32_t index,
uint32_t length)
}
static void
-text_model_cursor_position(void *data,
- struct text_model *text_model,
+text_input_cursor_position(void *data,
+ struct text_input *text_input,
uint32_t serial,
int32_t index,
int32_t anchor)
}
static void
-text_model_preedit_styling(void *data,
- struct text_model *text_model,
+text_input_preedit_styling(void *data,
+ struct text_input *text_input,
uint32_t serial,
uint32_t index,
uint32_t length,
entry->preedit_info.attr_list = pango_attr_list_new();
switch (style) {
- case TEXT_MODEL_PREEDIT_STYLE_DEFAULT:
- case TEXT_MODEL_PREEDIT_STYLE_UNDERLINE:
+ case TEXT_INPUT_PREEDIT_STYLE_DEFAULT:
+ case TEXT_INPUT_PREEDIT_STYLE_UNDERLINE:
attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
break;
- case TEXT_MODEL_PREEDIT_STYLE_INCORRECT:
+ case TEXT_INPUT_PREEDIT_STYLE_INCORRECT:
attr1 = pango_attr_underline_new(PANGO_UNDERLINE_ERROR);
attr2 = pango_attr_underline_color_new(65535, 0, 0);
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);
attr2 = pango_attr_foreground_new(65535, 65535, 65535);
break;
- case TEXT_MODEL_PREEDIT_STYLE_HIGHLIGHT:
- case TEXT_MODEL_PREEDIT_STYLE_ACTIVE:
+ case TEXT_INPUT_PREEDIT_STYLE_HIGHLIGHT:
+ case TEXT_INPUT_PREEDIT_STYLE_ACTIVE:
attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
attr2 = pango_attr_weight_new(PANGO_WEIGHT_BOLD);
break;
- case TEXT_MODEL_PREEDIT_STYLE_INACTIVE:
+ case TEXT_INPUT_PREEDIT_STYLE_INACTIVE:
attr1 = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
attr2 = pango_attr_foreground_new(0.3 * 65535, 0.3 * 65535, 0.3 * 65535);
break;
}
static void
-text_model_preedit_cursor(void *data,
- struct text_model *text_model,
+text_input_preedit_cursor(void *data,
+ struct text_input *text_input,
uint32_t serial,
int32_t index)
{
}
static void
-text_model_modifiers_map(void *data,
- struct text_model *text_model,
+text_input_modifiers_map(void *data,
+ struct text_input *text_input,
struct wl_array *map)
{
struct text_entry *entry = data;
}
static void
-text_model_keysym(void *data,
- struct text_model *text_model,
+text_input_keysym(void *data,
+ struct text_input *text_input,
uint32_t serial,
uint32_t time,
uint32_t key,
}
static void
-text_model_enter(void *data,
- struct text_model *text_model,
+text_input_enter(void *data,
+ struct text_input *text_input,
struct wl_surface *surface)
{
struct text_entry *entry = data;
}
static void
-text_model_leave(void *data,
- struct text_model *text_model)
+text_input_leave(void *data,
+ struct text_input *text_input)
{
struct text_entry *entry = data;
entry->active = 0;
- text_model_hide_input_panel(text_model);
+ text_input_hide_input_panel(text_input);
widget_schedule_redraw(entry->widget);
}
static void
-text_model_input_panel_state(void *data,
- struct text_model *text_model,
+text_input_input_panel_state(void *data,
+ struct text_input *text_input,
uint32_t state)
{
}
static void
-text_model_language(void *data,
- struct text_model *text_model,
+text_input_language(void *data,
+ struct text_input *text_input,
uint32_t serial,
const char *language)
{
}
static void
-text_model_text_direction(void *data,
- struct text_model *text_model,
+text_input_text_direction(void *data,
+ struct text_input *text_input,
uint32_t serial,
uint32_t direction)
{
switch (direction) {
- case TEXT_MODEL_TEXT_DIRECTION_LTR:
+ case TEXT_INPUT_TEXT_DIRECTION_LTR:
pango_direction = PANGO_DIRECTION_LTR;
break;
- case TEXT_MODEL_TEXT_DIRECTION_RTL:
+ case TEXT_INPUT_TEXT_DIRECTION_RTL:
pango_direction = PANGO_DIRECTION_RTL;
break;
- case TEXT_MODEL_TEXT_DIRECTION_AUTO:
+ case TEXT_INPUT_TEXT_DIRECTION_AUTO:
default:
pango_direction = PANGO_DIRECTION_NEUTRAL;
}
pango_context_set_base_dir(context, pango_direction);
}
-static const struct text_model_listener text_model_listener = {
- text_model_enter,
- text_model_leave,
- text_model_modifiers_map,
- text_model_input_panel_state,
- text_model_preedit_string,
- text_model_preedit_styling,
- text_model_preedit_cursor,
- text_model_commit_string,
- text_model_cursor_position,
- text_model_delete_surrounding_text,
- text_model_keysym,
- text_model_language,
- text_model_text_direction
+static const struct text_input_listener text_input_listener = {
+ text_input_enter,
+ text_input_leave,
+ text_input_modifiers_map,
+ text_input_input_panel_state,
+ text_input_preedit_string,
+ text_input_preedit_styling,
+ text_input_preedit_cursor,
+ text_input_commit_string,
+ text_input_cursor_position,
+ text_input_delete_surrounding_text,
+ text_input_keysym,
+ text_input_language,
+ text_input_text_direction
};
static struct text_entry*
entry->active = 0;
entry->cursor = strlen(text);
entry->anchor = entry->cursor;
- entry->model = text_model_factory_create_text_model(editor->text_model_factory);
- text_model_add_listener(entry->model, &text_model_listener, entry);
+ entry->text_input = text_input_manager_create_text_input(editor->text_input_manager);
+ text_input_add_listener(entry->text_input, &text_input_listener, entry);
widget_set_redraw_handler(entry->widget, text_entry_redraw_handler);
widget_set_button_handler(entry->widget, text_entry_button_handler);
text_entry_destroy(struct text_entry *entry)
{
widget_destroy(entry->widget);
- text_model_destroy(entry->model);
+ text_input_destroy(entry->text_input);
g_clear_object(&entry->layout);
free(entry->text);
free(entry);
struct wl_surface *surface = window_get_wl_surface(entry->window);
if (entry->click_to_show && entry->active) {
- text_model_show_input_panel(entry->model);
+ text_input_show_input_panel(entry->text_input);
return;
}
if (!entry->click_to_show)
- text_model_show_input_panel(entry->model);
+ text_input_show_input_panel(entry->text_input);
entry->serial++;
- text_model_activate(entry->model,
+ text_input_activate(entry->text_input,
entry->serial,
seat,
surface);
text_entry_deactivate(struct text_entry *entry,
struct wl_seat *seat)
{
- text_model_deactivate(entry->model,
+ text_input_deactivate(entry->text_input,
seat);
}
static void
text_entry_update(struct text_entry *entry)
{
- text_model_set_content_type(entry->model,
- TEXT_MODEL_CONTENT_HINT_NONE,
+ text_input_set_content_type(entry->text_input,
+ TEXT_INPUT_CONTENT_HINT_NONE,
entry->content_purpose);
- text_model_set_surrounding_text(entry->model,
+ text_input_set_surrounding_text(entry->text_input,
entry->text,
entry->cursor,
entry->anchor);
if (entry->preferred_language)
- text_model_set_preferred_language(entry->model,
+ text_input_set_preferred_language(entry->text_input,
entry->preferred_language);
- text_model_commit_state(entry->model);
+ text_input_commit_state(entry->text_input);
}
static void
}
entry->serial++;
- text_model_reset(entry->model, entry->serial);
+ text_input_reset(entry->text_input, entry->serial);
}
static void
}
if (state == WL_POINTER_BUTTON_STATE_RELEASED)
- text_model_invoke_action(entry->model,
+ text_input_invoke_action(entry->text_input,
button,
cursor - entry->cursor);
{
struct editor *editor = data;
- if (!strcmp(interface, "text_model_factory")) {
- editor->text_model_factory =
+ if (!strcmp(interface, "text_input_manager")) {
+ editor->text_input_manager =
display_bind(display, name,
- &text_model_factory_interface, 1);
+ &text_input_manager_interface, 1);
}
}
if (preferred_language)
editor.entry->preferred_language = strdup(preferred_language);
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;
window_set_title(editor.window, "Text Editor");
12,
4,
"en",
- TEXT_MODEL_TEXT_DIRECTION_LTR
+ TEXT_INPUT_TEXT_DIRECTION_LTR
};
static const struct layout numeric_layout = {
12,
2,
"en",
- TEXT_MODEL_TEXT_DIRECTION_LTR
+ TEXT_INPUT_TEXT_DIRECTION_LTR
};
static const struct layout arabic_layout = {
13,
4,
"ar",
- TEXT_MODEL_TEXT_DIRECTION_RTL
+ TEXT_INPUT_TEXT_DIRECTION_RTL
};
static const char *style_labels[] = {
get_current_layout(struct virtual_keyboard *keyboard)
{
switch (keyboard->content_purpose) {
- case TEXT_MODEL_CONTENT_PURPOSE_DIGITS:
- case TEXT_MODEL_CONTENT_PURPOSE_NUMBER:
+ case TEXT_INPUT_CONTENT_PURPOSE_DIGITS:
+ case TEXT_INPUT_CONTENT_PURPOSE_NUMBER:
return &numeric_layout;
default:
if (keyboard->preferred_language &&
THIS SOFTWARE.
</copyright>
- <interface name="text_model" version="1">
- <description summary="text model">
- A model for text input. Adds support for text input and input methods to
- applications. A text_model object is created from a text_model_factory and
- corresponds typically to a text entry in an application. Requests are used
- to activate/deactivate the model and set information like surrounding and
- selected text or the content type. The information about entered text is
- sent to the model via 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.
+ <interface name="text_input" version="1">
+ <description summary="text input">
+ An object used for text input. Adds support for text input and input
+ methods to applications. A text-input object is created from a
+ text_input_manager and corresponds typically to a text entry in an
+ application.
+ Requests are used to activate/deactivate the text-input object and set
+ state information like surrounding and selected text or the content type.
+ The information about entered text is sent to the text-input object via
+ 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>
<request name="activate">
<description summary="request activation">
- Requests the model to be activated (typically when the text entry gets
- focus). The seat argument is a wl_seat which maintains the focus for
- this activation. The surface argument is a wl_surface assigned to the
- model and tracked for focus lost. The activated event is emitted on
- successful activation.
+ Requests the text-input object to be activated (typically when the
+ text entry gets focus).
+ The seat argument is a wl_seat which maintains the focus for this
+ activation. The surface argument is a wl_surface assigned to the
+ text-input object and tracked for focus lost. The enter event
+ is emitted on successful activation.
</description>
<arg name="serial" type="uint"/>
<arg name="seat" type="object" interface="wl_seat"/>
</request>
<request name="deactivate">
<description summary="request deactivation">
- Requests the model to be deactivated (typically when the text entry
- lost focus). The seat argument is a wl_seat which was used for
- activation.
+ Requests the text-input object to be deactivated (typically when the
+ text entry lost focus). The seat argument is a wl_seat which was used
+ for activation.
</description>
<arg name="seat" type="object" interface="wl_seat"/>
</request>
</request>
<event name="enter">
<description summary="enter event">
- Notify the model when it is activated. Typically in response to an
- activate request.
+ Notify the text-input object when it received focus. Typically in
+ response to an activate request.
</description>
<arg name="surface" type="object" interface="wl_surface"/>
</event>
<event name="leave">
<description summary="leave event">
- Notify the model when it is deactivated. Either in response to a
- deactivate request or when the assigned surface lost focus or was
+ Notify the text-input object when it lost focus. Either in response
+ to a deactivate request or when the assigned surface lost focus or was
destroyed.
</description>
</event>
</event>
</interface>
- <interface name="text_model_factory" version="1">
- <description summary="text model factory">
- A factory for text models. This object is a global singleton.
+ <interface name="text_input_manager" version="1">
+ <description summary="text input manager">
+ A factory for text-input objects. This object is a global singleton.
</description>
- <request name="create_text_model">
- <description summary="create text model">
- Creates a new text model object.
+ <request name="create_text_input">
+ <description summary="create text input">
+ Creates a new text-input object.
</description>
- <arg name="id" type="new_id" interface="text_model"/>
+ <arg name="id" type="new_id" interface="text_input"/>
</request>
</interface>
</protocol>
struct input_method_context;
struct text_backend;
-struct text_model {
+struct text_input {
struct wl_resource resource;
struct weston_compositor *ec;
uint32_t input_panel_visible;
};
-struct text_model_factory {
- struct wl_global *text_model_factory_global;
+struct text_input_manager {
+ struct wl_global *text_input_manager_global;
struct wl_listener destroy_listener;
struct weston_compositor *ec;
struct wl_listener destroy_listener;
struct weston_seat *seat;
- struct text_model *model;
+ struct text_input *model;
struct wl_list link;
struct input_method_context {
struct wl_resource resource;
- struct text_model *model;
+ struct text_input *model;
struct input_method *input_method;
struct wl_list link;
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,
uint32_t serial);
static void input_method_context_end_keyboard_grab(struct input_method_context *context);
static void input_method_init_seat(struct weston_seat *seat);
static void
-deactivate_text_model(struct text_model *text_model,
+deactivate_text_input(struct text_input *text_input,
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) {
input_method_context_end_keyboard_grab(input_method->context);
input_method_send_deactivate(input_method->input_method_binding,
input_method->model = NULL;
input_method->context = NULL;
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
-destroy_text_model(struct wl_resource *resource)
+destroy_text_input(struct wl_resource *resource)
{
- struct text_model *text_model =
- container_of(resource, struct text_model, resource);
+ struct text_input *text_input =
+ container_of(resource, struct text_input, resource);
struct input_method *input_method, *next;
- wl_list_for_each_safe(input_method, next, &text_model->input_methods, link)
- deactivate_text_model(text_model, input_method);
+ wl_list_for_each_safe(input_method, next, &text_input->input_methods, link)
+ deactivate_text_input(text_input, input_method);
- free(text_model);
+ free(text_input);
}
static void
-text_model_set_surrounding_text(struct wl_client *client,
+text_input_set_surrounding_text(struct wl_client *client,
struct wl_resource *resource,
const char *text,
uint32_t cursor,
uint32_t anchor)
{
- struct text_model *text_model = resource->data;
+ struct text_input *text_input = resource->data;
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)
continue;
input_method_context_send_surrounding_text(&input_method->context->resource,
}
static void
-text_model_activate(struct wl_client *client,
+text_input_activate(struct wl_client *client,
struct wl_resource *resource,
uint32_t serial,
struct wl_resource *seat,
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 input_method *input_method = weston_seat->input_method;
- struct text_model *old = weston_seat->input_method->model;
- struct weston_compositor *ec = text_model->ec;
+ struct text_input *old = weston_seat->input_method->model;
+ struct weston_compositor *ec = text_input->ec;
- if (old == text_model)
+ if (old == text_input)
return;
if (old) {
- deactivate_text_model(old,
+ deactivate_text_input(old,
weston_seat->input_method);
}
- input_method->model = text_model;
- wl_list_insert(&text_model->input_methods, &input_method->link);
+ input_method->model = text_input;
+ wl_list_insert(&text_input->input_methods, &input_method->link);
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);
- text_model_send_enter(&text_model->resource, &text_model->surface->resource);
+ text_input_send_enter(&text_input->resource, &text_input->surface->resource);
}
static void
-text_model_deactivate(struct wl_client *client,
+text_input_deactivate(struct wl_client *client,
struct wl_resource *resource,
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;
- deactivate_text_model(text_model,
+ deactivate_text_input(text_input,
weston_seat->input_method);
}
static void
-text_model_reset(struct wl_client *client,
+text_input_reset(struct wl_client *client,
struct wl_resource *resource,
uint32_t serial)
{
- struct text_model *text_model = resource->data;
+ struct text_input *text_input = resource->data;
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)
continue;
input_method_context_send_reset(&input_method->context->resource, serial);
}
static void
-text_model_set_cursor_rectangle(struct wl_client *client,
+text_input_set_cursor_rectangle(struct wl_client *client,
struct wl_resource *resource,
int32_t x,
int32_t y,
}
static void
-text_model_set_content_type(struct wl_client *client,
+text_input_set_content_type(struct wl_client *client,
struct wl_resource *resource,
uint32_t hint,
uint32_t purpose)
{
- struct text_model *text_model = resource->data;
+ struct text_input *text_input = resource->data;
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)
continue;
input_method_context_send_content_type(&input_method->context->resource, hint, purpose);
}
static void
-text_model_invoke_action(struct wl_client *client,
+text_input_invoke_action(struct wl_client *client,
struct wl_resource *resource,
uint32_t button,
uint32_t index)
{
- struct text_model *text_model = resource->data;
+ struct text_input *text_input = resource->data;
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)
continue;
input_method_context_send_invoke_action(&input_method->context->resource, button, index);
}
static void
-text_model_commit_state(struct wl_client *client,
+text_input_commit_state(struct wl_client *client,
struct wl_resource *resource)
{
- struct text_model *text_model = resource->data;
+ struct text_input *text_input = resource->data;
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)
continue;
input_method_context_send_commit(&input_method->context->resource);
}
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 text_model *text_model = resource->data;
- struct weston_compositor *ec = text_model->ec;
+ struct text_input *text_input = resource->data;
+ 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);
}
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 text_model *text_model = resource->data;
- struct weston_compositor *ec = text_model->ec;
+ struct text_input *text_input = resource->data;
+ 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);
}
static void
-text_model_set_preferred_language(struct wl_client *client,
+text_input_set_preferred_language(struct wl_client *client,
struct wl_resource *resource,
const char *language)
{
- struct text_model *text_model = resource->data;
+ struct text_input *text_input = resource->data;
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)
continue;
input_method_context_send_preferred_language(&input_method->context->resource,
}
}
-static const struct text_model_interface text_model_implementation = {
- text_model_activate,
- text_model_deactivate,
- text_model_show_input_panel,
- text_model_hide_input_panel,
- text_model_reset,
- text_model_set_surrounding_text,
- text_model_set_content_type,
- text_model_set_cursor_rectangle,
- text_model_set_preferred_language,
- text_model_commit_state,
- text_model_invoke_action
+static const struct text_input_interface text_input_implementation = {
+ text_input_activate,
+ text_input_deactivate,
+ text_input_show_input_panel,
+ text_input_hide_input_panel,
+ text_input_reset,
+ text_input_set_surrounding_text,
+ text_input_set_content_type,
+ text_input_set_cursor_rectangle,
+ text_input_set_preferred_language,
+ text_input_commit_state,
+ 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,
uint32_t id)
{
- struct text_model_factory *text_model_factory = resource->data;
- struct text_model *text_model;
+ struct text_input_manager *text_input_manager = resource->data;
+ 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_model->resource.object.interface = &text_model_interface;
- text_model->resource.object.implementation =
- (void (**)(void)) &text_model_implementation;
+ text_input->resource.object.id = id;
+ text_input->resource.object.interface = &text_input_interface;
+ text_input->resource.object.implementation =
+ (void (**)(void)) &text_input_implementation;
- text_model->resource.data = text_model;
- text_model->resource.destroy = destroy_text_model;
+ text_input->resource.data = text_input;
+ 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 = {
- text_model_factory_create_text_model
+static const struct text_input_manager_interface text_input_manager_implementation = {
+ text_input_manager_create_text_input
};
static void
-bind_text_model_factory(struct wl_client *client,
+bind_text_input_manager(struct wl_client *client,
void *data,
uint32_t version,
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 events have to be sent, so we don't need the return value. */
- wl_client_add_object(client, &text_model_factory_interface,
- &text_model_factory_implementation,
- id, text_model_factory);
+ wl_client_add_object(client, &text_input_manager_interface,
+ &text_input_manager_implementation,
+ id, text_input_manager);
}
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 =
- container_of(listener, struct text_model_factory, destroy_listener);
+ struct text_input_manager *text_input_manager =
+ container_of(listener, struct text_input_manager, destroy_listener);
- wl_display_remove_global(text_model_factory->ec->wl_display,
- text_model_factory->text_model_factory_global);
+ wl_display_remove_global(text_input_manager->ec->wl_display,
+ text_input_manager->text_input_manager_global);
- free(text_model_factory);
+ free(text_input_manager);
}
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,
- &text_model_factory_interface,
- text_model_factory, bind_text_model_factory);
+ &text_input_manager_interface,
+ text_input_manager, bind_text_input_manager);
- text_model_factory->destroy_listener.notify = text_model_factory_notifier_destroy;
- wl_signal_add(&ec->destroy_signal, &text_model_factory->destroy_listener);
+ text_input_manager->destroy_listener.notify = text_input_manager_notifier_destroy;
+ wl_signal_add(&ec->destroy_signal, &text_input_manager->destroy_listener);
}
static void
{
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
{
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
{
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
{
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
{
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
{
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
{
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
{
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);
}
{
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
{
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);
}
}
static void
-input_method_context_create(struct text_model *model,
+input_method_context_create(struct text_input *model,
struct input_method *input_method,
uint32_t serial)
{
container_of(listener, struct input_method, destroy_listener);
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,
input_method->input_method_global);
return;
if (!surface || input_method->model->surface != surface)
- deactivate_text_model(input_method->model,
+ deactivate_text_input(input_method->model,
input_method);
}
text_backend_configuration(text_backend);
- text_model_factory_create(ec);
+ text_input_manager_create(ec);
return 0;
}
#include "weston-test-client-helper.h"
#include "../clients/text-client-protocol.h"
-struct text_model_state {
+struct text_input_state {
int activated;
int deactivated;
};
static void
-text_model_commit_string(void *data,
- struct text_model *text_model,
+text_input_commit_string(void *data,
+ struct text_input *text_input,
uint32_t serial,
const char *text)
{
}
static void
-text_model_preedit_string(void *data,
- struct text_model *text_model,
+text_input_preedit_string(void *data,
+ struct text_input *text_input,
uint32_t serial,
const char *text,
const char *commit)
}
static void
-text_model_delete_surrounding_text(void *data,
- struct text_model *text_model,
+text_input_delete_surrounding_text(void *data,
+ struct text_input *text_input,
uint32_t serial,
int32_t index,
uint32_t length)
}
static void
-text_model_cursor_position(void *data,
- struct text_model *text_model,
+text_input_cursor_position(void *data,
+ struct text_input *text_input,
uint32_t serial,
int32_t index,
int32_t anchor)
}
static void
-text_model_preedit_styling(void *data,
- struct text_model *text_model,
+text_input_preedit_styling(void *data,
+ struct text_input *text_input,
uint32_t serial,
uint32_t index,
uint32_t length,
}
static void
-text_model_preedit_cursor(void *data,
- struct text_model *text_model,
+text_input_preedit_cursor(void *data,
+ struct text_input *text_input,
uint32_t serial,
int32_t index)
{
}
static void
-text_model_modifiers_map(void *data,
- struct text_model *text_model,
+text_input_modifiers_map(void *data,
+ struct text_input *text_input,
struct wl_array *map)
{
}
static void
-text_model_keysym(void *data,
- struct text_model *text_model,
+text_input_keysym(void *data,
+ struct text_input *text_input,
uint32_t serial,
uint32_t time,
uint32_t sym,
}
static void
-text_model_enter(void *data,
- struct text_model *text_model,
+text_input_enter(void *data,
+ struct text_input *text_input,
struct wl_surface *surface)
{
- struct text_model_state *state = data;
+ struct text_input_state *state = data;
fprintf(stderr, "%s\n", __FUNCTION__);
}
static void
-text_model_leave(void *data,
- struct text_model *text_model)
+text_input_leave(void *data,
+ struct text_input *text_input)
{
- struct text_model_state *state = data;
+ struct text_input_state *state = data;
state->deactivated += 1;
}
static void
-text_model_input_panel_state(void *data,
- struct text_model *text_model,
+text_input_input_panel_state(void *data,
+ struct text_input *text_input,
uint32_t state)
{
}
static void
-text_model_language(void *data,
- struct text_model *text_model,
+text_input_language(void *data,
+ struct text_input *text_input,
uint32_t serial,
const char *language)
{
}
static void
-text_model_text_direction(void *data,
- struct text_model *text_model,
+text_input_text_direction(void *data,
+ struct text_input *text_input,
uint32_t serial,
uint32_t direction)
{
}
-static const struct text_model_listener text_model_listener = {
- text_model_enter,
- text_model_leave,
- text_model_modifiers_map,
- text_model_input_panel_state,
- text_model_preedit_string,
- text_model_preedit_styling,
- text_model_preedit_cursor,
- text_model_commit_string,
- text_model_cursor_position,
- text_model_delete_surrounding_text,
- text_model_keysym,
- text_model_language,
- text_model_text_direction
+static const struct text_input_listener text_input_listener = {
+ text_input_enter,
+ text_input_leave,
+ text_input_modifiers_map,
+ text_input_input_panel_state,
+ text_input_preedit_string,
+ text_input_preedit_styling,
+ text_input_preedit_cursor,
+ text_input_commit_string,
+ text_input_cursor_position,
+ text_input_delete_surrounding_text,
+ text_input_keysym,
+ text_input_language,
+ text_input_text_direction
};
TEST(text_test)
{
struct client *client;
struct global *global;
- struct text_model_factory *factory;
- struct text_model *text_model;
- struct text_model_state state;
+ struct text_input_manager *factory;
+ struct text_input *text_input;
+ struct text_input_state state;
client = client_create(100, 100, 100, 100);
assert(client);
factory = NULL;
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,
global->name,
- &text_model_factory_interface, 1);
+ &text_input_manager_interface, 1);
}
assert(factory);
memset(&state, 0, sizeof state);
- text_model = text_model_factory_create_text_model(factory);
- text_model_add_listener(text_model, &text_model_listener, &state);
+ text_input = text_input_manager_create_text_input(factory);
+ text_input_add_listener(text_input, &text_input_listener, &state);
/* Make sure our test surface has keyboard focus. */
wl_test_activate_surface(client->test->wl_test,
assert(client->input->keyboard->focus == client->surface);
/* 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_roundtrip(client);
assert(state.activated == 1 && state.deactivated == 0);
/* 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);
assert(state.activated == 1 && state.deactivated == 1);
/* 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_roundtrip(client);
assert(state.activated == 2 && state.deactivated == 1);