Fix closing of description window using WM controls.
[claws.git] / src / gtk / description_window.c
index f5e7f78668ea19719b07036f9303a52c529e85b0..f7b8ebc0bd355bc2643ad6116f0f25e63272fa08 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2011 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include <glib.h>
@@ -26,6 +27,7 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
+#include "defs.h"
 #include "manage_window.h"
 #include "description_window.h"
 #include "gtkutils.h"
@@ -50,15 +52,16 @@ void description_window_create(DescriptionWindow *dwindow)
                description_create(dwindow);
        
                gtk_window_set_transient_for(GTK_WINDOW(dwindow->window), GTK_WINDOW(dwindow->parent));
-               gtk_window_set_modal(GTK_WINDOW(dwindow->parent), FALSE);
+               dwindow->parent_modal = gtk_window_get_modal(GTK_WINDOW(dwindow->parent));
+#ifndef G_OS_WIN32
+               gtk_window_set_modal(GTK_WINDOW(dwindow->parent), TRUE);
+#else
+               gtk_window_set_modal(GTK_WINDOW(dwindow->window), TRUE);
+#endif
                gtk_window_set_destroy_with_parent(GTK_WINDOW(dwindow->window), TRUE);
                gtk_widget_show(dwindow->window);
 
-               /* in case the description window is closed using the WM's [X] button */
-               g_signal_connect(G_OBJECT(dwindow->window), "destroy",
-                               G_CALLBACK(gtk_widget_destroyed), &dwindow->window);
-
-       } else g_print("windows exist\n");
+       } else g_print("window exists\n");
 }
 
 static void description_create(DescriptionWindow * dwindow)
@@ -176,7 +179,7 @@ static void description_create(DescriptionWindow * dwindow)
                         G_CALLBACK(description_window_focus_in_event), NULL);
        g_signal_connect(G_OBJECT(dwindow->window), "focus_out_event",
                         G_CALLBACK(description_window_focus_out_event), NULL);
-       g_signal_connect(G_OBJECT(dwindow->window), "delete_event",
+       g_signal_connect(G_OBJECT(dwindow->window), "destroy",
                         G_CALLBACK(description_window_destroy), dwindow);
        
        if(dwindow->parent)
@@ -192,7 +195,7 @@ static gboolean description_window_key_pressed(GtkWidget *widget,
                                               GdkEventKey *event,
                                               gpointer data)
 {
-       if (event && event->keyval == GDK_Escape)
+       if (event && event->keyval == GDK_KEY_Escape)
                description_window_destroy(widget, data);
        return FALSE;
 }
@@ -219,14 +222,17 @@ static gboolean description_window_focus_out_event (GtkWidget *widget,
 static void description_window_destroy (GtkWidget *widget, gpointer data)
 {
        DescriptionWindow *dwindow = (DescriptionWindow *) data;
-       
+
        if(dwindow->window) {
                gtk_widget_hide(dwindow->window);
                gtk_widget_destroy(dwindow->window);
                dwindow->window = NULL;
        }
        
-       if(dwindow->parent)
+       if(dwindow->parent) {
+               if (GTK_IS_WINDOW(dwindow->parent))
+                       gtk_window_set_modal(GTK_WINDOW(dwindow->parent), dwindow->parent_modal);
                g_signal_handlers_disconnect_by_func(G_OBJECT(dwindow->parent), 
                                        description_window_destroy, dwindow->parent);
+       }
 }