From 10a4dfae45b05e4ed6ff23c90401ef5ac8773c09 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 23 Aug 2026 00:59:57 +0300
Subject: [PATCH 59/59] gtk4(x): Fix reopening Messages tab closed as window

If Messages were windowed and then closed, it was
impossible to reopen afterwards.

See RM #2160

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-gtk-4.0/gui_stuff.c  | 2 ++
 client/gui-gtk-4.0/messagewin.c | 4 +++-
 client/gui-gtk-5.0/gui_stuff.c  | 2 ++
 client/gui-gtk-5.0/messagewin.c | 4 +++-
 4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/client/gui-gtk-4.0/gui_stuff.c b/client/gui-gtk-4.0/gui_stuff.c
index 31ee468f5b..be24e1f97f 100644
--- a/client/gui-gtk-4.0/gui_stuff.c
+++ b/client/gui-gtk-4.0/gui_stuff.c
@@ -352,6 +352,8 @@ static gint gui_dialog_delete_handler(GtkWidget *widget, gpointer data)
 {
   struct gui_dialog *dlg = data;
 
+  dlg->v.window = NULL;
+
   /* emit response signal. */
   gui_dialog_response(dlg, GTK_RESPONSE_DELETE_EVENT);
 
diff --git a/client/gui-gtk-4.0/messagewin.c b/client/gui-gtk-4.0/messagewin.c
index 31bb202306..619a8319d8 100644
--- a/client/gui-gtk-4.0/messagewin.c
+++ b/client/gui-gtk-4.0/messagewin.c
@@ -420,7 +420,9 @@ static void meswin_dialog_free(struct meswin_dialog *pdialog)
 ****************************************************************************/
 void meswin_dialog_popup(bool raise)
 {
-  if (NULL == meswin.shell) {
+  if (meswin.shell == NULL
+      || (meswin.shell->type == GUI_DIALOG_WINDOW
+          && meswin.shell->v.window == NULL)) {
     meswin_dialog_init(&meswin);
   }
 
diff --git a/client/gui-gtk-5.0/gui_stuff.c b/client/gui-gtk-5.0/gui_stuff.c
index 90a1047177..8fbba7c44c 100644
--- a/client/gui-gtk-5.0/gui_stuff.c
+++ b/client/gui-gtk-5.0/gui_stuff.c
@@ -353,6 +353,8 @@ static gint gui_dialog_delete_handler(GtkWidget *widget, gpointer data)
 {
   struct gui_dialog *dlg = data;
 
+  dlg->v.window = NULL;
+
   /* emit response signal. */
   gui_dialog_response(dlg, GTK_RESPONSE_DELETE_EVENT);
 
diff --git a/client/gui-gtk-5.0/messagewin.c b/client/gui-gtk-5.0/messagewin.c
index 4acb358793..20763ce47c 100644
--- a/client/gui-gtk-5.0/messagewin.c
+++ b/client/gui-gtk-5.0/messagewin.c
@@ -420,7 +420,9 @@ static void meswin_dialog_free(struct meswin_dialog *pdialog)
 ****************************************************************************/
 void meswin_dialog_popup(bool raise)
 {
-  if (NULL == meswin.shell) {
+  if (meswin.shell == NULL
+      || (meswin.shell->type == GUI_DIALOG_WINDOW
+          && meswin.shell->v.window == NULL)) {
     meswin_dialog_init(&meswin);
   }
 
-- 
2.53.0

