From c3a54595ea72638fbc7b65ffc3c26966de772e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Tue, 16 Jul 2019 13:31:21 +0200 Subject: [PATCH] layersurface: Refresh layersurface on map If the surface gets unmapped and mapped again we have another GDK window so we have to reconfigure the layers surface on map and destroy it on unmap. This will be merged back into phosh if it works out. --- eek/layersurface.c | 49 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/eek/layersurface.c b/eek/layersurface.c index 05a14ad9..c9e93a83 100644 --- a/eek/layersurface.c +++ b/eek/layersurface.c @@ -185,18 +185,34 @@ on_phosh_layer_surface_realized (PhoshLayerSurface *self, gpointer unused) PhoshLayerSurfacePrivate *priv; GdkWindow *gdk_window; - g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self)); priv = phosh_layer_surface_get_instance_private (self); gdk_window = gtk_widget_get_window (GTK_WIDGET (self)); gdk_wayland_window_set_use_custom_surface (gdk_window); - - wl_display_roundtrip (gdk_wayland_display_get_wl_display (gdk_display_get_default ())); - priv->wl_surface = gdk_wayland_window_get_wl_surface (gdk_window); + gtk_window_set_decorated (GTK_WINDOW (self), FALSE); +} + + +static void +on_phosh_layer_surface_mapped (PhoshLayerSurface *self, gpointer unused) +{ + PhoshLayerSurfacePrivate *priv; + GdkWindow *gdk_window; + + g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self)); + priv = phosh_layer_surface_get_instance_private (self); + + if (!priv->wl_surface) { + gdk_window = gtk_widget_get_window (GTK_WIDGET (self)); + gdk_wayland_window_set_use_custom_surface (gdk_window); + priv->wl_surface = gdk_wayland_window_get_wl_surface (gdk_window); + } + g_debug ("Mapped %p", priv->wl_surface); + priv->layer_surface = zwlr_layer_shell_v1_get_layer_surface(priv->layer_shell, priv->wl_surface, priv->wl_output, @@ -211,18 +227,26 @@ on_phosh_layer_surface_realized (PhoshLayerSurface *self, gpointer unused) self); wl_surface_commit(priv->wl_surface); - gtk_window_set_decorated (GTK_WINDOW (self), FALSE); -} - - -static void -on_phosh_layer_surface_mapped (PhoshLayerSurface *self, gpointer unused) -{ /* Process all pending events, otherwise we end up sending ack configure * to a not yet configured surface */ wl_display_roundtrip (gdk_wayland_display_get_wl_display (gdk_display_get_default ())); } +static void +on_phosh_layer_surface_unmapped (PhoshLayerSurface *self, gpointer unused) +{ + PhoshLayerSurfacePrivate *priv; + + g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self)); + priv = phosh_layer_surface_get_instance_private (self); + + priv = phosh_layer_surface_get_instance_private (self); + if (priv->layer_surface) { + zwlr_layer_surface_v1_destroy(priv->layer_surface); + priv->layer_surface = NULL; + } + priv->wl_surface = NULL; +} static void phosh_layer_surface_constructed (GObject *object) @@ -235,6 +259,9 @@ phosh_layer_surface_constructed (GObject *object) g_signal_connect (self, "map", G_CALLBACK (on_phosh_layer_surface_mapped), NULL); + g_signal_connect (self, "unmap", + G_CALLBACK (on_phosh_layer_surface_unmapped), + NULL); }