diff --git a/src/layersurface.c b/src/layersurface.c index 11deb048f8e1184144c7dc1a24347fb440ca7dd8..e652ecc010bf1f1abf532809d34fd9f858461ce4 100644 --- a/src/layersurface.c +++ b/src/layersurface.c @@ -24,6 +24,8 @@ enum { PHOSH_LAYER_SURFACE_PROP_MARGIN_BOTTOM, PHOSH_LAYER_SURFACE_PROP_MARGIN_LEFT, PHOSH_LAYER_SURFACE_PROP_MARGIN_RIGHT, + PHOSH_LAYER_SURFACE_PROP_REQUESTED_WIDTH, + PHOSH_LAYER_SURFACE_PROP_REQUESTED_HEIGHT, PHOSH_LAYER_SURFACE_PROP_LAYER_WIDTH, PHOSH_LAYER_SURFACE_PROP_LAYER_HEIGHT, PHOSH_LAYER_SURFACE_PROP_NAMESPACE, @@ -50,6 +52,7 @@ typedef struct { gint margin_top, margin_bottom; gint margin_left, margin_right; gint width, height; + guint configured_width, configured_height; gchar *namespace; struct zwlr_layer_shell_v1 *layer_shell; struct wl_output *wl_output; @@ -64,10 +67,23 @@ static void layer_surface_configure(void *data, uint32_t height) { PhoshLayerSurface *self = data; + PhoshLayerSurfacePrivate *priv; + g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self)); + priv = phosh_layer_surface_get_instance_private (self); gtk_window_resize (GTK_WINDOW (self), width, height); zwlr_layer_surface_v1_ack_configure(surface, serial); + if (priv->configured_height != height) { + priv->configured_height = height; + g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_LAYER_HEIGHT]); + } + + if (priv->configured_width != width) { + priv->configured_width = width; + g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_LAYER_WIDTH]); + } + g_debug("Configured %p", self); g_signal_emit (self, signals[CONFIGURED], 0); } @@ -86,8 +102,8 @@ static void layer_surface_closed (void *data, } static struct zwlr_layer_surface_v1_listener layer_surface_listener = { - .configure = layer_surface_configure, - .closed = layer_surface_closed, + .configure = layer_surface_configure, + .closed = layer_surface_closed, }; static void @@ -147,9 +163,15 @@ phosh_layer_surface_set_property (GObject *object, priv->margin_left); break; case PHOSH_LAYER_SURFACE_PROP_LAYER_WIDTH: - priv->width = g_value_get_uint (value); + priv->configured_width = g_value_get_uint (value); break; case PHOSH_LAYER_SURFACE_PROP_LAYER_HEIGHT: + priv->configured_height = g_value_get_uint (value); + break; + case PHOSH_LAYER_SURFACE_PROP_REQUESTED_WIDTH: + priv->width = g_value_get_uint (value); + break; + case PHOSH_LAYER_SURFACE_PROP_REQUESTED_HEIGHT: priv->height = g_value_get_uint (value); break; case PHOSH_LAYER_SURFACE_PROP_NAMESPACE: @@ -204,9 +226,15 @@ phosh_layer_surface_get_property (GObject *object, g_value_set_int (value, priv->margin_right); break; case PHOSH_LAYER_SURFACE_PROP_LAYER_WIDTH: - g_value_set_uint (value, priv->width); + g_value_set_uint (value, priv->configured_width); break; case PHOSH_LAYER_SURFACE_PROP_LAYER_HEIGHT: + g_value_set_uint (value, priv->configured_height); + break; + case PHOSH_LAYER_SURFACE_PROP_REQUESTED_WIDTH: + g_value_set_uint (value, priv->width); + break; + case PHOSH_LAYER_SURFACE_PROP_REQUESTED_HEIGHT: g_value_set_uint (value, priv->height); break; case PHOSH_LAYER_SURFACE_PROP_NAMESPACE: @@ -242,6 +270,7 @@ on_phosh_layer_surface_mapped (PhoshLayerSurface *self, gpointer unused) { PhoshLayerSurfacePrivate *priv; GdkWindow *gdk_window; + guint wanted_width = 0, wanted_height = 0; g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self)); priv = phosh_layer_surface_get_instance_private (self); @@ -259,7 +288,20 @@ on_phosh_layer_surface_mapped (PhoshLayerSurface *self, gpointer unused) priv->layer, priv->namespace); 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); + + // Take into account that if the user wanted the compositor to choose a value, + // then it should be allowed again + // but at the same time, if an allocation was done with a specific value, + // then favor not resizing. + if (priv->width != 0) { + wanted_width = priv->configured_width; + } + + if (priv->height != 0) { + wanted_height = priv->configured_height; + } + + zwlr_layer_surface_v1_set_size(priv->layer_surface, wanted_width, wanted_height); zwlr_layer_surface_v1_set_anchor(priv->layer_surface, priv->anchor); zwlr_layer_surface_v1_set_margin(priv->layer_surface, priv->margin_top, @@ -431,25 +473,45 @@ phosh_layer_surface_class_init (PhoshLayerSurfaceClass *klass) 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); - props[PHOSH_LAYER_SURFACE_PROP_LAYER_WIDTH] = + props[PHOSH_LAYER_SURFACE_PROP_REQUESTED_WIDTH] = g_param_spec_uint ( "width", "Width", - "The width of the layer surface", + "The requested width of the layer surface", 0, G_MAXUINT, 0, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); - props[PHOSH_LAYER_SURFACE_PROP_LAYER_HEIGHT] = + props[PHOSH_LAYER_SURFACE_PROP_REQUESTED_HEIGHT] = g_param_spec_uint ( "height", "Height", - "The height of the layer surface", + "The requested height of the layer surface", 0, G_MAXUINT, 0, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); + + props[PHOSH_LAYER_SURFACE_PROP_LAYER_WIDTH] = + g_param_spec_uint ( + "configured-width", + "Configured width", + "The width of the layer surface set by the compositor", + 0, + G_MAXUINT, + 0, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); + + props[PHOSH_LAYER_SURFACE_PROP_LAYER_HEIGHT] = + g_param_spec_uint ( + "configured-height", + "Configured height", + "The height of the layer surface set by the compositor", + 0, + G_MAXUINT, + 0, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); props[PHOSH_LAYER_SURFACE_PROP_NAMESPACE] = g_param_spec_string ( @@ -529,7 +591,8 @@ phosh_layer_surface_get_wl_surface(PhoshLayerSurface *self) /** * phosh_layer_surface_set_size: * - * Set the size of a layer surface. A value of '-1' indicates 'use old value' + * Set the size of a layer surface. + * A value of '-1' indicates 'use configured value' */ void phosh_layer_surface_set_size(PhoshLayerSurface *self, gint width, gint height) @@ -539,16 +602,28 @@ phosh_layer_surface_set_size(PhoshLayerSurface *self, gint width, gint height) g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self)); priv = phosh_layer_surface_get_instance_private (self); - if (priv->height == height && priv->width == width) - return; + if (width == -1) + width = priv->configured_width; + + if (height == -1) + height = priv->configured_height; - if (width != -1) + if (priv->width != width) { priv->width = width; + g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_REQUESTED_WIDTH]); + } - if (height != -1) + if (priv->height != height) { priv->height = height; + g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_REQUESTED_HEIGHT]); + } + + if (priv->configured_height == height && priv->configured_width == width) + return; - zwlr_layer_surface_v1_set_size(priv->layer_surface, priv->width, priv->height); + if (gtk_widget_get_mapped (GTK_WIDGET (self))) { + zwlr_layer_surface_v1_set_size(priv->layer_surface, priv->width, priv->height); + } } /** @@ -658,3 +733,4 @@ phosh_layer_surface_wl_surface_commit (PhoshLayerSurface *self) if (priv->wl_surface) wl_surface_commit (priv->wl_surface); } +