From e5763bd2fd7982c7506f56c2cbd71fbd5f28d8ea Mon Sep 17 00:00:00 2001
From: Nick Schermer <nick@xfce.org>
Date: Thu, 27 Nov 2008 19:09:35 +0000
Subject: [PATCH] 	* thunar/thunar-preferences-dialog.c: Instead of using
 a transient 	  window, we do a fake-center-on-parent. So it looks like the 
   window belongs to the parent, but it is a standalone window. This 	 
 should fix the last part of bug #3586. 	* thunar/thunar-window.c:
 Register the properties dialog with 	  thunar_application_take_window() so
 it will get a new 	  GtkWindowGroup.

(Old svn revision: 28930)
---
 ChangeLog                          | 10 +++++++++
 thunar/thunar-preferences-dialog.c | 36 +++++++++++++++++++++++++++---
 thunar/thunar-window.c             | 12 +++++++---
 3 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e06a82b29..edb835485 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-11-27	Nick Schermer <nick@xfce.org>
+
+	* thunar/thunar-preferences-dialog.c: Instead of using a transient
+	  window, we do a fake-center-on-parent. So it looks like the
+	  window belongs to the parent, but it is a standalone window. This
+	  should fix the last part of bug #3586.
+	* thunar/thunar-window.c: Register the properties dialog with
+	  thunar_application_take_window() so it will get a new
+	  GtkWindowGroup.
+
 2008-11-27	Jannis Pohlmann <jannis@xfce.org>
 
 	* configure.in.in, thunar-vfs/thunar-vfs-monitor.c: Add HAVE_LINUX
diff --git a/thunar/thunar-preferences-dialog.c b/thunar/thunar-preferences-dialog.c
index 5c4e81863..fe333618e 100644
--- a/thunar/thunar-preferences-dialog.c
+++ b/thunar/thunar-preferences-dialog.c
@@ -222,7 +222,6 @@ thunar_preferences_dialog_init (ThunarPreferencesDialog *dialog)
 
   /* configure the dialog properties */
   gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
-  gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
   gtk_window_set_icon_name (GTK_WINDOW (dialog), "xfce-filemanager");
   gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
   gtk_window_set_title (GTK_WINDOW (dialog), _("File Manager Preferences"));
@@ -733,11 +732,42 @@ thunar_preferences_dialog_configure (ThunarPreferencesDialog *dialog)
 GtkWidget*
 thunar_preferences_dialog_new (GtkWindow *parent)
 {
-  GtkWidget *dialog;
+  GtkWidget    *dialog;
+  gint          root_x, root_y;
+  gint          window_width, window_height;
+  gint          dialog_width, dialog_height;
+  gint          monitor;
+  GdkRectangle  geometry;
+  GdkScreen    *screen;
 
   dialog = g_object_new (THUNAR_TYPE_PREFERENCES_DIALOG, NULL);
+
+  /* fake gtk_window_set_transient_for() for centering the window on
+   * the parent window. See bug #3586. */
   if (G_LIKELY (parent != NULL))
-    gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+    {
+      screen = gtk_window_get_screen (parent);
+      gtk_window_set_screen (GTK_WINDOW (dialog), screen);
+      gtk_widget_realize (dialog);
+
+      /* get the size and position on the windows */
+      gtk_window_get_position (parent, &root_x, &root_y);
+      gtk_window_get_size (parent, &window_width, &window_height);
+      gtk_window_get_size (GTK_WINDOW (dialog), &dialog_width, &dialog_height);
+
+      /* get the monitor geometry of the monitor with the parent window */
+      monitor = gdk_screen_get_monitor_at_point (screen, root_x, root_y);
+      gdk_screen_get_monitor_geometry (screen, monitor, &geometry);
+
+      /* center the dialog on the window and clamp on the monitor */
+      root_x += (window_width - dialog_width) / 2;
+      root_x = CLAMP (root_x, geometry.x, geometry.x + geometry.width - dialog_width);
+      root_y += (window_height - dialog_height) / 2;
+      root_y = CLAMP (root_y, geometry.y, geometry.y + geometry.height - dialog_height);
+
+      /* move the dialog */
+      gtk_window_move (GTK_WINDOW (dialog), root_x, root_y);
+    }
 
   return dialog;
 }
diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index 4563b56eb..5f32b29b2 100644
--- a/thunar/thunar-window.c
+++ b/thunar/thunar-window.c
@@ -1553,14 +1553,20 @@ static void
 thunar_window_action_preferences (GtkAction    *action,
                                   ThunarWindow *window)
 {
-  GtkWidget *dialog;
+  GtkWidget         *dialog;
+  ThunarApplication *application;
 
   _thunar_return_if_fail (GTK_IS_ACTION (action));
   _thunar_return_if_fail (THUNAR_IS_WINDOW (window));
 
-  /* allocate and display a preferences dialog */
+  /* allocate and display a preferences dialog */;
   dialog = thunar_preferences_dialog_new (GTK_WINDOW (window));
-  gtk_widget_show (dialog);
+  gtk_widget_show (dialog);  
+
+  /* ...and let the application take care of it */
+  application = thunar_application_get ();
+  thunar_application_take_window (application, GTK_WINDOW (dialog));
+  g_object_unref (G_OBJECT (application));
 }
 
 
-- 
GitLab