uint32_t button,
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_set_preedit(struct text_entry *entry,
+ const char *preedit_text,
+ int preedit_cursor);
static void
text_model_commit_string(void *data,
const char *text,
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
struct input_method *input_method;
struct input_method_context *context;
struct display *display;
+ char *preedit_string;
};
enum key_type {
switch (key->key_type) {
case keytype_default:
- input_method_context_commit_string(keyboard->keyboard->context,
- label, -1);
+ keyboard->keyboard->preedit_string = strcat(keyboard->keyboard->preedit_string,
+ label);
+ input_method_context_preedit_string(keyboard->keyboard->context,
+ keyboard->keyboard->preedit_string,
+ strlen(keyboard->keyboard->preedit_string));
break;
case keytype_backspace:
break;
case keytype_enter:
break;
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,
- " ", -1);
+ keyboard->keyboard->preedit_string,
+ strlen(keyboard->keyboard->preedit_string));
+ free(keyboard->keyboard->preedit_string);
+ keyboard->keyboard->preedit_string = strdup("");
break;
case keytype_switch:
if (keyboard->state == keyboardstate_default)
if (keyboard->context)
input_method_context_destroy(keyboard->context);
+ if (keyboard->preedit_string)
+ free(keyboard->preedit_string);
+
+ keyboard->preedit_string = strdup("");
+
keyboard->context = context;
input_method_context_add_listener(context,
&input_method_context_listener,
}
virtual_keyboard.context = NULL;
+ virtual_keyboard.preedit_string = NULL;
wl_display_add_global_listener(display_get_display(virtual_keyboard.display),
global_handler, &virtual_keyboard);
<arg name="text" type="string"/>
<arg name="index" type="uint"/>
</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">
<description summary="surrounding text event">
The plain surrounding text around the input position. Cursor is the
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 = {
input_method_context_destroy,
- input_method_context_commit_string
+ input_method_context_commit_string,
+ input_method_context_preedit_string,
};
static void