[libpanel] frame: add panel_frame_get_position()



commit 11dc15cf076f39b62889d1308709a7be7c7081bb
Author: Christian Hergert <chergert redhat com>
Date:   Thu Sep 15 20:25:51 2022 -0700

    frame: add panel_frame_get_position()
    
    This function is meant to give you something reasonable whether the
    frame is within a dock edge or center w/ a grid.

 src/panel-frame.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/panel-frame.h |  2 ++
 2 files changed, 59 insertions(+)
---
diff --git a/src/panel-frame.c b/src/panel-frame.c
index 79a84fa..87e3125 100644
--- a/src/panel-frame.c
+++ b/src/panel-frame.c
@@ -30,6 +30,8 @@
 #include "panel-grid-column-private.h"
 #include "panel-joined-menu-private.h"
 #include "panel-paned.h"
+#include "panel-position.h"
+#include "panel-resizer-private.h"
 #include "panel-save-delegate.h"
 #include "panel-save-dialog.h"
 #include "panel-scaler-private.h"
@@ -1358,3 +1360,58 @@ panel_frame_get_closeable (PanelFrame *self)
 
   return priv->closeable;
 }
+
+/**
+ * panel_frame_get_position:
+ * @self: a #PanelFrame
+ *
+ * Gets the #PanelPosition for the frame.
+ *
+ * Returns: (transfer full): a #PanelPosition
+ */
+PanelPosition *
+panel_frame_get_position (PanelFrame *self)
+{
+  PanelPosition *position;
+  GtkWidget *last_resizer = NULL;
+
+  g_return_val_if_fail (PANEL_IS_FRAME (self), NULL);
+
+  position = panel_position_new ();
+
+  for (GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (self));
+       parent != NULL;
+       parent = gtk_widget_get_parent (parent))
+    {
+      if (PANEL_IS_DOCK_CHILD (parent))
+        {
+          panel_position_set_area (position,
+                                   panel_dock_child_get_area (PANEL_DOCK_CHILD (parent)));
+          break;
+        }
+
+      if (PANEL_IS_RESIZER (parent))
+        {
+          last_resizer = parent;
+          continue;
+        }
+
+      if (PANEL_IS_PANED (parent))
+        {
+          GtkOrientation orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (parent));
+          int index = 0;
+
+          for (GtkWidget *sibling = gtk_widget_get_prev_sibling (last_resizer);
+               sibling != NULL;
+               sibling = gtk_widget_get_prev_sibling (sibling))
+            index++;
+
+          if (orientation == GTK_ORIENTATION_HORIZONTAL)
+            panel_position_set_column (position, index);
+          else if (orientation == GTK_ORIENTATION_VERTICAL)
+            panel_position_set_row (position, index);
+        }
+    }
+
+  return g_steal_pointer (&position);
+}
diff --git a/src/panel-frame.h b/src/panel-frame.h
index 567d16d..b049f5d 100644
--- a/src/panel-frame.h
+++ b/src/panel-frame.h
@@ -77,5 +77,7 @@ GtkWidget         *panel_frame_get_placeholder   (PanelFrame       *self);
 PANEL_AVAILABLE_IN_ALL
 void               panel_frame_set_placeholder   (PanelFrame       *self,
                                                   GtkWidget        *placeholder);
+PANEL_AVAILABLE_IN_ALL
+PanelPosition     *panel_frame_get_position      (PanelFrame       *self);
 
 G_END_DECLS


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