From 3757427aec6ee066e7f2cba2e8e8fd6c3ac7873a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
Date: Tue, 19 Jun 2018 12:18:21 +0200
Subject: [PATCH] phosh: Properly close menus

* Closes settings when favorites is clicked and vice verca
* Close menu when activated a second time
---
 src/phosh.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/phosh.c b/src/phosh.c
index 7ffddb9..411e49a 100644
--- a/src/phosh.c
+++ b/src/phosh.c
@@ -196,6 +196,19 @@ lockscreen_unlock_cb (PhoshShell *self, PhoshLockscreen *window)
 }
 
 
+static void
+close_menu (struct popup **popup)
+{
+  if (*popup == NULL)
+    return;
+
+  gtk_window_close (GTK_WINDOW ((*popup)->window));
+  gtk_widget_destroy (GTK_WIDGET ((*popup)->window));
+  free (*popup);
+  *popup = NULL;
+}
+
+
 static void
 app_launched_cb (PhoshShell *self,
                  PhoshFavorites *favorites)
@@ -203,10 +216,7 @@ app_launched_cb (PhoshShell *self,
   PhoshShellPrivate *priv = phosh_shell_get_instance_private (self);
 
   g_return_if_fail (priv->favorites);
-  gtk_window_close (GTK_WINDOW (priv->favorites->window));
-  gtk_widget_destroy (GTK_WIDGET (priv->favorites->window));
-  free (priv->favorites);
-  priv->favorites = NULL;
+  close_menu (&priv->favorites);
 }
 
 
@@ -264,8 +274,11 @@ favorites_activated_cb (PhoshShell *self,
   struct xdg_positioner *xdg_positioner;
   gint width, height;
 
-  if (priv->favorites)
+  close_menu (&priv->settings);
+  if (priv->favorites) {
+    close_menu (&priv->favorites);
     return;
+  }
 
   favorites = calloc (1, sizeof *favorites);
   favorites->window = phosh_favorites_new ();
@@ -311,13 +324,10 @@ setting_done_cb (PhoshShell *self,
   PhoshShellPrivate *priv = phosh_shell_get_instance_private (self);
 
   g_return_if_fail (priv->settings);
-
-  gtk_window_close (GTK_WINDOW (priv->settings->window));
-  gtk_widget_destroy (GTK_WIDGET (priv->settings->window));
-  free (priv->settings);
-  priv->settings = NULL;
+  close_menu (&priv->settings);
 }
 
+
 static void
 settings_activated_cb (PhoshShell *self,
                        PhoshPanel *window)
@@ -329,8 +339,11 @@ settings_activated_cb (PhoshShell *self,
   struct xdg_positioner *xdg_positioner;
   gint width, height, panel_width;
 
-  if (priv->settings)
+  close_menu (&priv->favorites);
+  if (priv->settings) {
+    close_menu (&priv->settings);
     return;
+  }
 
   settings = calloc (1, sizeof *settings);
   settings->window = phosh_settings_new ();
-- 
GitLab