[libpanel] widget: add helper to get widget position within dock/grid/frame



commit b3bcce081c435583b99909959546c6b6d0a48a94
Author: Christian Hergert <chergert redhat com>
Date:   Thu Sep 15 20:26:08 2022 -0700

    widget: add helper to get widget position within dock/grid/frame

 src/panel-widget.c | 37 +++++++++++++++++++++++++++++++++++++
 src/panel-widget.h |  2 ++
 2 files changed, 39 insertions(+)
---
diff --git a/src/panel-widget.c b/src/panel-widget.c
index 5e089da..ed78e4f 100644
--- a/src/panel-widget.c
+++ b/src/panel-widget.c
@@ -48,6 +48,7 @@
 #include "panel-dock-private.h"
 #include "panel-dock-child-private.h"
 #include "panel-frame-private.h"
+#include "panel-position.h"
 #include "panel-save-delegate.h"
 #include "panel-widget-private.h"
 
@@ -1549,3 +1550,39 @@ panel_widget_action_set_enabled (PanelWidget *self,
         }
     }
 }
+
+/**
+ * panel_widget_get_position:
+ * @self: a #PanelWidget
+ *
+ * Gets teh position of the widget within the dock.
+ *
+ * Returns: (transfer full) (nullable): a #PanelPosition or %NULL if the
+ *   widget isn't within a #PanelFrame.
+ */
+PanelPosition *
+panel_widget_get_position (PanelWidget *self)
+{
+  PanelFrame *frame;
+  PanelPosition *position;
+  guint n_pages;
+
+  g_return_val_if_fail (PANEL_IS_WIDGET (self), NULL);
+
+  if (!(frame = PANEL_FRAME (gtk_widget_get_ancestor (GTK_WIDGET (self), PANEL_TYPE_FRAME))))
+    return NULL;
+
+  position = panel_frame_get_position (frame);
+  n_pages = panel_frame_get_n_pages (frame);
+
+  for (guint i = 0; i < n_pages; i++)
+    {
+      if (panel_frame_get_page (frame, i) == self)
+        {
+          panel_position_set_depth (position, i);
+          break;
+        }
+    }
+
+  return g_steal_pointer (&position);
+}
diff --git a/src/panel-widget.h b/src/panel-widget.h
index de94200..7f931a4 100644
--- a/src/panel-widget.h
+++ b/src/panel-widget.h
@@ -110,6 +110,8 @@ PANEL_AVAILABLE_IN_ALL
 void               panel_widget_set_menu_model                (PanelWidget                 *self,
                                                                GMenuModel                  *menu_model);
 PANEL_AVAILABLE_IN_ALL
+PanelPosition     *panel_widget_get_position                  (PanelWidget                 *self);
+PANEL_AVAILABLE_IN_ALL
 void               panel_widget_raise                         (PanelWidget                 *self);
 PANEL_AVAILABLE_IN_ALL
 GtkWidget         *panel_widget_get_default_focus             (PanelWidget                 *self);


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