[console/zbrown/quick-ci-check: 3/5] pages: move window creation to window




commit 87108a266b5cebb284a1700c94aa721eef5e7002
Author: Zander Brown <zbrown gnome org>
Date:   Wed Aug 24 00:04:30 2022 +0100

    pages: move window creation to window
    
    Introduce a new signal, effectivly proxying the one on the underlying
    Adw.TabView, so that window creation can be handled in window itself —
    rather than having pages randomly know about making windows
    
    This isn't a purely idiomatic change, it means we can ensure the new
    window shares the original windows settings instance without having
    pages keep it's own reference

 src/kgx-marshals.list |  1 +
 src/kgx-pages.c       | 44 +++++++++++++++++++++++++-------------------
 src/kgx-window.c      | 21 +++++++++++++++++++++
 src/kgx-window.ui     |  1 +
 4 files changed, 48 insertions(+), 19 deletions(-)
---
diff --git a/src/kgx-marshals.list b/src/kgx-marshals.list
index 79c86d8..7f7c1f8 100644
--- a/src/kgx-marshals.list
+++ b/src/kgx-marshals.list
@@ -1,3 +1,4 @@
+OBJECT: VOID
 VOID: ENUM
 VOID: ENUM, STRING, BOOLEAN
 VOID: UINT, UINT
diff --git a/src/kgx-pages.c b/src/kgx-pages.c
index 4fcc075..6e1298e 100644
--- a/src/kgx-pages.c
+++ b/src/kgx-pages.c
@@ -31,7 +31,6 @@
 #include "kgx-close-dialog.h"
 #include "kgx-pages.h"
 #include "kgx-tab.h"
-#include "kgx-window.h"
 #include "kgx-terminal.h"
 #include "kgx-marshals.h"
 
@@ -97,6 +96,7 @@ static GParamSpec *pspecs[LAST_PROP] = { NULL, };
 
 enum {
   ZOOM,
+  CREATE_TEAROFF_HOST,
   N_SIGNALS
 };
 static guint signals[N_SIGNALS];
@@ -424,30 +424,13 @@ static AdwTabView *
 create_window (AdwTabView *view,
                KgxPages   *self)
 {
-  /* Perhaps this should be handled via KgxWindow? */
-  GtkWindow *window;
-  KgxWindow *new_window;
-  GtkApplication *app;
   KgxPages *new_pages;
   KgxPagesPrivate *priv;
-  int width, height;
 
-  window = GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (self)));
-  app = gtk_window_get_application (window);
+  g_signal_emit (self, signals[CREATE_TEAROFF_HOST], 0, &new_pages);
 
-  kgx_window_get_size (KGX_WINDOW (window), &width, &height);
-
-  new_window = g_object_new (KGX_TYPE_WINDOW,
-                             "application", app,
-                             "default-width", width,
-                             "default-height", height,
-                             NULL);
-
-  new_pages = kgx_window_get_pages (new_window);
   priv = kgx_pages_get_instance_private (new_pages);
 
-  gtk_window_present (GTK_WINDOW (new_window));
-
   return ADW_TAB_VIEW (priv->view);
 }
 
@@ -534,6 +517,20 @@ status_to_icon (GBinding     *binding,
 }
 
 
+static gboolean
+object_accumulator (GSignalInvocationHint *ihint,
+                    GValue                *return_value,
+                    const GValue          *signal_value,
+                    gpointer               data)
+{
+  GObject *object = g_value_get_object (signal_value);
+
+  g_value_set_object (return_value, object);
+
+  return !object;
+}
+
+
 static void
 kgx_pages_class_init (KgxPagesClass *klass)
 {
@@ -667,6 +664,15 @@ kgx_pages_class_init (KgxPagesClass *klass)
                                 1,
                                 KGX_TYPE_ZOOM);
 
+  signals[CREATE_TEAROFF_HOST] = g_signal_new ("create-tearoff-host",
+                                               G_TYPE_FROM_CLASS (klass),
+                                               G_SIGNAL_RUN_LAST,
+                                               0,
+                                               object_accumulator, NULL,
+                                               kgx_marshals_OBJECT__VOID,
+                                               KGX_TYPE_PAGES,
+                                               0);
+
   gtk_widget_class_set_template_from_resource (widget_class,
                                                KGX_APPLICATION_PATH "kgx-pages.ui");
 
diff --git a/src/kgx-window.c b/src/kgx-window.c
index 9c63bb2..bd32766 100644
--- a/src/kgx-window.c
+++ b/src/kgx-window.c
@@ -251,6 +251,26 @@ zoom (KgxPages  *pages,
 }
 
 
+static KgxPages *
+create_tearoff_host (KgxPages *pages, KgxWindow *self)
+{
+  GtkApplication *application = gtk_window_get_application (GTK_WINDOW (self));
+  KgxWindow *new_window;
+  int width, height;
+
+  kgx_window_get_size (self, &width, &height);
+
+  new_window = g_object_new (KGX_TYPE_WINDOW,
+                             "application", application,
+                             "default-width", width,
+                             "default-height", height,
+                             NULL);
+  gtk_window_present (GTK_WINDOW (new_window));
+
+  return KGX_PAGES (new_window->pages);
+}
+
+
 static void
 status_changed (GObject *object, GParamSpec *pspec, gpointer data)
 {
@@ -344,6 +364,7 @@ kgx_window_class_init (KgxWindowClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, size_changed);
 
   gtk_widget_class_bind_template_callback (widget_class, zoom);
+  gtk_widget_class_bind_template_callback (widget_class, create_tearoff_host);
   gtk_widget_class_bind_template_callback (widget_class, status_changed);
   gtk_widget_class_bind_template_callback (widget_class, extra_drag_drop);
   gtk_widget_class_bind_template_callback (widget_class, new_tab_cb);
diff --git a/src/kgx-window.ui b/src/kgx-window.ui
index 32e904c..dcfc0c9 100644
--- a/src/kgx-window.ui
+++ b/src/kgx-window.ui
@@ -151,6 +151,7 @@
               <object class="KgxPages" id="pages">
                 <property name="is-active" bind-source="KgxWindow" bind-property="is-active" 
bind-flags="sync-create" />
                 <signal name="zoom" handler="zoom" swapped="no"/>
+                <signal name="create-tearoff-host" handler="create_tearoff_host" swapped="no"/>
                 <signal name="notify::status" handler="status_changed" swapped="yes" />
               </object>
             </child>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]