summaryrefslogtreecommitdiffstats
path: root/meta-ivi/recipes-graphics/wayland/weston-1.6.0/0013-Reference-implementation-of-input-panel-for-ivi-shel.patch
blob: 3e938f5ba9c341306969e8ee01af76800d196f2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
From 301505d5b731d89e87a81de04d83230cb2de2246 Mon Sep 17 00:00:00 2001
From: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Date: Thu, 6 Nov 2014 13:44:18 +0900
Subject: [PATCH 13/15] Reference implementation of input panel for ivi-shell.
 - introduces ivi-shell/input-panel-ivi.c

The basement of this code is from input-panel.c of desktop shell.

--------------------------------------------------------
ivi-shell/input-panel-ivi.c: remove non-availalable header including

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

--------------------------------------------------------
input-panel-ivi: remove DENSO copyright

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

--------------------------------------------------------
input-panel-ivi: revert one patch to be separeated

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

--------------------------------------------------------
input-panel-ivi: remove panel_layer which is not required

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
---
 Makefile.am                 |    3 +-
 ivi-shell/input-panel-ivi.c |  391 +++++++++++++++++++++++++++++++++++++++++++
 ivi-shell/ivi-shell.c       |   30 ++++
 ivi-shell/ivi-shell.h       |   28 ++++
 ivi-shell/weston.ini.in     |    3 +
 5 files changed, 454 insertions(+), 1 deletion(-)
 create mode 100644 ivi-shell/input-panel-ivi.c

diff --git a/Makefile.am b/Makefile.am
index 081c854..2c9ffde 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -788,7 +788,8 @@ ivi_shell_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS)
 ivi_shell_la_SOURCES =				\
 	ivi-shell/ivi-shell.h			\
 	ivi-shell/ivi-shell.c			\
-	ivi-shell/ivi-layout-private.h
+	ivi-shell/ivi-layout-private.h		\
+	ivi-shell/input-panel-ivi.c
 nodist_ivi_shell_la_SOURCES =			\
 	protocol/ivi-application-protocol.c		\
 	protocol/ivi-application-server-protocol.h
diff --git a/ivi-shell/input-panel-ivi.c b/ivi-shell/input-panel-ivi.c
new file mode 100644
index 0000000..01fd329
--- /dev/null
+++ b/ivi-shell/input-panel-ivi.c
@@ -0,0 +1,391 @@
+/*
+ * Copyright © 2010-2012 Intel Corporation
+ * Copyright © 2011-2012 Collabora, Ltd.
+ * Copyright © 2013 Raspberry Pi Foundation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "ivi-shell.h"
+#include "input-method-server-protocol.h"
+#include "ivi-layout-private.h"
+
+struct input_panel_surface {
+	struct wl_resource *resource;
+	struct wl_signal destroy_signal;
+
+	struct ivi_shell *shell;
+
+	struct wl_list link;
+	struct weston_surface *surface;
+	struct weston_view *view;
+	struct wl_listener surface_destroy_listener;
+
+	struct weston_view_animation *anim;
+
+	struct weston_output *output;
+	uint32_t panel;
+};
+
+static void
+input_panel_slide_done(struct weston_view_animation *animation, void *data)
+{
+	struct input_panel_surface *ipsurf = data;
+
+	ipsurf->anim = NULL;
+}
+
+static void
+show_input_panel_surface(struct input_panel_surface *ipsurf)
+{
+	struct ivi_shell *shell = ipsurf->shell;
+	struct weston_seat *seat;
+	struct weston_surface *focus;
+	float x, y;
+
+	wl_list_for_each(seat, &shell->compositor->seat_list, link) {
+		if (!seat->keyboard)
+			continue;
+		focus = weston_surface_get_main_surface(seat->keyboard->focus);
+		ipsurf->output = focus->output;
+		x = ipsurf->output->x + (ipsurf->output->width - ipsurf->surface->width) / 2;
+		y = ipsurf->output->y + ipsurf->output->height - ipsurf->surface->height;
+		weston_view_set_position(ipsurf->view, x, y);
+	}
+
+	weston_layer_entry_insert(&shell->input_panel_layer.view_list,
+	                          &ipsurf->view->layer_link);
+	weston_view_geometry_dirty(ipsurf->view);
+	weston_view_update_transform(ipsurf->view);
+	weston_surface_damage(ipsurf->surface);
+
+	if (ipsurf->anim)
+		weston_view_animation_destroy(ipsurf->anim);
+
+	ipsurf->anim =
+		weston_slide_run(ipsurf->view,
+				 ipsurf->surface->height * 0.9, 0,
+				 input_panel_slide_done, ipsurf);
+}
+
+static void
+show_input_panels(struct wl_listener *listener, void *data)
+{
+	struct ivi_shell *shell =
+		container_of(listener, struct ivi_shell,
+			     show_input_panel_listener);
+	struct input_panel_surface *ipsurf, *next;
+
+	shell->text_input.surface = (struct weston_surface*)data;
+
+	if (shell->showing_input_panels)
+		return;
+
+	shell->showing_input_panels = true;
+
+	if (!shell->locked)
+		wl_list_insert(&shell->compositor->cursor_layer.link,
+			       &shell->input_panel_layer.link);
+
+	wl_list_for_each_safe(ipsurf, next,
+			      &shell->input_panel.surfaces, link) {
+		if (ipsurf->surface->width == 0)
+			continue;
+
+		show_input_panel_surface(ipsurf);
+	}
+}
+
+static void
+hide_input_panels(struct wl_listener *listener, void *data)
+{
+	struct ivi_shell *shell =
+		container_of(listener, struct ivi_shell,
+			     hide_input_panel_listener);
+	struct weston_view *view, *next;
+
+	if (!shell->showing_input_panels)
+		return;
+
+	shell->showing_input_panels = false;
+
+	if (!shell->locked)
+		wl_list_remove(&shell->input_panel_layer.link);
+
+	wl_list_for_each_safe(view, next,
+			      &shell->input_panel_layer.view_list.link,
+			      layer_link.link)
+		weston_view_unmap(view);
+}
+
+static void
+update_input_panels(struct wl_listener *listener, void *data)
+{
+	struct ivi_shell *shell =
+		container_of(listener, struct ivi_shell,
+			     update_input_panel_listener);
+
+	memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t));
+}
+
+static void
+input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy)
+{
+	struct input_panel_surface *ip_surface = surface->configure_private;
+	struct ivi_shell *shell = ip_surface->shell;
+	struct weston_view *view;
+	float x, y;
+
+	if (surface->width == 0)
+		return;
+
+	if (ip_surface->panel) {
+		view = get_default_view(shell->text_input.surface);
+		if (view == NULL)
+			return;
+		x = view->geometry.x + shell->text_input.cursor_rectangle.x2;
+		y = view->geometry.y + shell->text_input.cursor_rectangle.y2;
+	} else {
+		x = ip_surface->output->x + (ip_surface->output->width - surface->width) / 2;
+		y = ip_surface->output->y + ip_surface->output->height - surface->height;
+	}
+
+	weston_view_set_position(ip_surface->view, x, y);
+
+	if (!weston_surface_is_mapped(surface) && shell->showing_input_panels)
+		show_input_panel_surface(ip_surface);
+}
+
+static void
+destroy_input_panel_surface(struct input_panel_surface *input_panel_surface)
+{
+	wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface);
+
+	wl_list_remove(&input_panel_surface->surface_destroy_listener.link);
+	wl_list_remove(&input_panel_surface->link);
+
+	input_panel_surface->surface->configure = NULL;
+	weston_view_destroy(input_panel_surface->view);
+
+	free(input_panel_surface);
+}
+
+static struct input_panel_surface *
+get_input_panel_surface(struct weston_surface *surface)
+{
+	if (surface->configure == input_panel_configure) {
+		return surface->configure_private;
+	} else {
+		return NULL;
+	}
+}
+
+static void
+input_panel_handle_surface_destroy(struct wl_listener *listener, void *data)
+{
+	struct input_panel_surface *ipsurface = container_of(listener,
+							     struct input_panel_surface,
+							     surface_destroy_listener);
+
+	if (ipsurface->resource) {
+		wl_resource_destroy(ipsurface->resource);
+	} else {
+		destroy_input_panel_surface(ipsurface);
+	}
+}
+
+static struct input_panel_surface *
+create_input_panel_surface(struct ivi_shell *shell,
+			   struct weston_surface *surface)
+{
+	struct input_panel_surface *input_panel_surface;
+
+	input_panel_surface = calloc(1, sizeof *input_panel_surface);
+	if (!input_panel_surface)
+		return NULL;
+
+	surface->configure = input_panel_configure;
+	surface->configure_private = input_panel_surface;
+
+	input_panel_surface->shell = shell;
+
+	input_panel_surface->surface = surface;
+	input_panel_surface->view = weston_view_create(surface);
+
+	wl_signal_init(&input_panel_surface->destroy_signal);
+	input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy;
+	wl_signal_add(&surface->destroy_signal,
+		      &input_panel_surface->surface_destroy_listener);
+
+	wl_list_init(&input_panel_surface->link);
+
+	return input_panel_surface;
+}
+
+static void
+input_panel_surface_set_toplevel(struct wl_client *client,
+				 struct wl_resource *resource,
+				 struct wl_resource *output_resource,
+				 uint32_t position)
+{
+	struct input_panel_surface *input_panel_surface =
+		wl_resource_get_user_data(resource);
+	struct ivi_shell *shell = input_panel_surface->shell;
+
+	wl_list_insert(&shell->input_panel.surfaces,
+		       &input_panel_surface->link);
+
+	input_panel_surface->output = wl_resource_get_user_data(output_resource);
+	input_panel_surface->panel = 0;
+}
+
+static void
+input_panel_surface_set_overlay_panel(struct wl_client *client,
+				      struct wl_resource *resource)
+{
+	struct input_panel_surface *input_panel_surface =
+		wl_resource_get_user_data(resource);
+	struct ivi_shell *shell = input_panel_surface->shell;
+
+	wl_list_insert(&shell->input_panel.surfaces,
+		       &input_panel_surface->link);
+
+	input_panel_surface->panel = 1;
+}
+
+static const struct wl_input_panel_surface_interface input_panel_surface_implementation = {
+	input_panel_surface_set_toplevel,
+	input_panel_surface_set_overlay_panel
+};
+
+static void
+destroy_input_panel_surface_resource(struct wl_resource *resource)
+{
+	struct input_panel_surface *ipsurf =
+		wl_resource_get_user_data(resource);
+
+	destroy_input_panel_surface(ipsurf);
+}
+
+static void
+input_panel_get_input_panel_surface(struct wl_client *client,
+				    struct wl_resource *resource,
+				    uint32_t id,
+				    struct wl_resource *surface_resource)
+{
+	struct weston_surface *surface =
+		wl_resource_get_user_data(surface_resource);
+	struct ivi_shell *shell = wl_resource_get_user_data(resource);
+	struct input_panel_surface *ipsurf;
+
+	if (get_input_panel_surface(surface)) {
+		wl_resource_post_error(surface_resource,
+				       WL_DISPLAY_ERROR_INVALID_OBJECT,
+				       "wl_input_panel::get_input_panel_surface already requested");
+		return;
+	}
+
+	ipsurf = create_input_panel_surface(shell, surface);
+	if (!ipsurf) {
+		wl_resource_post_error(surface_resource,
+				       WL_DISPLAY_ERROR_INVALID_OBJECT,
+				       "surface->configure already set");
+		return;
+	}
+
+	ipsurf->resource =
+		wl_resource_create(client,
+				   &wl_input_panel_surface_interface, 1, id);
+	wl_resource_set_implementation(ipsurf->resource,
+				       &input_panel_surface_implementation,
+				       ipsurf,
+				       destroy_input_panel_surface_resource);
+}
+
+static const struct wl_input_panel_interface input_panel_implementation = {
+	input_panel_get_input_panel_surface
+};
+
+static void
+unbind_input_panel(struct wl_resource *resource)
+{
+	struct ivi_shell *shell = wl_resource_get_user_data(resource);
+
+	shell->input_panel.binding = NULL;
+}
+
+static void
+bind_input_panel(struct wl_client *client,
+             void *data, uint32_t version, uint32_t id)
+{
+	struct ivi_shell *shell = data;
+	struct wl_resource *resource;
+
+	resource = wl_resource_create(client,
+				      &wl_input_panel_interface, 1, id);
+
+	if (shell->input_panel.binding == NULL) {
+		wl_resource_set_implementation(resource,
+					       &input_panel_implementation,
+					       shell, unbind_input_panel);
+		shell->input_panel.binding = resource;
+		return;
+	}
+
+	wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
+			       "interface object already bound");
+}
+
+void
+input_panel_destroy(struct ivi_shell *shell)
+{
+	wl_list_remove(&shell->show_input_panel_listener.link);
+	wl_list_remove(&shell->hide_input_panel_listener.link);
+}
+
+int
+input_panel_setup(struct ivi_shell *shell)
+{
+	struct weston_compositor *ec = shell->compositor;
+
+	shell->show_input_panel_listener.notify = show_input_panels;
+	wl_signal_add(&ec->show_input_panel_signal,
+		      &shell->show_input_panel_listener);
+	shell->hide_input_panel_listener.notify = hide_input_panels;
+	wl_signal_add(&ec->hide_input_panel_signal,
+		      &shell->hide_input_panel_listener);
+	shell->update_input_panel_listener.notify = update_input_panels;
+	wl_signal_add(&ec->update_input_panel_signal,
+		      &shell->update_input_panel_listener);
+
+	wl_list_init(&shell->input_panel.surfaces);
+
+	if (wl_global_create(shell->compositor->wl_display,
+			     &wl_input_panel_interface, 1,
+			     shell, bind_input_panel) == NULL)
+		return -1;
+
+	return 0;
+}
diff --git a/ivi-shell/ivi-shell.c b/ivi-shell/ivi-shell.c
index 3904402..5723c00 100644
--- a/ivi-shell/ivi-shell.c
+++ b/ivi-shell/ivi-shell.c
@@ -375,6 +375,31 @@ bind_ivi_application(struct wl_client *client,
 				       shell, NULL);
 }
 
+struct weston_view *
+get_default_view(struct weston_surface *surface)
+{
+	struct ivi_shell_surface *shsurf;
+	struct weston_view *view;
+
+	if (!surface || wl_list_empty(&surface->views))
+		return NULL;
+
+	shsurf = get_ivi_shell_surface(surface);
+	if (shsurf && shsurf->layout_surface) {
+		view = shsurf->shell->ivi_layout->get_weston_view(shsurf->layout_surface);
+		if (view)
+			return view;
+	}
+
+	wl_list_for_each(view, &surface->views, surface_link) {
+		if (weston_view_is_mapped(view))
+			return view;
+	}
+
+	return container_of(surface->views.next,
+			    struct weston_view, surface_link);
+}
+
 /*
  * Called through the compositor's destroy signal.
  */
@@ -385,6 +410,8 @@ shell_destroy(struct wl_listener *listener, void *data)
 		container_of(listener, struct ivi_shell, destroy_listener);
 	struct ivi_shell_surface *ivisurf, *next;
 
+	input_panel_destroy(shell);
+
 	wl_list_for_each_safe(ivisurf, next, &shell->ivi_surface_list, link) {
 		wl_list_remove(&ivisurf->link);
 		free(ivisurf);
@@ -400,6 +427,7 @@ init_ivi_shell(struct weston_compositor *compositor, struct ivi_shell *shell)
 
 	wl_list_init(&shell->ivi_surface_list);
 
+	weston_layer_init(&shell->input_panel_layer, NULL);
 }
 
 static int
@@ -474,6 +502,8 @@ module_init(struct weston_compositor *compositor,
 	shell->destroy_listener.notify = shell_destroy;
 	wl_signal_add(&compositor->destroy_signal, &shell->destroy_listener);
 
+	if (input_panel_setup(shell) < 0)
+		return -1;
 
 	if (wl_global_create(compositor->wl_display,
 			     &ivi_application_interface, 1,
diff --git a/ivi-shell/ivi-shell.h b/ivi-shell/ivi-shell.h
index 1283a00..3441119 100644
--- a/ivi-shell/ivi-shell.h
+++ b/ivi-shell/ivi-shell.h
@@ -34,4 +34,32 @@ struct ivi_shell
 	struct wl_list ivi_surface_list; /* struct ivi_shell_surface::link */
 
 	struct ivi_layout_interface *ivi_layout;
+
+	struct wl_listener show_input_panel_listener;
+	struct wl_listener hide_input_panel_listener;
+	struct wl_listener update_input_panel_listener;
+
+	struct weston_layer input_panel_layer;
+
+	bool locked;
+	bool showing_input_panels;
+
+	struct {
+		struct weston_surface *surface;
+		pixman_box32_t cursor_rectangle;
+	} text_input;
+
+	struct {
+		struct wl_resource *binding;
+		struct wl_list surfaces;
+	} input_panel;
 };
+
+struct weston_view *
+get_default_view(struct weston_surface *surface);
+
+int
+input_panel_setup(struct ivi_shell *shell);
+
+void
+input_panel_destroy(struct ivi_shell *shell);
diff --git a/ivi-shell/weston.ini.in b/ivi-shell/weston.ini.in
index f8ef12f..050b806 100644
--- a/ivi-shell/weston.ini.in
+++ b/ivi-shell/weston.ini.in
@@ -32,6 +32,9 @@ home-id=1007
 workspace-background-color=0x99000000
 workspace-background-id=2001
 
+[input-method]
+path=@libexecdir@/weston-keyboard
+
 [ivi-launcher]
 workspace-id=0
 icon-id=4001
-- 
1.7.9.5