text: Fix set_surrounding_text request
Add cursor and anchor positions as arguments to the set_surrounding_text request. The cursor and anchor positions are relative to the surrounded text, so it does not make sense to have that separate. Remove the separate set_cursor_index and set_selected_text requests. Also update the corresponding event in input-method-context and add support for it in the weston example keyboard. Signed-off-by: Jan Arne Petersen <jpetersen@openismus.com>
This commit is contained in:
committed by
Kristian Høgsberg
parent
c1fbcb7c38
commit
cb08f4d844
@@ -433,6 +433,11 @@ text_entry_update_layout(struct text_entry *entry)
|
|||||||
free(text);
|
free(text);
|
||||||
|
|
||||||
widget_schedule_redraw(entry->widget);
|
widget_schedule_redraw(entry->widget);
|
||||||
|
|
||||||
|
text_model_set_surrounding_text(entry->model,
|
||||||
|
entry->text,
|
||||||
|
entry->cursor,
|
||||||
|
entry->anchor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@@ -136,6 +136,20 @@ button_handler(struct widget *widget,
|
|||||||
widget_schedule_redraw(widget);
|
widget_schedule_redraw(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
input_method_context_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 const struct input_method_context_listener input_method_context_listener = {
|
||||||
|
input_method_context_surrounding_text,
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
input_method_activate(void *data,
|
input_method_activate(void *data,
|
||||||
struct input_method *input_method,
|
struct input_method *input_method,
|
||||||
@@ -147,6 +161,9 @@ input_method_activate(void *data,
|
|||||||
input_method_context_destroy(keyboard->context);
|
input_method_context_destroy(keyboard->context);
|
||||||
|
|
||||||
keyboard->context = context;
|
keyboard->context = context;
|
||||||
|
input_method_context_add_listener(context,
|
||||||
|
&input_method_context_listener,
|
||||||
|
keyboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
+15
-9
@@ -11,10 +11,15 @@
|
|||||||
and compose text out of them.
|
and compose text out of them.
|
||||||
</description>
|
</description>
|
||||||
<request name="set_surrounding_text">
|
<request name="set_surrounding_text">
|
||||||
|
<description summary="sets the surrounding text">
|
||||||
|
Sets the plain surrounding text around the input position. Cursor is the
|
||||||
|
position within the surrounding text. Anchor is the position of the
|
||||||
|
selection anchor within the surrounding text. If there is no selected
|
||||||
|
text anchor is the same as cursor.
|
||||||
|
</description>
|
||||||
<arg name="text" type="string"/>
|
<arg name="text" type="string"/>
|
||||||
</request>
|
<arg name="cursor" type="uint"/>
|
||||||
<request name="set_cursor_index">
|
<arg name="anchor" type="uint"/>
|
||||||
<arg name="index" type="uint"/>
|
|
||||||
</request>
|
</request>
|
||||||
<request name="activate">
|
<request name="activate">
|
||||||
<description summary="request activation">
|
<description summary="request activation">
|
||||||
@@ -35,10 +40,6 @@
|
|||||||
</description>
|
</description>
|
||||||
<arg name="seat" type="object" interface="wl_seat"/>
|
<arg name="seat" type="object" interface="wl_seat"/>
|
||||||
</request>
|
</request>
|
||||||
<request name="set_selected_text">
|
|
||||||
<arg name="text" type="string"/>
|
|
||||||
<arg name="index" type="int"/>
|
|
||||||
</request>
|
|
||||||
<request name="set_micro_focus">
|
<request name="set_micro_focus">
|
||||||
<arg name="x" type="int"/>
|
<arg name="x" type="int"/>
|
||||||
<arg name="y" type="int"/>
|
<arg name="y" type="int"/>
|
||||||
@@ -104,11 +105,16 @@
|
|||||||
<arg name="text" type="string"/>
|
<arg name="text" type="string"/>
|
||||||
<arg name="index" type="uint"/>
|
<arg name="index" type="uint"/>
|
||||||
</request>
|
</request>
|
||||||
<event name="set_surrounding_text">
|
<event name="surrounding_text">
|
||||||
<description summary="surrounding text event">
|
<description summary="surrounding text event">
|
||||||
The surrounding text from the model.
|
The plain surrounding text around the input position. Cursor is the
|
||||||
|
position within the surrounding text. Anchor is the position of the
|
||||||
|
selection anchor within the surrounding text. If there is no selected
|
||||||
|
text anchor is the same as cursor.
|
||||||
</description>
|
</description>
|
||||||
<arg name="text" type="string"/>
|
<arg name="text" type="string"/>
|
||||||
|
<arg name="cursor" type="uint"/>
|
||||||
|
<arg name="anchor" type="uint"/>
|
||||||
</event>
|
</event>
|
||||||
</interface>
|
</interface>
|
||||||
|
|
||||||
|
|||||||
+7
-19
@@ -109,7 +109,9 @@ destroy_text_model(struct wl_resource *resource)
|
|||||||
static void
|
static void
|
||||||
text_model_set_surrounding_text(struct wl_client *client,
|
text_model_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 anchor)
|
||||||
{
|
{
|
||||||
struct text_model *text_model = resource->data;
|
struct text_model *text_model = resource->data;
|
||||||
struct input_method *input_method, *next;
|
struct input_method *input_method, *next;
|
||||||
@@ -117,17 +119,13 @@ text_model_set_surrounding_text(struct wl_client *client,
|
|||||||
wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) {
|
wl_list_for_each_safe(input_method, next, &text_model->input_methods, link) {
|
||||||
if (!input_method->context)
|
if (!input_method->context)
|
||||||
continue;
|
continue;
|
||||||
input_method_context_send_set_surrounding_text(&input_method->context->resource, text);
|
input_method_context_send_surrounding_text(&input_method->context->resource,
|
||||||
|
text,
|
||||||
|
cursor,
|
||||||
|
anchor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
text_model_set_cursor_index(struct wl_client *client,
|
|
||||||
struct wl_resource *resource,
|
|
||||||
uint32_t index)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
text_model_activate(struct wl_client *client,
|
text_model_activate(struct wl_client *client,
|
||||||
struct wl_resource *resource,
|
struct wl_resource *resource,
|
||||||
@@ -173,14 +171,6 @@ text_model_deactivate(struct wl_client *client,
|
|||||||
weston_seat->input_method);
|
weston_seat->input_method);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
text_model_set_selected_text(struct wl_client *client,
|
|
||||||
struct wl_resource *resource,
|
|
||||||
const char *text,
|
|
||||||
int32_t index)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
text_model_set_micro_focus(struct wl_client *client,
|
text_model_set_micro_focus(struct wl_client *client,
|
||||||
struct wl_resource *resource,
|
struct wl_resource *resource,
|
||||||
@@ -205,10 +195,8 @@ text_model_set_content_type(struct wl_client *client,
|
|||||||
|
|
||||||
static const struct text_model_interface text_model_implementation = {
|
static const struct text_model_interface text_model_implementation = {
|
||||||
text_model_set_surrounding_text,
|
text_model_set_surrounding_text,
|
||||||
text_model_set_cursor_index,
|
|
||||||
text_model_activate,
|
text_model_activate,
|
||||||
text_model_deactivate,
|
text_model_deactivate,
|
||||||
text_model_set_selected_text,
|
|
||||||
text_model_set_micro_focus,
|
text_model_set_micro_focus,
|
||||||
text_model_set_preedit,
|
text_model_set_preedit,
|
||||||
text_model_set_content_type
|
text_model_set_content_type
|
||||||
|
|||||||
Reference in New Issue
Block a user