2 * Copyright © 2010-2012 Intel Corporation
3 * Copyright © 2011-2012 Collabora, Ltd.
4 * Copyright © 2013 Raspberry Pi Foundation
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #include "ivi-shell.h"
36 #include "input-method-unstable-v1-server-protocol.h"
37 #include "ivi-layout-private.h"
38 #include "shared/helpers.h"
40 struct input_panel_surface {
41 struct wl_resource *resource;
42 struct wl_signal destroy_signal;
44 struct ivi_shell *shell;
47 struct weston_surface *surface;
48 struct weston_view *view;
49 struct wl_listener surface_destroy_listener;
51 struct weston_view_animation *anim;
53 struct weston_output *output;
58 input_panel_slide_done(struct weston_view_animation *animation, void *data)
60 struct input_panel_surface *ipsurf = data;
66 show_input_panel_surface(struct input_panel_surface *ipsurf)
68 struct ivi_shell *shell = ipsurf->shell;
69 struct weston_seat *seat;
70 struct weston_surface *focus;
73 wl_list_for_each(seat, &shell->compositor->seat_list, link) {
74 struct weston_keyboard *keyboard =
75 weston_seat_get_keyboard(seat);
77 if (!keyboard || !keyboard->focus)
79 focus = weston_surface_get_main_surface(keyboard->focus);
80 ipsurf->output = focus->output;
81 x = ipsurf->output->x + (ipsurf->output->width - ipsurf->surface->width) / 2;
82 y = ipsurf->output->y + ipsurf->output->height - ipsurf->surface->height;
83 weston_view_set_position(ipsurf->view, x, y);
86 weston_layer_entry_insert(&shell->input_panel_layer.view_list,
87 &ipsurf->view->layer_link);
88 weston_view_geometry_dirty(ipsurf->view);
89 weston_view_update_transform(ipsurf->view);
90 ipsurf->surface->is_mapped = true;
91 ipsurf->view->is_mapped = true;
92 weston_surface_damage(ipsurf->surface);
95 weston_view_animation_destroy(ipsurf->anim);
98 weston_slide_run(ipsurf->view,
99 ipsurf->surface->height * 0.9, 0,
100 input_panel_slide_done, ipsurf);
104 show_input_panels(struct wl_listener *listener, void *data)
106 struct ivi_shell *shell =
107 container_of(listener, struct ivi_shell,
108 show_input_panel_listener);
109 struct input_panel_surface *ipsurf, *next;
111 shell->text_input.surface = (struct weston_surface*)data;
113 if (shell->showing_input_panels)
116 shell->showing_input_panels = true;
119 weston_layer_set_position(&shell->input_panel_layer,
120 WESTON_LAYER_POSITION_TOP_UI);
122 wl_list_for_each_safe(ipsurf, next,
123 &shell->input_panel.surfaces, link) {
124 if (ipsurf->surface->width == 0)
127 show_input_panel_surface(ipsurf);
132 hide_input_panels(struct wl_listener *listener, void *data)
134 struct ivi_shell *shell =
135 container_of(listener, struct ivi_shell,
136 hide_input_panel_listener);
137 struct weston_view *view, *next;
139 if (!shell->showing_input_panels)
142 shell->showing_input_panels = false;
145 weston_layer_unset_position(&shell->input_panel_layer);
147 wl_list_for_each_safe(view, next,
148 &shell->input_panel_layer.view_list.link,
150 weston_view_unmap(view);
154 update_input_panels(struct wl_listener *listener, void *data)
156 struct ivi_shell *shell =
157 container_of(listener, struct ivi_shell,
158 update_input_panel_listener);
160 memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t));
164 input_panel_get_label(struct weston_surface *surface, char *buf, size_t len)
166 return snprintf(buf, len, "input panel");
170 input_panel_committed(struct weston_surface *surface, int32_t sx, int32_t sy)
172 struct input_panel_surface *ip_surface = surface->committed_private;
173 struct ivi_shell *shell = ip_surface->shell;
174 struct weston_view *view;
177 if (surface->width == 0)
180 if (ip_surface->panel) {
181 view = get_default_view(shell->text_input.surface);
184 x = view->geometry.x + shell->text_input.cursor_rectangle.x2;
185 y = view->geometry.y + shell->text_input.cursor_rectangle.y2;
187 x = ip_surface->output->x + (ip_surface->output->width - surface->width) / 2;
188 y = ip_surface->output->y + ip_surface->output->height - surface->height;
191 weston_view_set_position(ip_surface->view, x, y);
193 if (!weston_surface_is_mapped(surface) && shell->showing_input_panels)
194 show_input_panel_surface(ip_surface);
198 destroy_input_panel_surface(struct input_panel_surface *input_panel_surface)
200 wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface);
202 wl_list_remove(&input_panel_surface->surface_destroy_listener.link);
203 wl_list_remove(&input_panel_surface->link);
205 input_panel_surface->surface->committed = NULL;
206 weston_surface_set_label_func(input_panel_surface->surface, NULL);
207 weston_view_destroy(input_panel_surface->view);
209 free(input_panel_surface);
212 static struct input_panel_surface *
213 get_input_panel_surface(struct weston_surface *surface)
215 if (surface->committed == input_panel_committed) {
216 return surface->committed_private;
223 input_panel_handle_surface_destroy(struct wl_listener *listener, void *data)
225 struct input_panel_surface *ipsurface = container_of(listener,
226 struct input_panel_surface,
227 surface_destroy_listener);
229 if (ipsurface->resource) {
230 wl_resource_destroy(ipsurface->resource);
232 destroy_input_panel_surface(ipsurface);
236 static struct input_panel_surface *
237 create_input_panel_surface(struct ivi_shell *shell,
238 struct weston_surface *surface)
240 struct input_panel_surface *input_panel_surface;
242 input_panel_surface = calloc(1, sizeof *input_panel_surface);
243 if (!input_panel_surface)
246 surface->committed = input_panel_committed;
247 surface->committed_private = input_panel_surface;
248 weston_surface_set_label_func(surface, input_panel_get_label);
250 input_panel_surface->shell = shell;
252 input_panel_surface->surface = surface;
253 input_panel_surface->view = weston_view_create(surface);
255 wl_signal_init(&input_panel_surface->destroy_signal);
256 input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy;
257 wl_signal_add(&surface->destroy_signal,
258 &input_panel_surface->surface_destroy_listener);
260 wl_list_init(&input_panel_surface->link);
262 return input_panel_surface;
266 input_panel_surface_set_toplevel(struct wl_client *client,
267 struct wl_resource *resource,
268 struct wl_resource *output_resource,
271 struct input_panel_surface *input_panel_surface =
272 wl_resource_get_user_data(resource);
273 struct ivi_shell *shell = input_panel_surface->shell;
274 struct weston_head *head;
276 wl_list_insert(&shell->input_panel.surfaces,
277 &input_panel_surface->link);
279 head = weston_head_from_resource(output_resource);
280 input_panel_surface->output = head->output;
281 input_panel_surface->panel = 0;
285 input_panel_surface_set_overlay_panel(struct wl_client *client,
286 struct wl_resource *resource)
288 struct input_panel_surface *input_panel_surface =
289 wl_resource_get_user_data(resource);
290 struct ivi_shell *shell = input_panel_surface->shell;
292 wl_list_insert(&shell->input_panel.surfaces,
293 &input_panel_surface->link);
295 input_panel_surface->panel = 1;
298 static const struct zwp_input_panel_surface_v1_interface input_panel_surface_implementation = {
299 input_panel_surface_set_toplevel,
300 input_panel_surface_set_overlay_panel
304 destroy_input_panel_surface_resource(struct wl_resource *resource)
306 struct input_panel_surface *ipsurf =
307 wl_resource_get_user_data(resource);
309 destroy_input_panel_surface(ipsurf);
313 input_panel_get_input_panel_surface(struct wl_client *client,
314 struct wl_resource *resource,
316 struct wl_resource *surface_resource)
318 struct weston_surface *surface =
319 wl_resource_get_user_data(surface_resource);
320 struct ivi_shell *shell = wl_resource_get_user_data(resource);
321 struct input_panel_surface *ipsurf;
323 if (get_input_panel_surface(surface)) {
324 wl_resource_post_error(surface_resource,
325 WL_DISPLAY_ERROR_INVALID_OBJECT,
326 "wl_input_panel::get_input_panel_surface already requested");
330 ipsurf = create_input_panel_surface(shell, surface);
332 wl_resource_post_error(surface_resource,
333 WL_DISPLAY_ERROR_INVALID_OBJECT,
334 "surface->committed already set");
339 wl_resource_create(client,
340 &zwp_input_panel_surface_v1_interface,
343 wl_resource_set_implementation(ipsurf->resource,
344 &input_panel_surface_implementation,
346 destroy_input_panel_surface_resource);
349 static const struct zwp_input_panel_v1_interface input_panel_implementation = {
350 input_panel_get_input_panel_surface
354 unbind_input_panel(struct wl_resource *resource)
356 struct ivi_shell *shell = wl_resource_get_user_data(resource);
358 shell->input_panel.binding = NULL;
362 bind_input_panel(struct wl_client *client,
363 void *data, uint32_t version, uint32_t id)
365 struct ivi_shell *shell = data;
366 struct wl_resource *resource;
368 resource = wl_resource_create(client,
369 &zwp_input_panel_v1_interface, 1, id);
371 if (shell->input_panel.binding == NULL) {
372 wl_resource_set_implementation(resource,
373 &input_panel_implementation,
374 shell, unbind_input_panel);
375 shell->input_panel.binding = resource;
379 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
380 "interface object already bound");
384 input_panel_destroy(struct ivi_shell *shell)
386 wl_list_remove(&shell->show_input_panel_listener.link);
387 wl_list_remove(&shell->hide_input_panel_listener.link);
391 input_panel_setup(struct ivi_shell *shell)
393 struct weston_compositor *ec = shell->compositor;
395 shell->show_input_panel_listener.notify = show_input_panels;
396 wl_signal_add(&ec->show_input_panel_signal,
397 &shell->show_input_panel_listener);
398 shell->hide_input_panel_listener.notify = hide_input_panels;
399 wl_signal_add(&ec->hide_input_panel_signal,
400 &shell->hide_input_panel_listener);
401 shell->update_input_panel_listener.notify = update_input_panels;
402 wl_signal_add(&ec->update_input_panel_signal,
403 &shell->update_input_panel_listener);
405 wl_list_init(&shell->input_panel.surfaces);
407 if (wl_global_create(shell->compositor->wl_display,
408 &zwp_input_panel_v1_interface, 1,
409 shell, bind_input_panel) == NULL)