[libpanel] dock: return adjusted values for drag positions



commit ccf7f82939c419bf4cca3163d0c32542287a4de7
Author: Christian Hergert <chergert redhat com>
Date:   Fri Sep 16 00:12:12 2022 -0700

    dock: return adjusted values for drag positions

 src/panel-dock-child-private.h |  1 +
 src/panel-dock-child.c         |  8 ++++++
 src/panel-dock.c               | 65 ++++++++++++++++++++++++++++++++++++++----
 3 files changed, 69 insertions(+), 5 deletions(-)
---
diff --git a/src/panel-dock-child-private.h b/src/panel-dock-child-private.h
index b3b4c80..c3a210a 100644
--- a/src/panel-dock-child-private.h
+++ b/src/panel-dock-child-private.h
@@ -45,6 +45,7 @@ void       panel_dock_child_set_dragging      (PanelDockChild     *self,
 void       panel_dock_child_foreach_frame     (PanelDockChild     *self,
                                                PanelFrameCallback  callback,
                                                gpointer            user_data);
+int        panel_dock_child_get_drag_position (PanelDockChild     *self);
 void       panel_dock_child_set_drag_position (PanelDockChild     *self,
                                                int                 drag_position);
 
diff --git a/src/panel-dock-child.c b/src/panel-dock-child.c
index 7df8b6d..32b64f5 100644
--- a/src/panel-dock-child.c
+++ b/src/panel-dock-child.c
@@ -410,6 +410,14 @@ panel_dock_child_foreach_frame (PanelDockChild     *self,
     }
 }
 
+int
+panel_dock_child_get_drag_position (PanelDockChild *self)
+{
+  g_return_val_if_fail (PANEL_IS_DOCK_CHILD (self), -1);
+
+  return panel_resizer_get_drag_position (self->resizer);
+}
+
 void
 panel_dock_child_set_drag_position (PanelDockChild *self,
                                     int             drag_position)
diff --git a/src/panel-dock.c b/src/panel-dock.c
index 58eda5c..6f9d8e7 100644
--- a/src/panel-dock.c
+++ b/src/panel-dock.c
@@ -237,6 +237,62 @@ page_unmaximize_action (GtkWidget  *widget,
     }
 }
 
+static int
+get_drag_size (PanelDock *self,
+               PanelArea  area,
+               int        fallback)
+{
+  PanelDockPrivate *priv = panel_dock_get_instance_private (self);
+
+  g_assert (PANEL_IS_DOCK (self));
+
+  for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (priv->grid));
+       child != NULL;
+       child = gtk_widget_get_next_sibling (child))
+    {
+      if (PANEL_IS_DOCK_CHILD (child))
+        {
+          if (area == panel_dock_child_get_area (PANEL_DOCK_CHILD (child)))
+            {
+              int ret = panel_dock_child_get_drag_position (PANEL_DOCK_CHILD (child));
+
+              if (ret > 0)
+                return ret;
+            }
+        }
+    }
+
+  return fallback;
+}
+
+static int
+panel_dock_get_start_width (PanelDock *self)
+{
+  PanelDockPrivate *priv = panel_dock_get_instance_private (self);
+  return get_drag_size (self, PANEL_AREA_START, priv->start_width);
+}
+
+static int
+panel_dock_get_end_width (PanelDock *self)
+{
+  PanelDockPrivate *priv = panel_dock_get_instance_private (self);
+  return get_drag_size (self, PANEL_AREA_END, priv->end_width);
+}
+
+static int
+panel_dock_get_top_height (PanelDock *self)
+{
+  PanelDockPrivate *priv = panel_dock_get_instance_private (self);
+  return get_drag_size (self, PANEL_AREA_TOP, priv->top_height);
+}
+
+static int
+panel_dock_get_bottom_height (PanelDock *self)
+{
+  PanelDockPrivate *priv = panel_dock_get_instance_private (self);
+  return get_drag_size (self, PANEL_AREA_BOTTOM, priv->bottom_height);
+}
+
 static void
 panel_dock_dispose (GObject *object)
 {
@@ -256,7 +312,6 @@ panel_dock_get_property (GObject    *object,
                          GParamSpec *pspec)
 {
   PanelDock *self = PANEL_DOCK (object);
-  PanelDockPrivate *priv = panel_dock_get_instance_private (self);
 
   switch (prop_id)
     {
@@ -293,19 +348,19 @@ panel_dock_get_property (GObject    *object,
       break;
 
     case PROP_START_WIDTH:
-      g_value_set_int (value, priv->start_width);
+      g_value_set_int (value, panel_dock_get_start_width (self));
       break;
 
     case PROP_END_WIDTH:
-      g_value_set_int (value, priv->end_width);
+      g_value_set_int (value, panel_dock_get_end_width (self));
       break;
 
     case PROP_TOP_HEIGHT:
-      g_value_set_int (value, priv->top_height);
+      g_value_set_int (value, panel_dock_get_top_height (self));
       break;
 
     case PROP_BOTTOM_HEIGHT:
-      g_value_set_int (value, priv->bottom_height);
+      g_value_set_int (value, panel_dock_get_bottom_height (self));
       break;
 
     default:


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