[gnome-builder/wip/gtk4-port] libide/gui: add API for overlays



commit 1b94f9d4c6975931a97010495761910c1747de43
Author: Christian Hergert <chergert redhat com>
Date:   Mon Apr 18 07:10:35 2022 -0700

    libide/gui: add API for overlays
    
    These generally are only used on the primary workspace, but we could
    open them up elsewhere too if they are necessary, such as the editor
    workspace.

 src/libide/gui/ide-primary-workspace.c  | 26 ++++++++++++++++++++++++++
 src/libide/gui/ide-primary-workspace.ui |  6 +++++-
 src/libide/gui/ide-workspace.c          | 29 +++++++++++++++++++++++++++++
 src/libide/gui/ide-workspace.h          | 10 ++++++++++
 4 files changed, 70 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/gui/ide-primary-workspace.c b/src/libide/gui/ide-primary-workspace.c
index 09e9a2fbd..8a3a12d75 100644
--- a/src/libide/gui/ide-primary-workspace.c
+++ b/src/libide/gui/ide-primary-workspace.c
@@ -59,6 +59,7 @@ struct _IdePrimaryWorkspace
   PanelPaned         *edge_end;
   PanelPaned         *edge_bottom;
   IdeGrid            *grid;
+  GtkOverlay         *overlay;
 };
 
 G_DEFINE_FINAL_TYPE (IdePrimaryWorkspace, ide_primary_workspace, IDE_TYPE_WORKSPACE)
@@ -122,6 +123,28 @@ ide_primary_workspace_add_pane (IdeWorkspace     *workspace,
                              self->grid);
 }
 
+static void
+ide_primary_workspace_add_overlay (IdeWorkspace *workspace,
+                                   GtkWidget    *overlay)
+{
+  IdePrimaryWorkspace *self = (IdePrimaryWorkspace *)workspace;
+
+  g_assert (IDE_IS_PRIMARY_WORKSPACE (self));
+
+  gtk_overlay_add_overlay (self->overlay, overlay);
+}
+
+static void
+ide_primary_workspace_remove_overlay (IdeWorkspace *workspace,
+                                      GtkWidget    *overlay)
+{
+  IdePrimaryWorkspace *self = (IdePrimaryWorkspace *)workspace;
+
+  g_assert (IDE_IS_PRIMARY_WORKSPACE (self));
+
+  gtk_overlay_remove_overlay (self->overlay, overlay);
+}
+
 static IdeFrame *
 ide_primary_workspace_get_most_recent_frame (IdeWorkspace *workspace)
 {
@@ -181,6 +204,8 @@ ide_primary_workspace_class_init (IdePrimaryWorkspaceClass *klass)
 
   workspace_class->add_page = ide_primary_workspace_add_page;
   workspace_class->add_pane = ide_primary_workspace_add_pane;
+  workspace_class->add_overlay = ide_primary_workspace_add_overlay;
+  workspace_class->remove_overlay = ide_primary_workspace_remove_overlay;
   workspace_class->can_search = ide_primary_workspace_can_search;
   workspace_class->context_set = ide_primary_workspace_context_set;
   workspace_class->get_frame_at_position = ide_primary_workspace_get_frame_at_position;
@@ -196,6 +221,7 @@ ide_primary_workspace_class_init (IdePrimaryWorkspaceClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, edge_start);
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, grid);
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, header_bar);
+  gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, overlay);
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, project_title);
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, run_button);
 
diff --git a/src/libide/gui/ide-primary-workspace.ui b/src/libide/gui/ide-primary-workspace.ui
index 06709b5e0..f768da093 100644
--- a/src/libide/gui/ide-primary-workspace.ui
+++ b/src/libide/gui/ide-primary-workspace.ui
@@ -62,7 +62,11 @@
         <property name="reveal-start">true</property>
         <property name="vexpand">true</property>
         <child type="center">
-          <object class="IdeGrid" id="grid">
+          <object class="GtkOverlay" id="overlay">
+            <child>
+              <object class="IdeGrid" id="grid">
+              </object>
+            </child>
           </object>
         </child>
         <child type="start">
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index 6312127c0..02bbdca83 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -1285,3 +1285,32 @@ _ide_workspace_begin_global_search (IdeWorkspace *self)
   if (!gtk_widget_get_visible (GTK_WIDGET (priv->search_popover)))
     gtk_popover_popup (GTK_POPOVER (priv->search_popover));
 }
+
+void
+ide_workspace_add_overlay (IdeWorkspace *self,
+                           GtkWidget    *overlay)
+{
+  g_return_if_fail (IDE_IS_WORKSPACE (self));
+  g_return_if_fail (GTK_IS_WIDGET (overlay));
+  g_return_if_fail (gtk_widget_get_parent (overlay) == NULL);
+
+  if (IDE_WORKSPACE_GET_CLASS (self)->add_overlay == NULL)
+    g_critical ("Attempt to add overlay of type %s to workspace of type %s which does not support overlays",
+                G_OBJECT_TYPE_NAME (overlay), G_OBJECT_TYPE_NAME (self));
+  else
+    IDE_WORKSPACE_GET_CLASS (self)->add_overlay (self, overlay);
+}
+
+void
+ide_workspace_remove_overlay (IdeWorkspace *self,
+                              GtkWidget    *overlay)
+{
+  g_return_if_fail (IDE_IS_WORKSPACE (self));
+  g_return_if_fail (GTK_IS_WIDGET (overlay));
+
+  if (IDE_WORKSPACE_GET_CLASS (self)->remove_overlay == NULL)
+    g_critical ("Attempt to remove overlay of type %s to workspace of type %s which does not support 
overlays",
+                G_OBJECT_TYPE_NAME (overlay), G_OBJECT_TYPE_NAME (self));
+  else
+    IDE_WORKSPACE_GET_CLASS (self)->remove_overlay (self, overlay);
+}
diff --git a/src/libide/gui/ide-workspace.h b/src/libide/gui/ide-workspace.h
index fc2f43305..d0e29fda6 100644
--- a/src/libide/gui/ide-workspace.h
+++ b/src/libide/gui/ide-workspace.h
@@ -74,6 +74,10 @@ struct _IdeWorkspaceClass
   void        (*add_page)              (IdeWorkspace         *self,
                                         IdePage              *page,
                                         IdePanelPosition     *position);
+  void        (*add_overlay)           (IdeWorkspace         *self,
+                                        GtkWidget            *overlay);
+  void        (*remove_overlay)        (IdeWorkspace         *self,
+                                        GtkWidget            *overlay);
   PanelFrame *(*get_frame_at_position) (IdeWorkspace         *self,
                                         IdePanelPosition     *position);
   void        (*restore_size)          (IdeWorkspace         *self,
@@ -115,5 +119,11 @@ void            ide_workspace_add_page                 (IdeWorkspace      *self,
                                                         IdePanelPosition  *position);
 IDE_AVAILABLE_IN_ALL
 PanelStatusbar *ide_workspace_get_statusbar            (IdeWorkspace      *self);
+IDE_AVAILABLE_IN_ALL
+void            ide_workspace_add_overlay              (IdeWorkspace      *self,
+                                                        GtkWidget         *widget);
+IDE_AVAILABLE_IN_ALL
+void            ide_workspace_remove_overlay           (IdeWorkspace      *self,
+                                                        GtkWidget         *widget);
 
 G_END_DECLS


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