[gnome-builder] handy: use HdyApplicationWindow



commit e8ce633a8dd67f929f5a45f4ad9114b7b3a30d2b
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jan 11 22:03:24 2022 -0800

    handy: use HdyApplicationWindow
    
    Now that we link against libhandy, we can use HdyApplicationWindow if we
    fix a few pieces to go with it like the headerbar.
    
    The one thing we loose for right now is the fullscreen button, but that
    can come back if people really want it. It doesn't seem to be used much
    right now.

 src/libide/editor/ide-editor-workspace.ui         |  2 +-
 src/libide/gui/ide-header-bar.c                   |  3 +-
 src/libide/gui/ide-header-bar.h                   |  5 +-
 src/libide/gui/ide-header-bar.ui                  |  2 +-
 src/libide/gui/ide-preferences-window.c           |  4 +-
 src/libide/gui/ide-preferences-window.h           |  3 +-
 src/libide/gui/ide-preferences-window.ui          | 24 ++++---
 src/libide/gui/ide-primary-workspace.ui           |  2 +-
 src/libide/gui/ide-workspace.c                    | 82 ++++++++++++++++++++---
 src/libide/gui/ide-workspace.h                    |  5 +-
 src/libide/gui/ide-workspace.ui                   | 22 ++++--
 src/libide/terminal/ide-terminal-workspace.c      |  2 +-
 src/libide/terminal/ide-terminal-workspace.ui     |  2 +-
 src/plugins/buildui/gbp-buildui-workspace-addin.c |  2 +-
 src/plugins/dspy/gbp-dspy-workspace.ui            |  2 +-
 15 files changed, 122 insertions(+), 40 deletions(-)
---
diff --git a/src/libide/editor/ide-editor-workspace.ui b/src/libide/editor/ide-editor-workspace.ui
index 668e24157..baa2436df 100644
--- a/src/libide/editor/ide-editor-workspace.ui
+++ b/src/libide/editor/ide-editor-workspace.ui
@@ -4,7 +4,7 @@
     <child type="titlebar">
       <object class="IdeHeaderBar">
         <property name="show-close-button">true</property>
-        <property name="show-fullscreen-button">true</property>
+        <property name="show-fullscreen-button">false</property>
         <property name="menu-id">ide-editor-workspace-menu</property>
         <property name="visible">true</property>
         <child type="primary">
diff --git a/src/libide/gui/ide-header-bar.c b/src/libide/gui/ide-header-bar.c
index 245eb5c5e..19d361b09 100644
--- a/src/libide/gui/ide-header-bar.c
+++ b/src/libide/gui/ide-header-bar.c
@@ -34,6 +34,7 @@ typedef struct
   GtkToggleButton    *fullscreen_button;
   GtkImage           *fullscreen_image;
   DzlShortcutTooltip *fullscreen_tooltip;
+
   DzlMenuButton      *menu_button;
   DzlShortcutTooltip *menu_tooltip;
   GtkBox             *primary;
@@ -51,7 +52,7 @@ enum {
 
 static void buildable_iface_init (GtkBuildableIface *iface);
 
-G_DEFINE_TYPE_WITH_CODE (IdeHeaderBar, ide_header_bar, GTK_TYPE_HEADER_BAR,
+G_DEFINE_TYPE_WITH_CODE (IdeHeaderBar, ide_header_bar, HDY_TYPE_HEADER_BAR,
                          G_ADD_PRIVATE (IdeHeaderBar)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_iface_init))
 
diff --git a/src/libide/gui/ide-header-bar.h b/src/libide/gui/ide-header-bar.h
index f02cb14fd..0811a06a0 100644
--- a/src/libide/gui/ide-header-bar.h
+++ b/src/libide/gui/ide-header-bar.h
@@ -25,6 +25,7 @@
 #endif
 
 #include <gtk/gtk.h>
+#include <handy.h>
 #include <libide-core.h>
 
 G_BEGIN_DECLS
@@ -32,11 +33,11 @@ G_BEGIN_DECLS
 #define IDE_TYPE_HEADER_BAR (ide_header_bar_get_type())
 
 IDE_AVAILABLE_IN_3_32
-G_DECLARE_DERIVABLE_TYPE (IdeHeaderBar, ide_header_bar, IDE, HEADER_BAR, GtkHeaderBar)
+G_DECLARE_DERIVABLE_TYPE (IdeHeaderBar, ide_header_bar, IDE, HEADER_BAR, HdyHeaderBar)
 
 struct _IdeHeaderBarClass
 {
-  GtkHeaderBarClass parent_class;
+  HdyHeaderBarClass parent_class;
 
   /*< private >*/
   gpointer _reserved[16];
diff --git a/src/libide/gui/ide-header-bar.ui b/src/libide/gui/ide-header-bar.ui
index e55beb724..7cc625edc 100644
--- a/src/libide/gui/ide-header-bar.ui
+++ b/src/libide/gui/ide-header-bar.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.24 -->
-  <template class="IdeHeaderBar" parent="GtkHeaderBar">
+  <template class="IdeHeaderBar" parent="HdyHeaderBar">
     <child>
       <object class="DzlPriorityBox" id="primary">
         <property name="hexpand">true</property>
diff --git a/src/libide/gui/ide-preferences-window.c b/src/libide/gui/ide-preferences-window.c
index 683c2aaaa..29a845bdc 100644
--- a/src/libide/gui/ide-preferences-window.c
+++ b/src/libide/gui/ide-preferences-window.c
@@ -26,10 +26,10 @@
 
 struct _IdePreferencesWindow
 {
-  DzlApplicationWindow parent_window;
+  HdyApplicationWindow parent_window;
 };
 
-G_DEFINE_FINAL_TYPE (IdePreferencesWindow, ide_preferences_window, DZL_TYPE_APPLICATION_WINDOW)
+G_DEFINE_FINAL_TYPE (IdePreferencesWindow, ide_preferences_window, HDY_TYPE_APPLICATION_WINDOW)
 
 static void
 ide_preferences_window_class_init (IdePreferencesWindowClass *klass)
diff --git a/src/libide/gui/ide-preferences-window.h b/src/libide/gui/ide-preferences-window.h
index dc7fd2752..9b7d374a0 100644
--- a/src/libide/gui/ide-preferences-window.h
+++ b/src/libide/gui/ide-preferences-window.h
@@ -21,6 +21,7 @@
 #pragma once
 
 #include <dazzle.h>
+#include <handy.h>
 #include <libide-core.h>
 
 G_BEGIN_DECLS
@@ -28,6 +29,6 @@ G_BEGIN_DECLS
 #define IDE_TYPE_PREFERENCES_WINDOW (ide_preferences_window_get_type())
 
 IDE_AVAILABLE_IN_3_32
-G_DECLARE_FINAL_TYPE (IdePreferencesWindow, ide_preferences_window, IDE, PREFERENCES_WINDOW, 
DzlApplicationWindow)
+G_DECLARE_FINAL_TYPE (IdePreferencesWindow, ide_preferences_window, IDE, PREFERENCES_WINDOW, 
HdyApplicationWindow)
 
 G_END_DECLS
diff --git a/src/libide/gui/ide-preferences-window.ui b/src/libide/gui/ide-preferences-window.ui
index 33258b7d1..118a49e10 100644
--- a/src/libide/gui/ide-preferences-window.ui
+++ b/src/libide/gui/ide-preferences-window.ui
@@ -1,16 +1,22 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <template class="IdePreferencesWindow" parent="DzlApplicationWindow">
-    <child type="titlebar">
-      <object class="GtkHeaderBar" id="header_bar">
-        <property name="title" translatable="yes">Preferences</property>
-        <property name="show-close-button">true</property>
-        <property name="visible">true</property>
-      </object>
-    </child>
+  <template class="IdePreferencesWindow" parent="HdyApplicationWindow">
     <child>
-      <object class="IdePreferencesSurface" id="surface">
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
         <property name="visible">true</property>
+        <child>
+          <object class="HdyHeaderBar" id="header_bar">
+            <property name="title" translatable="yes">Preferences</property>
+            <property name="show-close-button">true</property>
+            <property name="visible">true</property>
+          </object>
+        </child>
+        <child>
+          <object class="IdePreferencesSurface" id="surface">
+            <property name="visible">true</property>
+          </object>
+        </child>
       </object>
     </child>
   </template>
diff --git a/src/libide/gui/ide-primary-workspace.ui b/src/libide/gui/ide-primary-workspace.ui
index 37a88cdea..d9dfddef4 100644
--- a/src/libide/gui/ide-primary-workspace.ui
+++ b/src/libide/gui/ide-primary-workspace.ui
@@ -5,7 +5,7 @@
       <object class="IdeHeaderBar" id="header_bar">
         <property name="menu-id">ide-primary-workspace-menu</property>
         <property name="show-close-button">true</property>
-        <property name="show-fullscreen-button">true</property>
+        <property name="show-fullscreen-button">false</property>
         <property name="visible">true</property>
         <child type="left">
           <object class="IdeSurfacesButton" id="surface_menu_button">
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index c968e4899..3d92bb4c8 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -70,11 +70,14 @@ typedef struct
    * fullscreen overlay so that it gets delivery of crossing events.
    */
   GtkEventBox *event_box;
+  GtkBox *vbox;
 
   /* A MRU that is updated as pages are focused. It allows us to move through
    * the pages in the order they've been most-recently focused.
    */
   GQueue page_mru;
+
+  guint in_key_press : 1;
 } IdeWorkspacePrivate;
 
 typedef struct
@@ -97,10 +100,11 @@ enum {
 
 static void buildable_iface_init (GtkBuildableIface *iface);
 
-G_DEFINE_ABSTRACT_TYPE_WITH_CODE (IdeWorkspace, ide_workspace, DZL_TYPE_APPLICATION_WINDOW,
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (IdeWorkspace, ide_workspace, HDY_TYPE_APPLICATION_WINDOW,
                                   G_ADD_PRIVATE (IdeWorkspace)
                                   G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_iface_init))
 
+static GtkBuildableIface *parent_builder;
 static GParamSpec *properties [N_PROPS];
 static guint signals [N_SIGNALS];
 
@@ -412,6 +416,7 @@ ide_workspace_real_foreach_page (IdeWorkspace *self,
                          &state);
 }
 
+#if 0
 static void
 ide_workspace_set_surface_fullscreen_cb (GtkWidget *widget,
                                          gpointer   user_data)
@@ -441,6 +446,7 @@ ide_workspace_real_set_fullscreen (DzlApplicationWindow *window,
                          ide_workspace_set_surface_fullscreen_cb,
                          GUINT_TO_POINTER (fullscreen));
 }
+#endif
 
 static void
 ide_workspace_grab_focus (GtkWidget *widget)
@@ -454,6 +460,28 @@ ide_workspace_grab_focus (GtkWidget *widget)
     gtk_widget_grab_focus (GTK_WIDGET (surface));
 }
 
+static gboolean
+ide_workspace_key_press_event (GtkWidget   *widget,
+                               GdkEventKey *event)
+{
+  IdeWorkspace *self = (IdeWorkspace *)widget;
+  IdeWorkspacePrivate *priv = ide_workspace_get_instance_private (self);
+  gboolean ret;
+
+  g_assert (IDE_IS_WORKSPACE (self));
+  g_assert (event != NULL);
+
+  /* Be re-entrant safe from the shortcut manager */
+  if (priv->in_key_press)
+    return GTK_WIDGET_CLASS (ide_workspace_parent_class)->key_press_event (widget, event);
+
+  priv->in_key_press = TRUE;
+  ret = dzl_shortcut_manager_handle_event (NULL, event, widget);
+  priv->in_key_press = FALSE;
+
+  return ret;
+}
+
 static void
 ide_workspace_finalize (GObject *object)
 {
@@ -513,7 +541,7 @@ ide_workspace_class_init (IdeWorkspaceClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-  DzlApplicationWindowClass *window_class = DZL_APPLICATION_WINDOW_CLASS (klass);
+  //DzlApplicationWindowClass *window_class = DZL_APPLICATION_WINDOW_CLASS (klass);
 
   object_class->finalize = ide_workspace_finalize;
   object_class->get_property = ide_workspace_get_property;
@@ -522,8 +550,9 @@ ide_workspace_class_init (IdeWorkspaceClass *klass)
   widget_class->destroy = ide_workspace_destroy;
   widget_class->delete_event = ide_workspace_delete_event;
   widget_class->grab_focus = ide_workspace_grab_focus;
+  widget_class->key_press_event = ide_workspace_key_press_event;
 
-  window_class->set_fullscreen = ide_workspace_real_set_fullscreen;
+  //window_class->set_fullscreen = ide_workspace_real_set_fullscreen;
 
   klass->foreach_page = ide_workspace_real_foreach_page;
   klass->context_set = ide_workspace_real_context_set;
@@ -588,6 +617,7 @@ ide_workspace_class_init (IdeWorkspaceClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, IdeWorkspace, event_box);
   gtk_widget_class_bind_template_child_private (widget_class, IdeWorkspace, overlay);
   gtk_widget_class_bind_template_child_private (widget_class, IdeWorkspace, surfaces);
+  gtk_widget_class_bind_template_child_private (widget_class, IdeWorkspace, vbox);
 }
 
 static void
@@ -730,20 +760,31 @@ ide_workspace_foreach_page (IdeWorkspace *self,
 IdeHeaderBar *
 ide_workspace_get_header_bar (IdeWorkspace *self)
 {
-  GtkWidget *titlebar;
+  IdeWorkspacePrivate *priv = ide_workspace_get_instance_private (self);
+  IdeHeaderBar *ret = NULL;
+  GList *children;
 
   g_return_val_if_fail (IDE_IS_WORKSPACE (self), NULL);
 
-  if ((titlebar = gtk_window_get_titlebar (GTK_WINDOW (self))))
+  children = gtk_container_get_children (GTK_CONTAINER (priv->vbox));
+
+  for (const GList *iter = children; iter; iter = iter->next)
     {
-      if (GTK_IS_STACK (titlebar))
-        titlebar = gtk_stack_get_visible_child (GTK_STACK (titlebar));
+      GtkWidget *widget = iter->data;
 
-      if (IDE_IS_HEADER_BAR (titlebar))
-        return IDE_HEADER_BAR (titlebar);
+      if (GTK_IS_STACK (widget))
+        widget = gtk_stack_get_visible_child (GTK_STACK (widget));
+
+      if (IDE_IS_HEADER_BAR (widget))
+        {
+          ret = IDE_HEADER_BAR (widget);
+          break;
+        }
     }
 
-  return NULL;
+  g_list_free (children);
+
+  return ret;
 }
 
 /**
@@ -888,10 +929,31 @@ ide_workspace_get_internal_child (GtkBuildable *buildable,
   return NULL;
 }
 
+static void
+ide_workspace_add_child (GtkBuildable *buildable,
+                         GtkBuilder   *builder,
+                         GObject      *object,
+                         const char   *type)
+{
+  IdeWorkspace *self = (IdeWorkspace *)buildable;
+  IdeWorkspacePrivate *priv = ide_workspace_get_instance_private (self);
+
+  g_assert (IDE_IS_WORKSPACE (self));
+  g_assert (GTK_IS_BUILDER (builder));
+
+  if (g_strcmp0 (type, "titlebar") == 0 && GTK_IS_WIDGET (object))
+    gtk_box_pack_start (priv->vbox, GTK_WIDGET (object), FALSE, FALSE, 0);
+  else
+    parent_builder->add_child (buildable, builder, object, type);
+}
+
 static void
 buildable_iface_init (GtkBuildableIface *iface)
 {
+  parent_builder = g_type_interface_peek_parent (iface);
+
   iface->get_internal_child = ide_workspace_get_internal_child;
+  iface->add_child = ide_workspace_add_child;
 }
 
 /**
diff --git a/src/libide/gui/ide-workspace.h b/src/libide/gui/ide-workspace.h
index 9e899c9d0..e9a28ac7a 100644
--- a/src/libide/gui/ide-workspace.h
+++ b/src/libide/gui/ide-workspace.h
@@ -25,6 +25,7 @@
 #endif
 
 #include <dazzle.h>
+#include <handy.h>
 #include <libide-core.h>
 #include <libide-projects.h>
 
@@ -37,11 +38,11 @@ G_BEGIN_DECLS
 #define IDE_TYPE_WORKSPACE (ide_workspace_get_type())
 
 IDE_AVAILABLE_IN_3_32
-G_DECLARE_DERIVABLE_TYPE (IdeWorkspace, ide_workspace, IDE, WORKSPACE, DzlApplicationWindow)
+G_DECLARE_DERIVABLE_TYPE (IdeWorkspace, ide_workspace, IDE, WORKSPACE, HdyApplicationWindow)
 
 struct _IdeWorkspaceClass
 {
-  DzlApplicationWindowClass parent_class;
+  HdyApplicationWindowClass parent_class;
 
   const gchar *kind;
 
diff --git a/src/libide/gui/ide-workspace.ui b/src/libide/gui/ide-workspace.ui
index 6af729f22..6b682ae62 100644
--- a/src/libide/gui/ide-workspace.ui
+++ b/src/libide/gui/ide-workspace.ui
@@ -1,20 +1,30 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <template class="IdeWorkspace" parent="DzlApplicationWindow">
+  <template class="IdeWorkspace" parent="HdyApplicationWindow">
     <child>
-      <object class="GtkEventBox" id="event_box">
+      <object class="GtkBox" id="vbox">
+        <property name="orientation">vertical</property>
         <property name="visible">true</property>
         <child>
-          <object class="GtkOverlay" id="overlay">
+          <object class="GtkEventBox" id="event_box">
+            <property name="vexpand">true</property>
             <property name="visible">true</property>
             <child>
-              <object class="GtkStack" id="surfaces">
-                <property name="homogeneous">false</property>
-                <property name="expand">true</property>
+              <object class="GtkOverlay" id="overlay">
                 <property name="visible">true</property>
+                <child>
+                  <object class="GtkStack" id="surfaces">
+                    <property name="homogeneous">false</property>
+                    <property name="expand">true</property>
+                    <property name="visible">true</property>
+                  </object>
+                </child>
               </object>
             </child>
           </object>
+          <packing>
+            <property name="pack-type">end</property>
+          </packing>
         </child>
       </object>
     </child>
diff --git a/src/libide/terminal/ide-terminal-workspace.c b/src/libide/terminal/ide-terminal-workspace.c
index bdd0e33d0..bd24f3895 100644
--- a/src/libide/terminal/ide-terminal-workspace.c
+++ b/src/libide/terminal/ide-terminal-workspace.c
@@ -54,7 +54,7 @@ ide_terminal_workspace_context_set_cb (GtkWidget  *widget,
       bar = g_object_new (IDE_TYPE_OMNI_BAR,
                           "visible", TRUE,
                           NULL);
-      gtk_header_bar_set_custom_title (GTK_HEADER_BAR (self->header_bar), GTK_WIDGET (bar));
+      hdy_header_bar_set_custom_title (HDY_HEADER_BAR (self->header_bar), GTK_WIDGET (bar));
 
       label = g_object_new (GTK_TYPE_LABEL,
                             "visible", TRUE,
diff --git a/src/libide/terminal/ide-terminal-workspace.ui b/src/libide/terminal/ide-terminal-workspace.ui
index 7254daa35..125bb2657 100644
--- a/src/libide/terminal/ide-terminal-workspace.ui
+++ b/src/libide/terminal/ide-terminal-workspace.ui
@@ -6,7 +6,7 @@
     <child type="titlebar">
       <object class="IdeHeaderBar" id="header_bar">
         <property name="show-close-button">true</property>
-        <property name="show-fullscreen-button">true</property>
+        <property name="show-fullscreen-button">false</property>
         <property name="menu-id">ide-terminal-workspace-menu</property>
         <property name="visible">true</property>
         <child type="secondary">
diff --git a/src/plugins/buildui/gbp-buildui-workspace-addin.c 
b/src/plugins/buildui/gbp-buildui-workspace-addin.c
index 703c09f08..0ea51bec7 100644
--- a/src/plugins/buildui/gbp-buildui-workspace-addin.c
+++ b/src/plugins/buildui/gbp-buildui-workspace-addin.c
@@ -277,7 +277,7 @@ gbp_buildui_workspace_addin_load (IdeWorkspaceAddin *addin,
                                               "build-manager.rebuild");
 
   headerbar = ide_workspace_get_header_bar (workspace);
-  omnibar = IDE_OMNI_BAR (gtk_header_bar_get_custom_title (GTK_HEADER_BAR (headerbar)));
+  omnibar = IDE_OMNI_BAR (hdy_header_bar_get_custom_title (HDY_HEADER_BAR (headerbar)));
   workbench = ide_widget_get_workbench (GTK_WIDGET (workspace));
   context = ide_workbench_get_context (workbench);
   build_manager = ide_build_manager_from_context (context);
diff --git a/src/plugins/dspy/gbp-dspy-workspace.ui b/src/plugins/dspy/gbp-dspy-workspace.ui
index 4d920eab4..f67f22ff8 100644
--- a/src/plugins/dspy/gbp-dspy-workspace.ui
+++ b/src/plugins/dspy/gbp-dspy-workspace.ui
@@ -6,7 +6,7 @@
     <child type="titlebar">
       <object class="IdeHeaderBar" id="header_bar">
         <property name="show-close-button">true</property>
-        <property name="show-fullscreen-button">true</property>
+        <property name="show-fullscreen-button">false</property>
         <property name="visible">true</property>
         <child type="title">
           <object class="GtkLabel">


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