# HG changeset patch
# Node ID 127ac6306b96
# Parent  b9dc817fbb3f
diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -1169,6 +1169,7 @@
 		* pidgin_pounces_manager_show
 		* pidgin_prefs_labeled_entry
 		* pidgin_prefs_labeled_password
+		* pidgin_prefs_show
 		* pidgin_privacy_dialog_hide
 		* pidgin_privacy_dialog_show
 		* pidgin_privacy_init
diff --git a/pidgin/pidginapplication.c b/pidgin/pidginapplication.c
--- a/pidgin/pidginapplication.c
+++ b/pidgin/pidginapplication.c
@@ -479,9 +479,19 @@
 static void
 pidgin_application_preferences(G_GNUC_UNUSED GSimpleAction *simple,
                                G_GNUC_UNUSED GVariant *parameter,
-                               G_GNUC_UNUSED gpointer data)
+                               gpointer data)
 {
-	pidgin_prefs_show();
+	PidginApplication *application = data;
+	static GtkWidget *preferences = NULL;
+
+	if(!GTK_IS_WIDGET(preferences)) {
+		preferences = g_object_new(PIDGIN_TYPE_PREFS_WINDOW, NULL);
+		g_object_add_weak_pointer(G_OBJECT(preferences), (gpointer)&preferences);
+	}
+
+	pidgin_application_present_transient_window(application,
+	                                            GTK_WINDOW(preferences));
+
 }
 
 static void
diff --git a/pidgin/prefs/pidginprefs.h b/pidgin/prefs/pidginprefs.h
--- a/pidgin/prefs/pidginprefs.h
+++ b/pidgin/prefs/pidginprefs.h
@@ -45,13 +45,6 @@
 void pidgin_prefs_init(void);
 
 /**
- * pidgin_prefs_show:
- *
- * Shows the preferences dialog.
- */
-void pidgin_prefs_show(void);
-
-/**
  * pidgin_prefs_checkbox:
  * @title: The text to be displayed as the checkbox label
  * @key:   The key of the purple bool pref that will be represented by the checkbox
diff --git a/pidgin/prefs/pidginprefs.c b/pidgin/prefs/pidginprefs.c
--- a/pidgin/prefs/pidginprefs.c
+++ b/pidgin/prefs/pidginprefs.c
@@ -42,9 +42,6 @@
 	GtkDialog parent;
 };
 
-/* Main dialog */
-static PidginPrefsWindow *prefs = NULL;
-
 G_DEFINE_TYPE(PidginPrefsWindow, pidgin_prefs_window, GTK_TYPE_DIALOG);
 
 /******************************************************************************
@@ -475,19 +472,6 @@
 }
 
 static void
-delete_prefs(G_GNUC_UNUSED GtkWidget *asdf, G_GNUC_UNUSED void *gdsa)
-{
-	/* Close any request dialogs */
-	purple_request_close_with_handle(prefs);
-	purple_notify_close_with_handle(prefs);
-
-	/* Unregister callbacks. */
-	purple_prefs_disconnect_by_handle(prefs);
-
-	prefs = NULL;
-}
-
-static void
 vv_test_switch_page_cb(GtkStack *stack, G_GNUC_UNUSED GParamSpec *pspec,
                        gpointer data)
 {
@@ -503,17 +487,26 @@
  * GObject Implementation
  *****************************************************************************/
 static void
+pidgin_prefs_window_finalize(GObject *obj) {
+	purple_prefs_disconnect_by_handle(obj);
+
+	G_OBJECT_CLASS(pidgin_prefs_window_parent_class)->finalize(obj);
+}
+
+static void
 pidgin_prefs_window_class_init(PidginPrefsWindowClass *klass)
 {
+	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
 	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
 
+	obj_class->finalize = pidgin_prefs_window_finalize;
+
 	gtk_widget_class_set_template_from_resource(
 		widget_class,
 		"/im/pidgin/Pidgin3/Prefs/prefs.ui"
 	);
 
 	/* Main window */
-	gtk_widget_class_bind_template_callback(widget_class, delete_prefs);
 	gtk_widget_class_bind_template_callback(widget_class,
 	                                        vv_test_switch_page_cb);
 }
@@ -528,17 +521,6 @@
  * API
  *****************************************************************************/
 void
-pidgin_prefs_show(void)
-{
-	if (prefs == NULL) {
-		prefs = PIDGIN_PREFS_WINDOW(g_object_new(
-					pidgin_prefs_window_get_type(), NULL));
-	}
-
-	gtk_window_present(GTK_WINDOW(prefs));
-}
-
-void
 pidgin_prefs_init(void)
 {
 	purple_prefs_add_none(PIDGIN_PREFS_ROOT "");
diff --git a/pidgin/resources/Prefs/prefs.ui b/pidgin/resources/Prefs/prefs.ui
--- a/pidgin/resources/Prefs/prefs.ui
+++ b/pidgin/resources/Prefs/prefs.ui
@@ -28,7 +28,6 @@
   <!-- interface-copyright Pidgin Developers <devel@pidgin.im> -->
   <template class="PidginPrefsWindow" parent="GtkDialog">
     <property name="title" translatable="1">Preferences</property>
-    <signal name="destroy" handler="delete_prefs" swapped="no"/>
     <child internal-child="content_area">
       <object class="GtkBox">
         <property name="vexpand">1</property>
