[PATCH v2 3/3] keyboard: add support for invoke_action

Jan Arne Petersen jpetersen at openismus.com
Thu Dec 6 06:35:47 PST 2012


From: Jan Arne Petersen <jpetersen at openismus.com>

Set the pre-edit cursor on the clicked index on invoke_action.

Signed-off-by: Jan Arne Petersen <jpetersen at openismus.com>
---
 clients/keyboard.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/clients/keyboard.c b/clients/keyboard.c
index 1c7ea1a..ab95e93 100644
--- a/clients/keyboard.c
+++ b/clients/keyboard.c
@@ -335,17 +335,22 @@ virtual_keyboard_commit_preedit(struct virtual_keyboard *keyboard)
 }
 
 static void
-virtual_keyboard_send_preedit(struct virtual_keyboard *keyboard)
+virtual_keyboard_send_preedit(struct virtual_keyboard *keyboard,
+			      int32_t cursor)
 {
+	uint32_t index = strlen(keyboard->preedit_string);
+
 	if (keyboard->preedit_style)
 		input_method_context_preedit_styling(keyboard->context,
 						     keyboard->serial,
 						     0,
 						     strlen(keyboard->preedit_string),
 						     keyboard->preedit_style);
+	if (cursor > 0)
+		index = cursor;
 	input_method_context_preedit_cursor(keyboard->context,
 					    keyboard->serial,
-					    strlen(keyboard->preedit_string));
+					    index);
 	input_method_context_preedit_string(keyboard->context,
 					    keyboard->serial,
 					    keyboard->preedit_string,
@@ -366,7 +371,7 @@ keyboard_handle_key(struct keyboard *keyboard, uint32_t time, const struct key *
 
 			keyboard->keyboard->preedit_string = strcat(keyboard->keyboard->preedit_string,
 								    label);
-			virtual_keyboard_send_preedit(keyboard->keyboard);
+			virtual_keyboard_send_preedit(keyboard->keyboard, -1);
 			break;
 		case keytype_backspace:
 			if (state != WL_POINTER_BUTTON_STATE_PRESSED)
@@ -378,7 +383,7 @@ keyboard_handle_key(struct keyboard *keyboard, uint32_t time, const struct key *
 									     -1, 1);
 			} else {
 				keyboard->keyboard->preedit_string[strlen(keyboard->keyboard->preedit_string) - 1] = '\0';
-				virtual_keyboard_send_preedit(keyboard->keyboard);
+				virtual_keyboard_send_preedit(keyboard->keyboard, -1);
 			}
 			break;
 		case keytype_enter:
@@ -446,7 +451,7 @@ keyboard_handle_key(struct keyboard *keyboard, uint32_t time, const struct key *
 			if (state != WL_POINTER_BUTTON_STATE_PRESSED)
 				break;
 			keyboard->keyboard->preedit_style = (keyboard->keyboard->preedit_style + 1) % 8; /* TODO */
-			virtual_keyboard_send_preedit(keyboard->keyboard);
+			virtual_keyboard_send_preedit(keyboard->keyboard, -1);
 			break;
 	}
 }
@@ -546,10 +551,25 @@ input_method_context_content_type(void *data,
 	keyboard->content_purpose = purpose;
 }
 
+static void
+input_method_context_invoke_action(void *data,
+				   struct input_method_context *context,
+				   uint32_t button,
+				   uint32_t index)
+{
+	struct virtual_keyboard *keyboard = data;
+
+	if (button != BTN_LEFT)
+		return;
+
+	virtual_keyboard_send_preedit(keyboard, index);
+}
+
 static const struct input_method_context_listener input_method_context_listener = {
 	input_method_context_surrounding_text,
 	input_method_context_reset,
-	input_method_context_content_type
+	input_method_context_content_type,
+	input_method_context_invoke_action
 };
 
 static void
-- 
1.7.11.7



More information about the wayland-devel mailing list