Browse Source

yutani: add new animation for dialogs (inspired by gnome shell)

K. Lange 2 years ago
parent
commit
6748a76146
5 changed files with 49 additions and 13 deletions
  1. 1 1
      apps/about.c
  2. 30 11
      apps/compositor.c
  3. 1 1
      apps/showdialog.c
  4. 16 0
      base/usr/include/toaru/yutani-server.h
  5. 1 0
      base/usr/include/toaru/yutani.h

+ 1 - 1
apps/about.c

@@ -111,7 +111,7 @@ int main(int argc, char * argv[]) {
 	struct decor_bounds bounds;
 	decor_get_bounds(NULL, &bounds);
 
-	window = yutani_window_create(yctx, width + bounds.width, height + bounds.height);
+	window = yutani_window_create_flags(yctx, width + bounds.width, height + bounds.height, YUTANI_WINDOW_FLAG_DIALOG_ANIMATION);
 	req_center_x = yctx->display_width / 2;
 	req_center_y = yctx->display_height / 2;
 

+ 30 - 11
apps/compositor.c

@@ -376,6 +376,15 @@ static yutani_server_window_t * get_focused(yutani_globals_t * yg) {
 	return yg->bottom_z;
 }
 
+static int yutani_pick_animation(uint32_t flags, int direction) {
+	if (flags & YUTANI_WINDOW_FLAG_DIALOG_ANIMATION) {
+		return (direction == 0) ? YUTANI_EFFECT_SQUEEZE_IN : YUTANI_EFFECT_SQUEEZE_OUT;
+	}
+
+	return (direction == 0) ? YUTANI_EFFECT_FADE_IN : YUTANI_EFFECT_FADE_OUT;
+}
+
+
 /**
  * Create a server window object.
  *
@@ -408,7 +417,7 @@ static yutani_server_window_t * server_window_create(yutani_globals_t * yg, int
 	win->client_offsets[4] = 0;
 	win->client_length  = 0;
 	win->client_strings = NULL;
-	win->anim_mode = YUTANI_EFFECT_FADE_IN;
+	win->anim_mode = yutani_pick_animation(flags, 0);
 	win->anim_start = yutani_current_time(yg);
 	win->alpha_threshold = 0;
 	win->show_mouse = 1;
@@ -711,7 +720,7 @@ static int yutani_blit_window(yutani_globals_t * yg, yutani_server_window_t * wi
 		int frame = yutani_time_since(yg, window->anim_start);
 		if (frame >= yutani_animation_lengths[window->anim_mode]) {
 			/* XXX handle animation-end things like cleanup of closing windows */
-			if (window->anim_mode == YUTANI_EFFECT_FADE_OUT) {
+			if (yutani_is_closing_animation[window->anim_mode]) {
 				list_insert(yg->windows_to_remove, window);
 				goto draw_finish;
 			}
@@ -720,24 +729,34 @@ static int yutani_blit_window(yutani_globals_t * yg, yutani_server_window_t * wi
 			goto draw_window;
 		} else {
 			switch (window->anim_mode) {
+				case YUTANI_EFFECT_SQUEEZE_OUT:
 				case YUTANI_EFFECT_FADE_OUT:
 					{
 						frame = yutani_animation_lengths[window->anim_mode] - frame;
 					}
+				case YUTANI_EFFECT_SQUEEZE_IN:
 				case YUTANI_EFFECT_FADE_IN:
 					{
 						double time_diff = ((double)frame / (float)yutani_animation_lengths[window->anim_mode]);
-						double x = 0.75 + time_diff * 0.25;
-						int t_x = (window->width * (1.0 - x)) / 2;
-						int t_y = (window->height * (1.0 - x)) / 2;
 
-						double opacity = time_diff * (double)(window->opacity) / 255.0;
+						if (window->server_flags & YUTANI_WINDOW_FLAG_DIALOG_ANIMATION) {
+							double x = time_diff;
+							int t_y = (window->height * (1.0 -x)) / 2;
 
-						if (!yutani_window_is_top(yg, window) && !yutani_window_is_bottom(yg, window) &&
-							!(window->server_flags & YUTANI_WINDOW_FLAG_ALT_ANIMATION)) {
-							draw_sprite_scaled_alpha(yg->backend_ctx, &_win_sprite, window->x + t_x, window->y + t_y, window->width * x, window->height * x, opacity);
+							draw_sprite_scaled(yg->backend_ctx, &_win_sprite, window->x, window->y + t_y, window->width, window->height * x);
 						} else {
-							draw_sprite_alpha(yg->backend_ctx, &_win_sprite, window->x, window->y, opacity);
+							double x = 0.75 + time_diff * 0.25;
+							int t_x = (window->width * (1.0 - x)) / 2;
+							int t_y = (window->height * (1.0 - x)) / 2;
+
+							double opacity = time_diff * (double)(window->opacity) / 255.0;
+
+							if (!yutani_window_is_top(yg, window) && !yutani_window_is_bottom(yg, window) &&
+									!(window->server_flags & YUTANI_WINDOW_FLAG_ALT_ANIMATION)) {
+								draw_sprite_scaled_alpha(yg->backend_ctx, &_win_sprite, window->x + t_x, window->y + t_y, window->width * x, window->height * x, opacity);
+							} else {
+								draw_sprite_alpha(yg->backend_ctx, &_win_sprite, window->x, window->y, opacity);
+							}
 						}
 					}
 					break;
@@ -1225,7 +1244,7 @@ static void mark_window(yutani_globals_t * yg, yutani_server_window_t * window)
  * Set a window as closed. It will be removed after rendering has completed.
  */
 static void window_mark_for_close(yutani_globals_t * yg, yutani_server_window_t * w) {
-	w->anim_mode = YUTANI_EFFECT_FADE_OUT;
+	w->anim_mode = yutani_pick_animation(w->server_flags, 1);
 	w->anim_start = yutani_current_time(yg);
 }
 

+ 1 - 1
apps/showdialog.c

@@ -142,7 +142,7 @@ int main(int argc, char * argv[]) {
 	struct decor_bounds bounds;
 	decor_get_bounds(NULL, &bounds);
 
-	window = yutani_window_create(yctx, width + bounds.width, height + bounds.height);
+	window = yutani_window_create_flags(yctx, width + bounds.width, height + bounds.height, YUTANI_WINDOW_FLAG_DIALOG_ANIMATION);
 	req_center_x = yctx->display_width / 2;
 	req_center_y = yctx->display_height / 2;
 

+ 16 - 0
base/usr/include/toaru/yutani-server.h

@@ -48,6 +48,10 @@ typedef enum {
 	/* XXX: Are these used? */
 	YUTANI_EFFECT_MINIMIZE,
 	YUTANI_EFFECT_UNMINIMIZE,
+
+	/* Dialog animations, faster than the fades */
+	YUTANI_EFFECT_SQUEEZE_IN,
+	YUTANI_EFFECT_SQUEEZE_OUT,
 } yutani_effect;
 
 /* Animation lengths */
@@ -57,6 +61,18 @@ static int yutani_animation_lengths[] = {
 	200, /* Fade Out */
 	0,   /* Minimize */
 	0,   /* Unminimized */
+	100, /* Squeeze in */
+	100, /* Squeeze out */
+};
+
+static int yutani_is_closing_animation[] = {
+	0,
+	0,
+	1,
+	0,
+	0,
+	0,
+	1,
 };
 
 /* Debug Options */

+ 1 - 0
base/usr/include/toaru/yutani.h

@@ -459,6 +459,7 @@ struct yutani_msg_clipboard {
 #define YUTANI_WINDOW_FLAG_DISALLOW_DRAG    (1 << 1)
 #define YUTANI_WINDOW_FLAG_DISALLOW_RESIZE  (1 << 2)
 #define YUTANI_WINDOW_FLAG_ALT_ANIMATION    (1 << 3)
+#define YUTANI_WINDOW_FLAG_DIALOG_ANIMATION (1 << 4)
 
 /* YUTANI_SPECIAL_REQUEST
  *