Commit 8775e876 authored by Alexander Mikhaylenko's avatar Alexander Mikhaylenko Committed by Guido Gunther
Browse files

notification-banner: Support swipe-to-hide

Use a vertical swipe up to dismiss the banner without closing it.
parent 48e0e630
Pipeline #62242 passed with stages
in 59 minutes and 49 seconds
......@@ -12,6 +12,7 @@
#include "notification-banner.h"
#include "notification-frame.h"
#include "shell.h"
#include "swipe-away-bin.h"
#include "util.h"
#define HANDY_USE_UNSTABLE_API
......@@ -34,14 +35,10 @@ static GParamSpec *props[LAST_PROP];
struct _PhoshNotificationBanner {
PhoshLayerSurface parent;
PhoshSwipeAwayBin *hide_bin;
PhoshNotification *notification;
gulong handler_expired;
gulong handler_closed;
struct {
double progress;
gint64 last_frame;
} animation;
};
typedef struct _PhoshNotificationBanner PhoshNotificationBanner;
......@@ -57,6 +54,16 @@ clear_handler (PhoshNotificationBanner *self)
}
static void
removed (PhoshNotificationBanner *self)
{
clear_handler (self);
/* Close the banner */
gtk_widget_destroy (GTK_WIDGET (self));
}
static void
expired (PhoshNotification *notification,
PhoshNotificationBanner *self)
......@@ -64,10 +71,7 @@ expired (PhoshNotification *notification,
g_return_if_fail (PHOSH_IS_NOTIFICATION_BANNER (self));
g_return_if_fail (PHOSH_IS_NOTIFICATION (notification));
clear_handler (self);
/* Close the banner */
gtk_widget_destroy (GTK_WIDGET (self));
phosh_swipe_away_bin_remove (self->hide_bin);
}
......@@ -79,10 +83,7 @@ closed (PhoshNotification *notification,
g_return_if_fail (PHOSH_IS_NOTIFICATION_BANNER (self));
g_return_if_fail (PHOSH_IS_NOTIFICATION (notification));
clear_handler (self);
/* Close the banner */
gtk_widget_destroy (GTK_WIDGET (self));
removed (self);
}
......@@ -91,6 +92,7 @@ phosh_notification_banner_set_notification (PhoshNotificationBanner *self,
PhoshNotification *notification)
{
GtkWidget *content;
int height;
g_set_object (&self->notification, notification);
......@@ -98,7 +100,11 @@ phosh_notification_banner_set_notification (PhoshNotificationBanner *self,
phosh_notification_frame_set_reserve_size (PHOSH_NOTIFICATION_FRAME (content), TRUE);
phosh_notification_frame_bind_notification (PHOSH_NOTIFICATION_FRAME (content),
self->notification);
gtk_container_add (GTK_CONTAINER (self), content);
g_object_get (self, "height", &height, NULL);
gtk_widget_set_margin_top (content, height);
gtk_container_add (GTK_CONTAINER (self->hide_bin), content);
self->handler_expired = g_signal_connect (self->notification, "expired",
G_CALLBACK (expired), self);
......@@ -161,65 +167,14 @@ phosh_notification_banner_finalize (GObject *object)
}
static void
phosh_notification_banner_slide (PhoshNotificationBanner *self)
{
int margin;
int height;
double progress = hdy_ease_out_cubic (self->animation.progress);
progress = 1.0 - progress;
gtk_window_get_size (GTK_WINDOW (self), NULL, &height);
margin = (height - 300) * progress;
phosh_layer_surface_set_margins (PHOSH_LAYER_SURFACE (self), margin, 0, 0, 0);
phosh_layer_surface_wl_surface_commit (PHOSH_LAYER_SURFACE (self));
}
static gboolean
animate_down_cb (GtkWidget *widget,
GdkFrameClock *frame_clock,
gpointer user_data)
{
gint64 time;
gboolean finished = FALSE;
PhoshNotificationBanner *self = PHOSH_NOTIFICATION_BANNER (widget);
time = gdk_frame_clock_get_frame_time (frame_clock) - self->animation.last_frame;
if (self->animation.last_frame < 0) {
time = 0;
}
self->animation.progress += 0.06666 * time / 16666.00;
self->animation.last_frame = gdk_frame_clock_get_frame_time (frame_clock);
if (self->animation.progress >= 1.0) {
finished = TRUE;
self->animation.progress = 1.0;
}
phosh_notification_banner_slide (self);
return finished ? G_SOURCE_REMOVE : G_SOURCE_CONTINUE;
}
static void
phosh_notification_banner_show (GtkWidget *widget)
{
PhoshNotificationBanner *self = PHOSH_NOTIFICATION_BANNER (widget);
gboolean enable_animations;
enable_animations = hdy_get_enable_animations (GTK_WIDGET (self));
self->animation.last_frame = -1;
self->animation.progress = enable_animations ? 0.0 : 1.0;
gtk_widget_add_tick_callback (GTK_WIDGET (self), animate_down_cb, NULL, NULL);
GTK_WIDGET_CLASS (phosh_notification_banner_parent_class)->show (widget);
phosh_swipe_away_bin_reveal (self->hide_bin);
}
......@@ -254,6 +209,9 @@ phosh_notification_banner_class_init (PhoshNotificationBannerClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/sm/puri/phosh/ui/notification-banner.ui");
gtk_widget_class_bind_template_child (widget_class, PhoshNotificationBanner, hide_bin);
gtk_widget_class_bind_template_callback (widget_class, removed);
gtk_widget_class_set_css_name (widget_class, "phosh-notification-banner");
}
......@@ -261,9 +219,11 @@ phosh_notification_banner_class_init (PhoshNotificationBannerClass *klass)
static void
phosh_notification_banner_init (PhoshNotificationBanner *self)
{
self->animation.progress = 0.0;
g_type_ensure (PHOSH_TYPE_SWIPE_AWAY_BIN);
gtk_widget_init_template (GTK_WIDGET (self));
phosh_swipe_away_bin_hide (self->hide_bin);
}
......@@ -278,7 +238,6 @@ phosh_notification_banner_new (PhoshNotification *notification)
return g_object_new (PHOSH_TYPE_NOTIFICATION_BANNER,
"notification", notification,
/* layer surface */
"margin-top", -300,
"layer-shell", phosh_wayland_get_zwlr_layer_shell_v1 (wl),
"anchor", ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP,
"width", MIN (width, 450) * 3,
......
......@@ -3,8 +3,16 @@
<requires lib="gtk+" version="3.20"/>
<template class="PhoshNotificationBanner" parent="PhoshLayerSurface">
<property name="height">50</property>
<property name="margin-top">-50</property>
<property name="kbd-interactivity">False</property>
<property name="exclusive-zone">0</property>
<property name="namespace">phosh notification</property>
<child>
<object class="PhoshSwipeAwayBin" id="hide_bin">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<signal name="removed" handler="removed" swapped="true"/>
</object>
</child>
</template>
</interface>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment