Verified Commit e0702f49 authored by Sebastian Krzyszkowiak's avatar Sebastian Krzyszkowiak
Browse files

PhoshHome: (un)folding animation proof-of-concept

parent ea777fb7
Pipeline #26977 passed with stages
in 4 minutes and 58 seconds
......@@ -46,6 +46,9 @@ struct _PhoshHome
GtkWidget *btn_osk;
GtkWidget *favorites;
gfloat fold;
gint64 animation;
PhoshHomeState state;
};
G_DEFINE_TYPE(PhoshHome, phosh_home, PHOSH_TYPE_LAYER_SURFACE);
......@@ -219,6 +222,45 @@ phosh_home_new (struct zwlr_layer_shell_v1 *layer_shell,
NULL);
}
static gboolean animate(GtkWidget *widget,
GdkFrameClock *frame_clock,
gpointer user_data) {
int height;
gboolean ret;
gint64 time;
PhoshHome *self = PHOSH_HOME(widget);
time = gdk_frame_clock_get_frame_time(frame_clock) - self->animation;
if (time < 0) {
time = 0;
}
self->animation = gdk_frame_clock_get_frame_time(frame_clock);
if (self->state == PHOSH_HOME_STATE_UNFOLDED) {
self->fold -= 0.1 * time / 16666.00;
} else {
self->fold += 0.1 * time / 16666.00;
}
ret = G_SOURCE_CONTINUE;
if (self->fold > 1.0) {
self->fold = 1.0;
ret = G_SOURCE_REMOVE;
}
if (self->fold < 0.0) {
self->fold = 0.0;
ret = G_SOURCE_REMOVE;
}
g_object_get(PHOSH_LAYER_SURFACE(self), "height", &height, NULL);
phosh_layer_surface_set_margins(PHOSH_LAYER_SURFACE (self), 0, 0, (-height + PHOSH_HOME_BUTTON_HEIGHT) * self->fold, 0);
phosh_layer_surface_set_exclusive_zone(PHOSH_LAYER_SURFACE (self), height * self->fold + PHOSH_HOME_BUTTON_HEIGHT * (1.0 - self->fold)); // "The exclusive zone includes the margin."
// TODO: is exclusive zone calculated properly for negative margins?
gtk_widget_queue_draw(GTK_WIDGET(self));
return ret;
}
/**
* phosh_home_set_state:
*
......@@ -239,11 +281,15 @@ phosh_home_set_state (PhoshHome *self, PhoshHomeState state)
g_debug ("Setting state to %s", g_enum_to_string (PHOSH_TYPE_HOME_STATE, state));
phosh_shell_get_usable_area (phosh_shell_get_default (), NULL, NULL, &width, &height);
/* We don't change the exclusive zone since we don't want to push all clients upward */
if (state == PHOSH_HOME_STATE_UNFOLDED)
height = PHOSH_HOME_BUTTON_HEIGHT + height;
else
height = PHOSH_HOME_BUTTON_HEIGHT;
height += PHOSH_HOME_BUTTON_HEIGHT;
self->animation = g_get_monotonic_time();
gtk_widget_add_tick_callback(GTK_WIDGET(self), animate, NULL, NULL);
phosh_layer_surface_set_margins(PHOSH_LAYER_SURFACE (self), 0, 0, (-height + PHOSH_HOME_BUTTON_HEIGHT) * self->fold, 0);
phosh_layer_surface_set_exclusive_zone(PHOSH_LAYER_SURFACE (self), height * self->fold + PHOSH_HOME_BUTTON_HEIGHT * (1.0 - self->fold)); // "The exclusive zone includes the margin."
// TODO: is exclusive zone calculated properly for negative margins?
phosh_layer_surface_set_size (PHOSH_LAYER_SURFACE (self), width, height);
......
......@@ -20,6 +20,10 @@ enum {
PHOSH_LAYER_SURFACE_PROP_LAYER,
PHOSH_LAYER_SURFACE_PROP_KBD_INTERACTIVITY,
PHOSH_LAYER_SURFACE_PROP_EXCLUSIVE_ZONE,
PHOSH_LAYER_SURFACE_PROP_MARGIN_TOP,
PHOSH_LAYER_SURFACE_PROP_MARGIN_BOTTOM,
PHOSH_LAYER_SURFACE_PROP_MARGIN_LEFT,
PHOSH_LAYER_SURFACE_PROP_MARGIN_RIGHT,
PHOSH_LAYER_SURFACE_PROP_LAYER_WIDTH,
PHOSH_LAYER_SURFACE_PROP_LAYER_HEIGHT,
PHOSH_LAYER_SURFACE_PROP_NAMESPACE,
......@@ -43,6 +47,8 @@ typedef struct {
guint layer;
gboolean kbd_interactivity;
gint exclusive_zone;
gint margin_top, margin_bottom;
gint margin_left, margin_right;
gint width, height;
gchar *namespace;
struct zwlr_layer_shell_v1 *layer_shell;
......@@ -112,6 +118,18 @@ phosh_layer_surface_set_property (GObject *object,
case PHOSH_LAYER_SURFACE_PROP_EXCLUSIVE_ZONE:
priv->exclusive_zone = g_value_get_int (value);
break;
case PHOSH_LAYER_SURFACE_PROP_MARGIN_TOP:
priv->margin_top = g_value_get_int (value);
break;
case PHOSH_LAYER_SURFACE_PROP_MARGIN_BOTTOM:
priv->margin_bottom = g_value_get_int (value);
break;
case PHOSH_LAYER_SURFACE_PROP_MARGIN_LEFT:
priv->margin_left = g_value_get_int (value);
break;
case PHOSH_LAYER_SURFACE_PROP_MARGIN_RIGHT:
priv->margin_right = g_value_get_int (value);
break;
case PHOSH_LAYER_SURFACE_PROP_LAYER_WIDTH:
priv->width = g_value_get_uint (value);
break;
......@@ -157,6 +175,18 @@ phosh_layer_surface_get_property (GObject *object,
case PHOSH_LAYER_SURFACE_PROP_EXCLUSIVE_ZONE:
g_value_set_int (value, priv->exclusive_zone);
break;
case PHOSH_LAYER_SURFACE_PROP_MARGIN_TOP:
g_value_set_int (value, priv->margin_top);
break;
case PHOSH_LAYER_SURFACE_PROP_MARGIN_BOTTOM:
g_value_set_int (value, priv->margin_bottom);
break;
case PHOSH_LAYER_SURFACE_PROP_MARGIN_LEFT:
g_value_set_int (value, priv->margin_left);
break;
case PHOSH_LAYER_SURFACE_PROP_MARGIN_RIGHT:
g_value_set_int (value, priv->margin_right);
break;
case PHOSH_LAYER_SURFACE_PROP_LAYER_WIDTH:
g_value_set_uint (value, priv->width);
break;
......@@ -215,6 +245,11 @@ on_phosh_layer_surface_mapped (PhoshLayerSurface *self, gpointer unused)
zwlr_layer_surface_v1_set_exclusive_zone(priv->layer_surface, priv->exclusive_zone);
zwlr_layer_surface_v1_set_size(priv->layer_surface, priv->width, priv->height);
zwlr_layer_surface_v1_set_anchor(priv->layer_surface, priv->anchor);
zwlr_layer_surface_v1_set_margin(priv->layer_surface,
priv->margin_top,
priv->margin_right,
priv->margin_bottom,
priv->margin_left);
zwlr_layer_surface_v1_set_keyboard_interactivity(priv->layer_surface, priv->kbd_interactivity);
zwlr_layer_surface_v1_add_listener(priv->layer_surface,
&layer_surface_listener,
......@@ -338,6 +373,46 @@ phosh_layer_surface_class_init (PhoshLayerSurfaceClass *klass)
0,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PHOSH_LAYER_SURFACE_PROP_MARGIN_LEFT] =
g_param_spec_int (
"margin-left",
"Left margin",
"Distance away from the left anchor point",
G_MININT,
G_MAXINT,
0,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PHOSH_LAYER_SURFACE_PROP_MARGIN_RIGHT] =
g_param_spec_int (
"margin-right",
"Right margin",
"Distance away from the right anchor point",
G_MININT,
G_MAXINT,
0,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PHOSH_LAYER_SURFACE_PROP_MARGIN_TOP] =
g_param_spec_int (
"margin-top",
"Top margin",
"Distance away from the top anchor point",
G_MININT,
G_MAXINT,
0,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PHOSH_LAYER_SURFACE_PROP_MARGIN_BOTTOM] =
g_param_spec_int (
"margin-bottom",
"Bottom margin",
"Distance away from the bottom anchor point",
G_MININT,
G_MAXINT,
0,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PHOSH_LAYER_SURFACE_PROP_LAYER_WIDTH] =
g_param_spec_uint (
"width",
......@@ -356,7 +431,7 @@ phosh_layer_surface_class_init (PhoshLayerSurfaceClass *klass)
0,
G_MAXUINT,
0,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PHOSH_LAYER_SURFACE_PROP_NAMESPACE] =
g_param_spec_string (
......@@ -457,3 +532,42 @@ phosh_layer_surface_set_size(PhoshLayerSurface *self, gint width, gint height)
zwlr_layer_surface_v1_set_size(priv->layer_surface, priv->width, priv->height);
}
/**
* phosh_layer_surface_set_margins:
*
* Set anchor margins of a layer surface.
*/
void
phosh_layer_surface_set_margins(PhoshLayerSurface *self, gint top, gint right, gint bottom, gint left)
{
PhoshLayerSurfacePrivate *priv;
g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self));
priv = phosh_layer_surface_get_instance_private (self);
priv->margin_top = top;
priv->margin_left = left;
priv->margin_right = right;
priv->margin_bottom = bottom;
zwlr_layer_surface_v1_set_margin(priv->layer_surface, top, right, bottom, left);
}
/**
* phosh_layer_surface_set_exclusive_zone:
*
* Set exclusive zone of a layer surface.
*/
void
phosh_layer_surface_set_exclusive_zone(PhoshLayerSurface *self, gint zone)
{
PhoshLayerSurfacePrivate *priv;
g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self));
priv = phosh_layer_surface_get_instance_private (self);
priv->exclusive_zone = zone;
zwlr_layer_surface_v1_set_exclusive_zone(priv->layer_surface, zone);
}
......@@ -34,3 +34,10 @@ struct wl_surface *phosh_layer_surface_get_wl_surface(PhoshLayerS
void phosh_layer_surface_set_size(PhoshLayerSurface *self,
gint width,
gint height);
void phosh_layer_surface_set_margins(PhoshLayerSurface *self,
gint top,
gint right,
gint bottom,
gint left);
void phosh_layer_surface_set_exclusive_zone(PhoshLayerSurface *self,
gint zone);
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