[gnome-panel/wip/packed-objects: 7/17] panel: Add a center pack type for objects and make clock centered



commit c0acda10f22e26047e3819df982ded00dd9f5b06
Author: Vincent Untz <vuntz gnome org>
Date:   Wed Mar 30 21:48:28 2011 +0530

    panel: Add a center pack type for objects and make clock centered
    
    Woo. Of course, moving/adding objects is still a bad idea.

 data/panel-default-layout.layout    |    4 +-
 gnome-panel/panel-enums-gsettings.h |    5 ++-
 gnome-panel/panel-widget.c          |   51 ++++++++++++++++++++++++++++++++++-
 3 files changed, 55 insertions(+), 5 deletions(-)
---
diff --git a/data/panel-default-layout.layout b/data/panel-default-layout.layout
index 01c80ae..8659613 100644
--- a/data/panel-default-layout.layout
+++ b/data/panel-default-layout.layout
@@ -17,14 +17,14 @@ pack-index=0
 [Object clock]
 object-iid=ClockAppletFactory::ClockApplet
 toplevel-id=top-panel
-pack-type=end
+pack-type=center
 pack-index=0
 
 [Object notification-area]
 object-iid=NotificationAreaAppletFactory::NotificationArea
 toplevel-id=top-panel
 pack-type=end
-pack-index=1
+pack-index=0
 
 [Object window-list]
 object-iid=WnckletFactory::WindowListApplet
diff --git a/gnome-panel/panel-enums-gsettings.h b/gnome-panel/panel-enums-gsettings.h
index 0fb14c1..27a814e 100644
--- a/gnome-panel/panel-enums-gsettings.h
+++ b/gnome-panel/panel-enums-gsettings.h
@@ -30,8 +30,9 @@
 G_BEGIN_DECLS
 
 typedef enum {
-	PANEL_OBJECT_PACK_START = 0,
-	PANEL_OBJECT_PACK_END   = 1
+	PANEL_OBJECT_PACK_START  = 0,
+	PANEL_OBJECT_PACK_CENTER = 1,
+	PANEL_OBJECT_PACK_END    = 2
 } PanelObjectPackType;
 
 typedef enum { /*< flags=0 >*/
diff --git a/gnome-panel/panel-widget.c b/gnome-panel/panel-widget.c
index 48ae1c6..af752d3 100644
--- a/gnome-panel/panel-widget.c
+++ b/gnome-panel/panel-widget.c
@@ -900,6 +900,47 @@ panel_widget_update_packed_start (PanelWidget *panel)
 }
 
 /* Note: only use this function when you can; see comment above
+ * panel_widget_update_packed_start()
+ * For center specifically, we require ad->cells to be set. Note that we don't
+ * care much about min_cells: if we need it, this means objects will have to be
+ * pushed to accomodate other objects, which will kill centering anyway.
+ * (FIXME: hrm, not that sure about it ;-)) */
+static void
+panel_widget_update_packed_center (PanelWidget *panel)
+{
+	GList *list,*l;
+	AppletData *ad;
+	int size_all = 0;
+	int pos_next;
+
+	if (panel->packed)
+		return;
+
+	list = get_applet_list_pack (panel, PANEL_OBJECT_PACK_CENTER);
+
+	/* get size used by the objects */
+	for (l = list; l; l = l->next) {
+		ad = l->data;
+		size_all += ad->cells;
+	}
+
+	/* update absolute position of all applets based on this information,
+	 * starting with the first centered object */
+	pos_next = (panel->size - size_all) / 2;
+	l = list;
+
+	while (l) {
+		ad = l->data;
+		ad->abs_pos = pos_next;
+		pos_next += 1; /* += ad->cells is the exact right value, but 1
+				  is enough for the order */
+		l = l->next;
+	}
+
+	g_list_free (list);
+}
+
+/* Note: only use this function when you can; see comment above
  * panel_widget_update_packed_start() */
 static void
 panel_widget_update_packed_end (PanelWidget *panel)
@@ -1205,6 +1246,7 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
 
 		/* Re-compute the position of objects, based on their size */
 		panel_widget_update_packed_start (panel);
+		panel_widget_update_packed_center (panel);
 		panel_widget_update_packed_end (panel);
 
 		/* Second pass: try to position from the start, to make sure
@@ -2258,7 +2300,9 @@ panel_widget_add (PanelWidget         *panel,
 				pack_type = PANEL_OBJECT_PACK_END;
 				pack_index = 0;
 			} else {
-				list = get_applet_list_pack (panel, PANEL_OBJECT_PACK_START);
+				list = get_applet_list_pack (panel, PANEL_OBJECT_PACK_CENTER);
+				if (!list)
+					list = get_applet_list_pack (panel, PANEL_OBJECT_PACK_START);
 
 				if (!list) {
 					pack_type = PANEL_OBJECT_PACK_START;
@@ -2275,6 +2319,11 @@ panel_widget_add (PanelWidget         *panel,
 		} else {
 			GList *list,*l;
 
+			/* only support adding to start/end packs if no index
+			 * is provided */
+			if (pack_type == PANEL_OBJECT_PACK_CENTER)
+				pack_type = PANEL_OBJECT_PACK_START;
+
 			list = get_applet_list_pack (panel, pack_type);
 
 			l = NULL;



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