This will not work with multiple seats, right? I guess the input_method struct would have to be broken up into a 'global' part (containing the global object bindings) and a per seat part. Or am I missing something?
Cheers, Philipp On Fri, Aug 10, 2012 at 4:47 PM, Jan Arne Petersen <jpeter...@openismus.com> wrote: > From: Jan Arne Petersen <jpeter...@openismus.com> > > Add a wl_seat argument to the activate and deactivate requests of > text_method. > > On activation a text_model gets assigned to the input_method of the > wl_seat specified in the activate request. > --- > clients/editor.c | 28 +++++++++++++++------- > protocol/text.xml | 9 +++++-- > src/compositor.c | 2 +- > src/compositor.h | 6 ++++- > src/text-backend.c | 70 > ++++++++++++++++++++++++++++++++---------------------- > 5 files changed, 75 insertions(+), 40 deletions(-) > > diff --git a/clients/editor.c b/clients/editor.c > index 9cb7326..a5347fe 100644 > --- a/clients/editor.c > +++ b/clients/editor.c > @@ -33,6 +33,7 @@ > > struct text_entry { > struct widget *widget; > + struct window *window; > char *text; > int active; > struct rectangle allocation; > @@ -152,6 +153,7 @@ text_entry_create(struct editor *editor, const char *text) > surface = window_get_wl_surface(editor->window); > > entry->widget = editor->widget; > + entry->window = editor->window; > entry->text = strdup(text); > entry->active = 0; > entry->model = > text_model_factory_create_text_model(editor->text_model_factory, surface); > @@ -271,15 +273,22 @@ rectangle_contains(struct rectangle *rectangle, int32_t > x, int32_t y) > } > > static void > -text_entry_activate(struct text_entry *entry) > +text_entry_activate(struct text_entry *entry, > + struct wl_seat *seat) > { > - text_model_activate(entry->model); > + struct wl_surface *surface = window_get_wl_surface(entry->window); > + > + text_model_activate(entry->model, > + seat, > + surface); > } > > static void > -text_entry_deactivate(struct text_entry *entry) > +text_entry_deactivate(struct text_entry *entry, > + struct wl_seat *seat) > { > - text_model_deactivate(entry->model); > + text_model_deactivate(entry->model, > + seat); > } > > static void > @@ -291,6 +300,7 @@ button_handler(struct widget *widget, > struct editor *editor = data; > struct rectangle allocation; > int32_t x, y; > + struct wl_seat *seat; > > if (state != WL_POINTER_BUTTON_STATE_PRESSED || button != BTN_LEFT) { > return; > @@ -306,13 +316,15 @@ button_handler(struct widget *widget, > int32_t activate_editor = > rectangle_contains(&editor->editor->allocation, x, y); > assert(!(activate_entry && activate_editor)); > > + seat = input_get_seat(input); > + > if (activate_entry) { > - text_entry_activate(editor->entry); > + text_entry_activate(editor->entry, seat); > } else if (activate_editor) { > - text_entry_activate(editor->editor); > + text_entry_activate(editor->editor, seat); > } else { > - text_entry_deactivate(editor->entry); > - text_entry_deactivate(editor->editor); > + text_entry_deactivate(editor->entry, seat); > + text_entry_deactivate(editor->editor, seat); > } > > widget_schedule_redraw(widget); > diff --git a/protocol/text.xml b/protocol/text.xml > index ac12a1a..e73cacb 100644 > --- a/protocol/text.xml > +++ b/protocol/text.xml > @@ -6,8 +6,13 @@ > <request name="set_cursor_index"> > <arg name="index" type="uint"/> > </request> > - <request name="activate"/> > - <request name="deactivate"/> > + <request name="activate"> > + <arg name="seat" type="object" interface="wl_seat"/> > + <arg name="surface" type="object" interface="wl_surface"/> > + </request> > + <request name="deactivate"> > + <arg name="seat" type="object" interface="wl_seat"/> > + </request> > <request name="set_selected_text"> > <arg name="text" type="string"/> > <arg name="index" type="int"/> > diff --git a/src/compositor.c b/src/compositor.c > index 34df5f7..f6e67eb 100644 > --- a/src/compositor.c > +++ b/src/compositor.c > @@ -2632,6 +2632,7 @@ weston_seat_init(struct weston_seat *seat, struct > weston_compositor *ec) > &seat->new_drag_icon_listener); > > clipboard_create(seat); > + input_method_create(ec, seat); > } > > WL_EXPORT void > @@ -3183,7 +3184,6 @@ weston_compositor_init(struct weston_compositor *ec, > > screenshooter_create(ec); > text_cursor_position_notifier_create(ec); > - input_method_create(ec); > > wl_data_device_manager_init(ec->wl_display); > > diff --git a/src/compositor.h b/src/compositor.h > index 47301fa..acf38a4 100644 > --- a/src/compositor.h > +++ b/src/compositor.h > @@ -47,6 +47,7 @@ struct weston_surface; > struct shell_surface; > struct weston_seat; > struct weston_output; > +struct input_method; > > enum weston_keyboard_modifier { > MODIFIER_CTRL = (1 << 0), > @@ -235,6 +236,8 @@ struct weston_seat { > struct xkb_state *state; > enum weston_led leds; > } xkb_state; > + > + struct input_method *input_method; > }; > > struct weston_shader { > @@ -742,7 +745,8 @@ void > text_cursor_position_notifier_create(struct weston_compositor *ec); > > void > -input_method_create(struct weston_compositor *ec); > +input_method_create(struct weston_compositor *ec, > + struct weston_seat *seat); > > struct weston_process; > typedef void (*weston_process_cleanup_func_t)(struct weston_process *process, > diff --git a/src/text-backend.c b/src/text-backend.c > index 9113c9b..c634aec 100644 > --- a/src/text-backend.c > +++ b/src/text-backend.c > @@ -30,9 +30,9 @@ struct input_method; > struct text_model { > struct wl_resource resource; > > - struct wl_list link; > + struct weston_compositor *ec; > > - struct input_method *input_method; > + struct wl_list input_methods; > }; > > struct input_method { > @@ -42,17 +42,20 @@ struct input_method { > struct wl_listener destroy_listener; > > struct weston_compositor *ec; > - struct wl_list models; > - struct text_model *active_model; > + struct text_model *model; > + > + struct wl_list link; > }; > > static void > -deactivate_text_model(struct text_model *text_model) > +deactivate_text_model(struct text_model *text_model, > + struct input_method *input_method) > { > - struct weston_compositor *ec = text_model->input_method->ec; > + struct weston_compositor *ec = text_model->ec; > > - if (text_model->input_method->active_model == text_model) { > - text_model->input_method->active_model = NULL; > + if (input_method->model == text_model) { > + wl_list_remove(&input_method->link); > + input_method->model = NULL; > wl_signal_emit(&ec->hide_input_panel_signal, ec); > text_model_send_deactivated(&text_model->resource); > } > @@ -63,10 +66,11 @@ destroy_text_model(struct wl_resource *resource) > { > struct text_model *text_model = > container_of(resource, struct text_model, resource); > + struct input_method *input_method, *next; > > - deactivate_text_model(text_model); > + wl_list_for_each_safe(input_method, next, &text_model->input_methods, > link) > + deactivate_text_model(text_model, input_method); > > - wl_list_remove(&text_model->link); > free(text_model); > } > > @@ -86,19 +90,25 @@ text_model_set_cursor_index(struct wl_client *client, > > static void > text_model_activate(struct wl_client *client, > - struct wl_resource *resource) > + struct wl_resource *resource, > + struct wl_resource *seat, > + struct wl_resource *surface) > { > struct text_model *text_model = resource->data; > - struct weston_compositor *ec = text_model->input_method->ec; > + struct weston_seat *weston_seat = seat->data; > + struct text_model *old = weston_seat->input_method->model; > + struct weston_compositor *ec = text_model->ec; > > - if (text_model->input_method->active_model) { > - if (text_model->input_method->active_model == text_model) > - return; > + if (old == text_model) > + return; > > - deactivate_text_model(text_model->input_method->active_model); > + if (old) { > + deactivate_text_model(old, > + weston_seat->input_method); > } > > - text_model->input_method->active_model = text_model; > + weston_seat->input_method->model = text_model; > + wl_list_insert(&text_model->input_methods, > &weston_seat->input_method->link); > > wl_signal_emit(&ec->show_input_panel_signal, ec); > > @@ -107,11 +117,14 @@ text_model_activate(struct wl_client *client, > > static void > text_model_deactivate(struct wl_client *client, > - struct wl_resource *resource) > + struct wl_resource *resource, > + struct wl_resource *seat) > { > struct text_model *text_model = resource->data; > + struct weston_seat *weston_seat = seat->data; > > - deactivate_text_model(text_model); > + deactivate_text_model(text_model, > + weston_seat->input_method); > } > > static void > @@ -144,7 +157,7 @@ text_model_set_content_type(struct wl_client *client, > { > } > > -struct text_model_interface text_model_implementation = { > +static const struct text_model_interface text_model_implementation = { > text_model_set_surrounding_text, > text_model_set_cursor_index, > text_model_activate, > @@ -173,11 +186,11 @@ static void text_model_factory_create_text_model(struct > wl_client *client, > (void (**)(void)) &text_model_implementation; > text_model->resource.data = text_model; > > - text_model->input_method = input_method; > + text_model->ec = input_method->ec; > > wl_client_add_resource(client, &text_model->resource); > > - wl_list_insert(&input_method->models, &text_model->link); > + wl_list_init(&text_model->input_methods); > }; > > static const struct text_model_factory_interface > text_model_factory_implementation = { > @@ -207,8 +220,8 @@ input_method_commit_string(struct wl_client *client, > { > struct input_method *input_method = resource->data; > > - if (input_method->active_model) { > - > text_model_send_commit_string(&input_method->active_model->resource, text, > index); > + if (input_method->model) { > + text_model_send_commit_string(&input_method->model->resource, > text, index); > } > } > > @@ -263,16 +276,15 @@ input_method_notifier_destroy(struct wl_listener > *listener, void *data) > } > > void > -input_method_create(struct weston_compositor *ec) > +input_method_create(struct weston_compositor *ec, > + struct weston_seat *seat) > { > struct input_method *input_method; > > input_method = calloc(1, sizeof *input_method); > > input_method->ec = ec; > - input_method->active_model = NULL; > - > - wl_list_init(&input_method->models); > + input_method->model = NULL; > > input_method->input_method_global = > wl_display_add_global(ec->wl_display, > @@ -286,4 +298,6 @@ input_method_create(struct weston_compositor *ec) > > input_method->destroy_listener.notify = input_method_notifier_destroy; > wl_signal_add(&ec->destroy_signal, &input_method->destroy_listener); > + > + seat->input_method = input_method; > } > -- > 1.7.11.2 > > _______________________________________________ > wayland-devel mailing list > wayland-devel@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/wayland-devel _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel