text: Add support for pre-edit string
Add support of preedit-string to the example editor client. Also add a preedit_string request to the input_method_context interface and use that in the example weston keyboard to first create a pre-edit string when entering keys and commit it on space. Signed-off-by: Jan Arne Petersen <jpetersen@openismus.com>
This commit is contained in:
committed by
Kristian Høgsberg
parent
892f1c3975
commit
43f4aa8cab
@@ -209,6 +209,9 @@ static void text_entry_button_handler(struct widget *widget,
|
|||||||
uint32_t button,
|
uint32_t button,
|
||||||
enum wl_pointer_button_state state, void *data);
|
enum wl_pointer_button_state state, void *data);
|
||||||
static void text_entry_insert_at_cursor(struct text_entry *entry, const char *text);
|
static void text_entry_insert_at_cursor(struct text_entry *entry, const char *text);
|
||||||
|
static void text_entry_set_preedit(struct text_entry *entry,
|
||||||
|
const char *preedit_text,
|
||||||
|
int preedit_cursor);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
text_model_commit_string(void *data,
|
text_model_commit_string(void *data,
|
||||||
@@ -234,6 +237,16 @@ text_model_preedit_string(void *data,
|
|||||||
const char *text,
|
const char *text,
|
||||||
uint32_t index)
|
uint32_t index)
|
||||||
{
|
{
|
||||||
|
struct text_entry *entry = data;
|
||||||
|
|
||||||
|
if (index > strlen(text)) {
|
||||||
|
fprintf(stderr, "Invalid cursor index %d\n", index);
|
||||||
|
index = strlen(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
text_entry_set_preedit(entry, text, index);
|
||||||
|
|
||||||
|
widget_schedule_redraw(entry->widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
+21
-3
@@ -37,6 +37,7 @@ struct virtual_keyboard {
|
|||||||
struct input_method *input_method;
|
struct input_method *input_method;
|
||||||
struct input_method_context *context;
|
struct input_method_context *context;
|
||||||
struct display *display;
|
struct display *display;
|
||||||
|
char *preedit_string;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum key_type {
|
enum key_type {
|
||||||
@@ -214,16 +215,27 @@ keyboard_handle_key(struct keyboard *keyboard, const struct key *key)
|
|||||||
|
|
||||||
switch (key->key_type) {
|
switch (key->key_type) {
|
||||||
case keytype_default:
|
case keytype_default:
|
||||||
input_method_context_commit_string(keyboard->keyboard->context,
|
keyboard->keyboard->preedit_string = strcat(keyboard->keyboard->preedit_string,
|
||||||
label, -1);
|
label);
|
||||||
|
input_method_context_preedit_string(keyboard->keyboard->context,
|
||||||
|
keyboard->keyboard->preedit_string,
|
||||||
|
strlen(keyboard->keyboard->preedit_string));
|
||||||
break;
|
break;
|
||||||
case keytype_backspace:
|
case keytype_backspace:
|
||||||
break;
|
break;
|
||||||
case keytype_enter:
|
case keytype_enter:
|
||||||
break;
|
break;
|
||||||
case keytype_space:
|
case keytype_space:
|
||||||
|
keyboard->keyboard->preedit_string = strcat(keyboard->keyboard->preedit_string,
|
||||||
|
" ");
|
||||||
|
input_method_context_preedit_string(keyboard->keyboard->context,
|
||||||
|
"",
|
||||||
|
0);
|
||||||
input_method_context_commit_string(keyboard->keyboard->context,
|
input_method_context_commit_string(keyboard->keyboard->context,
|
||||||
" ", -1);
|
keyboard->keyboard->preedit_string,
|
||||||
|
strlen(keyboard->keyboard->preedit_string));
|
||||||
|
free(keyboard->keyboard->preedit_string);
|
||||||
|
keyboard->keyboard->preedit_string = strdup("");
|
||||||
break;
|
break;
|
||||||
case keytype_switch:
|
case keytype_switch:
|
||||||
if (keyboard->state == keyboardstate_default)
|
if (keyboard->state == keyboardstate_default)
|
||||||
@@ -297,6 +309,11 @@ input_method_activate(void *data,
|
|||||||
if (keyboard->context)
|
if (keyboard->context)
|
||||||
input_method_context_destroy(keyboard->context);
|
input_method_context_destroy(keyboard->context);
|
||||||
|
|
||||||
|
if (keyboard->preedit_string)
|
||||||
|
free(keyboard->preedit_string);
|
||||||
|
|
||||||
|
keyboard->preedit_string = strdup("");
|
||||||
|
|
||||||
keyboard->context = context;
|
keyboard->context = context;
|
||||||
input_method_context_add_listener(context,
|
input_method_context_add_listener(context,
|
||||||
&input_method_context_listener,
|
&input_method_context_listener,
|
||||||
@@ -390,6 +407,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual_keyboard.context = NULL;
|
virtual_keyboard.context = NULL;
|
||||||
|
virtual_keyboard.preedit_string = NULL;
|
||||||
|
|
||||||
wl_display_add_global_listener(display_get_display(virtual_keyboard.display),
|
wl_display_add_global_listener(display_get_display(virtual_keyboard.display),
|
||||||
global_handler, &virtual_keyboard);
|
global_handler, &virtual_keyboard);
|
||||||
|
|||||||
@@ -42,6 +42,13 @@
|
|||||||
<arg name="text" type="string"/>
|
<arg name="text" type="string"/>
|
||||||
<arg name="index" type="uint"/>
|
<arg name="index" type="uint"/>
|
||||||
</request>
|
</request>
|
||||||
|
<request name="preedit_string">
|
||||||
|
<description summary="pre-edit string">
|
||||||
|
Send the pre-edit string text to the applications text model.
|
||||||
|
</description>
|
||||||
|
<arg name="text" type="string"/>
|
||||||
|
<arg name="index" type="uint"/>
|
||||||
|
</request>
|
||||||
<event name="surrounding_text">
|
<event name="surrounding_text">
|
||||||
<description summary="surrounding text event">
|
<description summary="surrounding text event">
|
||||||
The plain surrounding text around the input position. Cursor is the
|
The plain surrounding text around the input position. Cursor is the
|
||||||
|
|||||||
+13
-1
@@ -294,9 +294,21 @@ input_method_context_commit_string(struct wl_client *client,
|
|||||||
text_model_send_commit_string(&context->model->resource, text, index);
|
text_model_send_commit_string(&context->model->resource, text, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
input_method_context_preedit_string(struct wl_client *client,
|
||||||
|
struct wl_resource *resource,
|
||||||
|
const char *text,
|
||||||
|
uint32_t index)
|
||||||
|
{
|
||||||
|
struct input_method_context *context = resource->data;
|
||||||
|
|
||||||
|
text_model_send_preedit_string(&context->model->resource, text, index);
|
||||||
|
}
|
||||||
|
|
||||||
static const struct input_method_context_interface input_method_context_implementation = {
|
static const struct input_method_context_interface input_method_context_implementation = {
|
||||||
input_method_context_destroy,
|
input_method_context_destroy,
|
||||||
input_method_context_commit_string
|
input_method_context_commit_string,
|
||||||
|
input_method_context_preedit_string,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user