animation, shell: add kbd focus change animation

When enabled, this will make all but the keyboard-focused window dim.
Also the background gets dimmed, if there are any windows open. The
panel is not dimmed.

When the keyboard focus changes, the change in dimming is animated.

The dimming is implemented with transparent solid-color surfaces, two at
most. The net effect of two overlapping dim surfaces is kept constant
during animations (stable fade animation).

There is a new weston.ini option "focus-animation", that defaults to
none, and can be set to "dim-layer" to enable the focus change
animation.

[pq: Sliced, squashed, and rebased the patch series. Fixed surface alpha
interaction with the switcher. Wrote the commit message.]

[pochu: rebased, ported to weston_view]
diff --git a/src/animation.c b/src/animation.c
index c71b506..8739f19 100644
--- a/src/animation.c
+++ b/src/animation.c
@@ -127,9 +127,10 @@
 	weston_view_animation_frame_func_t reset;
 	weston_view_animation_done_func_t done;
 	void *data;
+	void *private;
 };
 
-static void
+WL_EXPORT void
 weston_view_animation_destroy(struct weston_view_animation *animation)
 {
 	wl_list_remove(&animation->animation.link);
@@ -185,7 +186,8 @@
 			  weston_view_animation_frame_func_t frame,
 			  weston_view_animation_frame_func_t reset,
 			  weston_view_animation_done_func_t done,
-			  void *data)
+			  void *data,
+			  void *private)
 {
 	struct weston_view_animation *animation;
 
@@ -200,6 +202,7 @@
 	animation->data = data;
 	animation->start = start;
 	animation->stop = stop;
+	animation->private = private;
 	weston_matrix_init(&animation->transform.matrix);
 	wl_list_insert(&view->geometry.transformation_list,
 		       &animation->transform.link);
@@ -257,7 +260,7 @@
 
 	zoom = weston_view_animation_run(view, start, stop,
 					 zoom_frame, reset_alpha,
-					 done, data);
+					 done, data, NULL);
 
 	weston_spring_init(&zoom->spring, 300.0, start, stop);
 	zoom->spring.friction = 1400;
@@ -286,7 +289,7 @@
 
 	fade = weston_view_animation_run(view, 0, end,
 					 fade_frame, reset_alpha,
-					 done, data);
+					 done, data, NULL);
 
 	weston_spring_init(&fade->spring, k, start, end);
 
@@ -305,6 +308,46 @@
 }
 
 static void
+stable_fade_frame(struct weston_view_animation *animation)
+{
+	struct weston_view *back_view;
+
+	if (animation->spring.current > 0.999)
+		animation->view->alpha = 1;
+	else if (animation->spring.current < 0.001 )
+		animation->view->alpha = 0;
+	else
+		animation->view->alpha = animation->spring.current;
+
+	back_view = (struct weston_view *) animation->private;
+	back_view->alpha =
+		(animation->spring.target - animation->view->alpha) /
+		(1.0 - animation->view->alpha);
+	weston_view_geometry_dirty(back_view);
+}
+
+WL_EXPORT struct weston_view_animation *
+weston_stable_fade_run(struct weston_view *front_view, float start,
+		struct weston_view *back_view, float end,
+		weston_view_animation_done_func_t done, void *data)
+{
+	struct weston_view_animation *fade;
+
+	fade = weston_view_animation_run(front_view, 0, 0,
+					    stable_fade_frame, NULL,
+					    done, data, back_view);
+
+
+	weston_spring_init(&fade->spring, 400, start, end);
+	fade->spring.friction = 1150;
+
+	front_view->alpha = start;
+	back_view->alpha = end;
+
+	return fade;
+}
+
+static void
 slide_frame(struct weston_view_animation *animation)
 {
 	float scale;
@@ -324,7 +367,7 @@
 
 	animation = weston_view_animation_run(view, start, stop,
 					      slide_frame, NULL, done,
-					      data);
+					      data, NULL);
 	if (!animation)
 		return NULL;