<div dir="ltr"><br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 8, 2016 at 5:40 PM Arnaud Vrac <<a href="mailto:avrac@freebox.fr">avrac@freebox.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The input method protocol should be updated next:<br>
* we need the input method panel geometry to be able to fill the<br>
* input_panel_state event parameters.<br>
<br>
* reason in update_state should be forwarded to the input method.<br>
<br>
* the input method delete_surrounding_text request arguments should be<br>
updated to match the new text input updated semantic.<br></blockquote><div><br></div><div>Yes, it would be still good to fix bugs like <a href="https://bugs.freedesktop.org/show_bug.cgi?id=84034">https://bugs.freedesktop.org/show_bug.cgi?id=84034</a> and also the construction of input_method and input_method_context objects. I would also not mind to keep this protocol weston only for now.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
Makefile.am | 4 +-<br>
src/text-backend.c | 185 +++++++++++++++++++++++++++--------------------------<br>
2 files changed, 98 insertions(+), 91 deletions(-)<br>
<br>
diff --git a/Makefile.am b/Makefile.am<br>
index d1d2178..798ed93 100644<br>
--- a/Makefile.am<br>
+++ b/Makefile.am<br>
@@ -124,8 +124,8 @@ nodist_libweston_la_SOURCES = \<br>
protocol/weston-screenshooter-server-protocol.h \<br>
protocol/text-cursor-position-protocol.c \<br>
protocol/text-cursor-position-server-protocol.h \<br>
- protocol/text-input-unstable-v1-protocol.c \<br>
- protocol/text-input-unstable-v1-server-protocol.h \<br>
+ protocol/text-input-unstable-v2-protocol.c \<br>
+ protocol/text-input-unstable-v2-server-protocol.h \<br>
protocol/input-method-unstable-v1-protocol.c \<br>
protocol/input-method-unstable-v1-server-protocol.h \<br>
protocol/presentation-time-protocol.c \<br>
diff --git a/src/text-backend.c b/src/text-backend.c<br>
index 3b6aa91..1517611 100644<br>
--- a/src/text-backend.c<br>
+++ b/src/text-backend.c<br>
@@ -34,7 +34,7 @@<br>
<br>
#include "compositor.h"<br>
#include "weston.h"<br>
-#include "text-input-unstable-v1-server-protocol.h"<br>
+#include "text-input-unstable-v2-server-protocol.h"<br>
#include "input-method-unstable-v1-server-protocol.h"<br>
#include "shared/helpers.h"<br>
<br>
@@ -47,6 +47,7 @@ struct text_input {<br>
struct wl_resource *resource;<br>
<br>
struct weston_compositor *ec;<br>
+ struct weston_seat *seat;<br>
<br>
struct wl_list input_methods;<br>
<br>
@@ -127,7 +128,10 @@ text_input_set_input_panel_visible(struct text_input *text_input, bool visible)<br>
return;<br>
<br>
text_input->input_panel_visible = visible;<br>
- zwp_text_input_v1_send_input_panel_state(text_input->resource, visible);<br>
+ zwp_text_input_v2_send_input_panel_state(text_input->resource, visible ?<br>
+ ZWP_TEXT_INPUT_V2_INPUT_PANEL_VISIBILITY_VISIBLE :<br>
+ ZWP_TEXT_INPUT_V2_INPUT_PANEL_VISIBILITY_HIDDEN,<br>
+ 0, 0, 0, 0);<br>
}<br>
<br>
static void<br>
@@ -135,6 +139,7 @@ deactivate_input_method(struct input_method *input_method)<br>
{<br>
struct text_input *text_input = input_method->input;<br>
struct weston_compositor *ec = text_input->ec;<br>
+ uint32_t serial;<br>
<br>
if (input_method->context && input_method->input_method_binding) {<br>
input_method_context_end_keyboard_grab(input_method->context);<br>
@@ -153,7 +158,14 @@ deactivate_input_method(struct input_method *input_method)<br>
text_input_set_input_panel_visible(text_input, false);<br>
text_input->manager->current_panel = NULL;<br>
}<br>
- zwp_text_input_v1_send_leave(text_input->resource);<br>
+<br>
+ if (text_input->surface) {<br>
+ serial = wl_display_next_serial(ec->wl_display);<br>
+ zwp_text_input_v2_send_leave(text_input->resource, serial,<br>
+ text_input->surface->resource);<br>
+ }<br>
+<br>
+ text_input->surface = NULL;<br>
}<br>
<br>
static void<br>
@@ -173,8 +185,8 @@ static void<br>
text_input_set_surrounding_text(struct wl_client *client,<br>
struct wl_resource *resource,<br>
const char *text,<br>
- uint32_t cursor,<br>
- uint32_t anchor)<br>
+ int32_t cursor,<br>
+ int32_t anchor)<br>
{<br>
struct text_input *text_input = wl_resource_get_user_data(resource);<br>
struct input_method *input_method, *next;<br>
@@ -189,16 +201,22 @@ text_input_set_surrounding_text(struct wl_client *client,<br>
}<br>
<br>
static void<br>
-text_input_activate(struct wl_client *client,<br>
- struct wl_resource *resource,<br>
- struct wl_resource *seat,<br>
- struct wl_resource *surface)<br>
+text_input_destroy(struct wl_client *client, struct wl_resource *resource)<br>
+{<br>
+ wl_resource_destroy(resource);<br>
+}<br>
+<br>
+static void<br>
+text_input_enable(struct wl_client *client,<br>
+ struct wl_resource *resource,<br>
+ struct wl_resource *surface)<br>
{<br>
struct text_input *text_input = wl_resource_get_user_data(resource);<br>
- struct weston_seat *weston_seat = wl_resource_get_user_data(seat);<br>
- struct input_method *input_method = weston_seat->input_method;<br>
+ struct weston_seat *seat = text_input->seat;<br>
+ struct input_method *input_method = seat->input_method;<br>
struct weston_compositor *ec = text_input->ec;<br>
struct text_input *current;<br>
+ uint32_t serial;<br>
<br>
if (input_method->input == text_input)<br>
return;<br>
@@ -208,7 +226,7 @@ text_input_activate(struct wl_client *client,<br>
<br>
input_method->input = text_input;<br>
wl_list_insert(&text_input->input_methods, &input_method->link);<br>
- input_method_init_seat(weston_seat);<br>
+ input_method_init_seat(seat);<br>
<br>
text_input->surface = wl_resource_get_user_data(surface);<br>
<br>
@@ -230,35 +248,21 @@ text_input_activate(struct wl_client *client,<br>
text_input->manager->current_panel = text_input;<br>
}<br>
<br>
- zwp_text_input_v1_send_enter(text_input->resource,<br>
+ serial = wl_display_next_serial(ec->wl_display);<br>
+ zwp_text_input_v2_send_enter(text_input->resource, serial,<br>
text_input->surface->resource);<br>
}<br>
<br>
static void<br>
-text_input_deactivate(struct wl_client *client,<br>
- struct wl_resource *resource,<br>
- struct wl_resource *seat)<br>
-{<br>
- struct weston_seat *weston_seat = wl_resource_get_user_data(seat);<br>
-<br>
- if (weston_seat->input_method->input)<br>
- deactivate_input_method(weston_seat->input_method);<br>
-}<br>
-<br>
-static void<br>
-text_input_reset(struct wl_client *client,<br>
- struct wl_resource *resource)<br>
+text_input_disable(struct wl_client *client,<br>
+ struct wl_resource *resource,<br>
+ struct wl_resource *surface)<br>
{<br>
struct text_input *text_input = wl_resource_get_user_data(resource);<br>
- struct input_method *input_method, *next;<br>
+ struct weston_seat *seat = text_input->seat;<br>
<br>
- wl_list_for_each_safe(input_method, next,<br>
- &text_input->input_methods, link) {<br>
- if (!input_method->context)<br>
- continue;<br>
- zwp_input_method_context_v1_send_reset(<br>
- input_method->context->resource);<br>
- }<br>
+ if (seat->input_method->input)<br>
+ deactivate_input_method(seat->input_method);<br>
}<br>
<br>
static void<br>
@@ -300,27 +304,10 @@ text_input_set_content_type(struct wl_client *client,<br>
}<br>
<br>
static void<br>
-text_input_invoke_action(struct wl_client *client,<br>
- struct wl_resource *resource,<br>
- uint32_t button,<br>
- uint32_t index)<br>
-{<br>
- struct text_input *text_input = wl_resource_get_user_data(resource);<br>
- struct input_method *input_method, *next;<br>
-<br>
- wl_list_for_each_safe(input_method, next,<br>
- &text_input->input_methods, link) {<br>
- if (!input_method->context)<br>
- continue;<br>
- zwp_input_method_context_v1_send_invoke_action(<br>
- input_method->context->resource, button, index);<br>
- }<br>
-}<br>
-<br>
-static void<br>
-text_input_commit_state(struct wl_client *client,<br>
+text_input_update_state(struct wl_client *client,<br>
struct wl_resource *resource,<br>
- uint32_t serial)<br>
+ uint32_t serial,<br>
+ uint32_t reason)<br>
{<br>
struct text_input *text_input = wl_resource_get_user_data(resource);<br>
struct input_method *input_method, *next;<br>
@@ -329,8 +316,14 @@ text_input_commit_state(struct wl_client *client,<br>
&text_input->input_methods, link) {<br>
if (!input_method->context)<br>
continue;<br>
- zwp_input_method_context_v1_send_commit_state(<br>
- input_method->context->resource, serial);<br>
+<br>
+ if (reason == ZWP_TEXT_INPUT_V2_UPDATE_STATE_RESET) {<br>
+ zwp_input_method_context_v1_send_reset(<br>
+ input_method->context->resource);<br>
+ } else {<br>
+ zwp_input_method_context_v1_send_commit_state(<br>
+ input_method->context->resource, serial);<br>
+ }<br>
}<br>
}<br>
<br>
@@ -386,23 +379,31 @@ text_input_set_preferred_language(struct wl_client *client,<br>
}<br>
}<br>
<br>
-static const struct zwp_text_input_v1_interface text_input_implementation = {<br>
- text_input_activate,<br>
- text_input_deactivate,<br>
+static const struct zwp_text_input_v2_interface text_input_implementation = {<br>
+ text_input_destroy,<br>
+ text_input_enable,<br>
+ text_input_disable,<br>
text_input_show_input_panel,<br>
text_input_hide_input_panel,<br>
- text_input_reset,<br>
text_input_set_surrounding_text,<br>
text_input_set_content_type,<br>
text_input_set_cursor_rectangle,<br>
text_input_set_preferred_language,<br>
- text_input_commit_state,<br>
- text_input_invoke_action<br>
+ text_input_update_state,<br>
};<br>
<br>
-static void text_input_manager_create_text_input(struct wl_client *client,<br>
- struct wl_resource *resource,<br>
- uint32_t id)<br>
+static void<br>
+text_input_manager_destroy(struct wl_client *client,<br>
+ struct wl_resource *resource)<br>
+{<br>
+ wl_resource_destroy(resource);<br>
+}<br>
+<br>
+static void<br>
+text_input_manager_get_text_input(struct wl_client *client,<br>
+ struct wl_resource *resource,<br>
+ uint32_t id,<br>
+ struct wl_resource *seat)<br>
{<br>
struct text_input_manager *text_input_manager =<br>
wl_resource_get_user_data(resource);<br>
@@ -413,19 +414,21 @@ static void text_input_manager_create_text_input(struct wl_client *client,<br>
return;<br>
<br>
text_input->resource =<br>
- wl_resource_create(client, &zwp_text_input_v1_interface, 1, id);<br>
+ wl_resource_create(client, &zwp_text_input_v2_interface, 1, id);<br>
wl_resource_set_implementation(text_input->resource,<br>
&text_input_implementation,<br>
text_input, destroy_text_input);<br>
<br>
text_input->ec = text_input_manager->ec;<br>
text_input->manager = text_input_manager;<br>
+ text_input->seat = wl_resource_get_user_data(seat);<br>
<br>
wl_list_init(&text_input->input_methods);<br>
-};<br>
+}<br>
<br>
-static const struct zwp_text_input_manager_v1_interface manager_implementation = {<br>
- text_input_manager_create_text_input<br>
+static const struct zwp_text_input_manager_v2_interface manager_implementation = {<br>
+ text_input_manager_destroy,<br>
+ text_input_manager_get_text_input<br>
};<br>
<br>
static void<br>
@@ -440,7 +443,7 @@ bind_text_input_manager(struct wl_client *client,<br>
/* No checking for duplicate binding necessary. */<br>
resource =<br>
wl_resource_create(client,<br>
- &zwp_text_input_manager_v1_interface, 1, id);<br>
+ &zwp_text_input_manager_v2_interface, 1, id);<br>
if (resource)<br>
wl_resource_set_implementation(resource,<br>
&manager_implementation,<br>
@@ -473,7 +476,7 @@ text_input_manager_create(struct weston_compositor *ec)<br>
<br>
text_input_manager->text_input_manager_global =<br>
wl_global_create(ec->wl_display,<br>
- &zwp_text_input_manager_v1_interface, 1,<br>
+ &zwp_text_input_manager_v2_interface, 1,<br>
text_input_manager, bind_text_input_manager);<br>
<br>
text_input_manager->destroy_listener.notify =<br>
@@ -499,8 +502,8 @@ input_method_context_commit_string(struct wl_client *client,<br>
wl_resource_get_user_data(resource);<br>
<br>
if (context->input)<br>
- zwp_text_input_v1_send_commit_string(context->input->resource,<br>
- serial, text);<br>
+ zwp_text_input_v2_send_commit_string(context->input->resource,<br>
+ text);<br>
}<br>
<br>
static void<br>
@@ -514,8 +517,8 @@ input_method_context_preedit_string(struct wl_client *client,<br>
wl_resource_get_user_data(resource);<br>
<br>
if (context->input)<br>
- zwp_text_input_v1_send_preedit_string(context->input->resource,<br>
- serial, text, commit);<br>
+ zwp_text_input_v2_send_preedit_string(context->input->resource,<br>
+ text, commit);<br>
}<br>
<br>
static void<br>
@@ -529,7 +532,7 @@ input_method_context_preedit_styling(struct wl_client *client,<br>
wl_resource_get_user_data(resource);<br>
<br>
if (context->input)<br>
- zwp_text_input_v1_send_preedit_styling(context->input->resource,<br>
+ zwp_text_input_v2_send_preedit_styling(context->input->resource,<br>
index, length, style);<br>
}<br>
<br>
@@ -542,7 +545,7 @@ input_method_context_preedit_cursor(struct wl_client *client,<br>
wl_resource_get_user_data(resource);<br>
<br>
if (context->input)<br>
- zwp_text_input_v1_send_preedit_cursor(context->input->resource,<br>
+ zwp_text_input_v2_send_preedit_cursor(context->input->resource,<br>
cursor);<br>
}<br>
<br>
@@ -555,9 +558,14 @@ input_method_context_delete_surrounding_text(struct wl_client *client,<br>
struct input_method_context *context =<br>
wl_resource_get_user_data(resource);<br>
<br>
- if (context->input)<br>
- zwp_text_input_v1_send_delete_surrounding_text(<br>
- context->input->resource, index, length);<br>
+ if (context->input) {<br>
+ int before = -index;<br>
+ int after = index + length;<br>
+<br>
+ if (before >= 0 && after >= 0)<br>
+ zwp_text_input_v2_send_delete_surrounding_text(<br>
+ context->input->resource, before, after);<br>
+ }<br>
}<br>
<br>
static void<br>
@@ -570,7 +578,7 @@ input_method_context_cursor_position(struct wl_client *client,<br>
wl_resource_get_user_data(resource);<br>
<br>
if (context->input)<br>
- zwp_text_input_v1_send_cursor_position(context->input->resource,<br>
+ zwp_text_input_v2_send_cursor_position(context->input->resource,<br>
index, anchor);<br>
}<br>
<br>
@@ -583,7 +591,7 @@ input_method_context_modifiers_map(struct wl_client *client,<br>
wl_resource_get_user_data(resource);<br>
<br>
if (context->input)<br>
- zwp_text_input_v1_send_modifiers_map(context->input->resource,<br>
+ zwp_text_input_v2_send_modifiers_map(context->input->resource,<br>
map);<br>
}<br>
<br>
@@ -600,9 +608,8 @@ input_method_context_keysym(struct wl_client *client,<br>
wl_resource_get_user_data(resource);<br>
<br>
if (context->input)<br>
- zwp_text_input_v1_send_keysym(context->input->resource,<br>
- serial, time,<br>
- sym, state, modifiers);<br>
+ zwp_text_input_v2_send_keysym(context->input->resource,<br>
+ time, sym, state, modifiers);<br>
}<br>
<br>
static void<br>
@@ -764,8 +771,8 @@ input_method_context_language(struct wl_client *client,<br>
wl_resource_get_user_data(resource);<br>
<br>
if (context->input)<br>
- zwp_text_input_v1_send_language(context->input->resource,<br>
- serial, language);<br>
+ zwp_text_input_v2_send_language(context->input->resource,<br>
+ language);<br>
}<br>
<br>
static void<br>
@@ -778,8 +785,8 @@ input_method_context_text_direction(struct wl_client *client,<br>
wl_resource_get_user_data(resource);<br>
<br>
if (context->input)<br>
- zwp_text_input_v1_send_text_direction(context->input->resource,<br>
- serial, direction);<br>
+ zwp_text_input_v2_send_text_direction(context->input->resource,<br>
+ direction);<br>
}<br>
<br>
<br>
--<br>
2.7.4<br>
<br></blockquote><div><br></div><div>Looks good.</div><div><span style="line-height:1.5"><br></span></div><div><span style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif;font-size:13px">Reviewed-by:</span><span style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif;font-size:13px"> Jan Arne Petersen <<a href="mailto:janarne@gmail.com" target="_blank">janarne@gmail.com</a>></span><br></div></div></div>