← Back to team overview

ayatana-commits team mailing list archive

[Branch ~notify-osd-developers/notify-osd/main] Rev 391: Merged my slot-allocation branch separating gravity from slot-allocation

 

Merge authors:
  Mirco Müller (macslow)
Related merge proposals:
  https://code.launchpad.net/~macslow/notify-osd/slot-allocation/+merge/11521
  proposed by: Mirco Müller (macslow)
  review: Approve - Ted Gould (ted)
------------------------------------------------------------
revno: 391 [merge]
committer: Mirco Müller <mirco.mueller@xxxxxxxxxx>
branch nick: notify-osd
timestamp: Thu 2009-09-10 17:50:08 +0200
message:
  Merged my slot-allocation branch separating gravity from slot-allocation
  scheme.
modified:
  src/defaults.c
  src/defaults.h
  src/display.c
  src/stack.c
  tests/test-defaults.c


--
lp:notify-osd
https://code.launchpad.net/~notify-osd-developers/notify-osd/main

Your team ayatana-commits is subscribed to branch lp:notify-osd.
To unsubscribe from this branch go to https://code.launchpad.net/~notify-osd-developers/notify-osd/main/+edit-subscription.
=== modified file 'src/defaults.c'
--- src/defaults.c	2009-09-01 11:19:59 +0000
+++ src/defaults.c	2009-09-10 13:16:07 +0000
@@ -864,6 +864,9 @@
 		_handle_error (self, error);
 		return;
 	}
+
+	// use fixed slot-allocation for async. and sync. bubbles
+	self->slot_allocation = SLOT_ALLOCATION_FIXED;
 }
 
 static void
@@ -2608,3 +2611,12 @@
 
 	return gravity;
 }
+
+SlotAllocation
+defaults_get_slot_allocation (Defaults *self)
+{
+	if (!self || !IS_DEFAULTS (self))
+		return SLOT_ALLOCATION_NONE;
+
+	return self->slot_allocation;
+}

=== modified file 'src/defaults.h'
--- src/defaults.h	2009-09-01 08:46:33 +0000
+++ src/defaults.h	2009-09-10 13:11:32 +0000
@@ -61,53 +61,61 @@
         GRAVITY_EAST        // vertically centered at right of screen
 } Gravity;
 
+typedef enum
+{
+        SLOT_ALLOCATION_NONE = 0,
+        SLOT_ALLOCATION_FIXED,  // async. always in top, sync. always in bottom
+        SLOT_ALLOCATION_DYNAMIC // async. and sync can take top or bottom
+} SlotAllocation;
+
 /* instance structure */
 struct _Defaults
 {
 	GObject parent;
 
 	/* private */
-	GConfClient* context;
-	guint        notifier[6];
-	gint         desktop_width;
-	gint         desktop_height;
-	gint         desktop_top;
-	gint         desktop_bottom;
-	gint         desktop_left;
-	gint         desktop_right;
-	gdouble      desktop_bottom_gap;
-	gdouble      stack_height;
-	gdouble      bubble_vert_gap;
-	gdouble      bubble_horz_gap;
-	gdouble      bubble_width;
-	gdouble      bubble_min_height;
-	gdouble      bubble_max_height;
-	gdouble      bubble_shadow_size;
-	GString*     bubble_shadow_color;
-	GString*     bubble_bg_color;
-	GString*     bubble_bg_opacity;
-	GString*     bubble_hover_opacity;
-	gdouble      bubble_corner_radius;
-	gdouble      content_shadow_size;
-	GString*     content_shadow_color;
-	gdouble      margin_size;
-	gdouble      icon_size;
-	gdouble      gauge_size;
-	gdouble      gauge_outline_width;
-	gint         fade_in_timeout;
-	gint         fade_out_timeout;
-	gint         on_screen_timeout;
-	GString*     text_font_face;
-	GString*     text_title_color;
-	gint         text_title_weight;
-	gdouble      text_title_size;
-	GString*     text_body_color;
-	gint         text_body_weight;
-	gdouble      text_body_size;
-	gdouble      pixels_per_em;
-	gdouble      system_font_size;
-	gdouble      screen_dpi;
-	Gravity      gravity;
+	GConfClient*   context;
+	guint          notifier[6];
+	gint           desktop_width;
+	gint           desktop_height;
+	gint           desktop_top;
+	gint           desktop_bottom;
+	gint           desktop_left;
+	gint           desktop_right;
+	gdouble        desktop_bottom_gap;
+	gdouble        stack_height;
+	gdouble        bubble_vert_gap;
+	gdouble        bubble_horz_gap;
+	gdouble        bubble_width;
+	gdouble        bubble_min_height;
+	gdouble        bubble_max_height;
+	gdouble        bubble_shadow_size;
+	GString*       bubble_shadow_color;
+	GString*       bubble_bg_color;
+	GString*       bubble_bg_opacity;
+	GString*       bubble_hover_opacity;
+	gdouble        bubble_corner_radius;
+	gdouble        content_shadow_size;
+	GString*       content_shadow_color;
+	gdouble        margin_size;
+	gdouble        icon_size;
+	gdouble        gauge_size;
+	gdouble        gauge_outline_width;
+	gint           fade_in_timeout;
+	gint           fade_out_timeout;
+	gint           on_screen_timeout;
+	GString*       text_font_face;
+	GString*       text_title_color;
+	gint           text_title_weight;
+	gdouble        text_title_size;
+	GString*       text_body_color;
+	gint           text_body_weight;
+	gdouble        text_body_size;
+	gdouble        pixels_per_em;
+	gdouble        system_font_size;
+	gdouble        screen_dpi;
+	Gravity        gravity;
+	SlotAllocation slot_allocation;
 };
 
 /* class structure */
@@ -252,6 +260,9 @@
 Gravity
 defaults_get_gravity (Defaults *self);
 
+SlotAllocation
+defaults_get_slot_allocation (Defaults *self);
+
 G_END_DECLS
 
 #endif /* __DEFAULTS_H */

=== modified file 'src/display.c'
--- src/display.c	2009-09-08 13:26:40 +0000
+++ src/display.c	2009-09-10 13:11:32 +0000
@@ -83,16 +83,39 @@
 	// TODO: with multi-head, in focus follow mode, there may be enough
 	// space left on the top monitor
 
-	switch (defaults_get_gravity (d))
+	switch (defaults_get_slot_allocation (d))
 	{
-		case GRAVITY_NORTH_EAST:
+		case SLOT_ALLOCATION_FIXED:
+			if (stack_is_slot_vacant (self, SLOT_TOP))
+			{
+				stack_get_slot_position (self,
+							 SLOT_TOP,
+							 bubble_get_height (bubble),
+							 &x,
+							 &y);
+				if (x == -1 || y == -1)
+					g_warning ("%s(): No slot-coords!\n",
+						   G_STRFUNC);
+				else
+					stack_allocate_slot (self,
+							     bubble,
+							     SLOT_TOP);
+			}
+			else
+			{
+				g_warning ("%s(): Top slot taken!\n",
+				           G_STRFUNC);
+			}
+		break;
+
+		case SLOT_ALLOCATION_DYNAMIC:
 			// see if we're call at the wrong moment, when both
 			// slots are occupied by bubbles
 			if (!stack_is_slot_vacant (self, SLOT_TOP) &&
 			    !stack_is_slot_vacant (self, SLOT_BOTTOM))
 			{
 				g_warning ("%s(): Both slots taken!\n",
-				           G_STRFUNC);
+					   G_STRFUNC);
 			}
 			else
 			{
@@ -104,31 +127,31 @@
 				    stack_is_slot_vacant (self, SLOT_BOTTOM))
 				{
 					stack_get_slot_position (self,
-						                 SLOT_TOP,
-					                         bubble_get_height (bubble),
-						                 &x,
-						                 &y);
+								 SLOT_TOP,
+								 bubble_get_height (bubble),
+								 &x,
+								 &y);
 					if (x == -1 || y == -1)
 						g_warning ("%s(): No coords!\n",
 							   G_STRFUNC);
 					else
 						stack_allocate_slot (self,
-							             bubble,
-							             SLOT_TOP);
+								     bubble,
+								     SLOT_TOP);
 				}
 				// next check if top is occupied and bottom is
 				// still vacant, then place sync. bubble in
 				// bottom slot
 				else if (!stack_is_slot_vacant (self,
-				                                SLOT_TOP) &&
-				         stack_is_slot_vacant (self,
-				                               SLOT_BOTTOM))
+								SLOT_TOP) &&
+					 stack_is_slot_vacant (self,
+							       SLOT_BOTTOM))
 				{
 					stack_get_slot_position (self,
-						                 SLOT_BOTTOM,
-					                         bubble_get_height (bubble),
-						                 &x,
-						                 &y);
+								 SLOT_BOTTOM,
+								 bubble_get_height (bubble),
+								 &x,
+								 &y);
 					if (x == -1 || y == -1)
 						g_warning ("%s(): No coords!\n",
 							   G_STRFUNC);
@@ -149,44 +172,18 @@
 				// we want to avoid the "gap" between the bottom
 				// bubble and the panel
 				else if (stack_is_slot_vacant (self,
-				                               SLOT_TOP) &&
-				         !stack_is_slot_vacant (self,
-				                                SLOT_BOTTOM))
+							       SLOT_TOP) &&
+					 !stack_is_slot_vacant (self,
+								SLOT_BOTTOM))
 				{
 					g_warning ("%s(): Gap, gap, gap!!!\n",
-					           G_STRFUNC);
+						   G_STRFUNC);
 				}
 			}
 		break;
 
-		case GRAVITY_EAST:
-			// see if reserved top slot for sync. bubble is really
-			// vacant
-			if (stack_is_slot_vacant (self, SLOT_TOP) == OCCUPIED)
-			{
-				g_warning ("%s(): Top slot taken!\n",
-				           G_STRFUNC);
-			}
-			// if not just put sync. bubble in top slot
-			else
-			{
-				stack_get_slot_position (self,
-				                         SLOT_TOP,
-				                         bubble_get_height (bubble),
-				                         &x,
-				                         &y);
-				if (x == -1 || y == -1)
-					g_warning ("%s(): No slot-coords!\n",
-					           G_STRFUNC);
-				else
-					stack_allocate_slot (self,
-					                     bubble,
-					                     SLOT_TOP);
-			}
-		break;
-
-		default:
-			g_warning ("Unhandled gravity!\n");
+		default :
+			g_warning ("Unhandled slot-allocation!\n");
 		break;
 	}
 
@@ -322,124 +319,104 @@
 
 	d = self->defaults;
 
-	switch (defaults_get_gravity (d))
+	switch (defaults_get_slot_allocation (d))
 	{
-		case GRAVITY_NORTH_EAST:
-			if (!stack_is_slot_vacant (self, SLOT_TOP) &&
-			    !stack_is_slot_vacant (self, SLOT_BOTTOM))
-			{
-				g_warning ("%s(): Both slots taken!\n",
-				           G_STRFUNC);
-			}
-			else
-			{
-				if (stack_is_slot_vacant (self, SLOT_TOP))
-				{
-					stack_get_slot_position (self,
-						                 SLOT_TOP,
-					                         bubble_get_height (bubble),
-						                 &x,
-						                 &y);
-					if (x == -1 || y == -1)
-						g_warning ("%s(): No coords!\n",
-							   G_STRFUNC);
-					else
-						stack_allocate_slot (self,
-							             bubble,
-							             SLOT_TOP);
-				}
-				else if (stack_is_slot_vacant (self,
-				                               SLOT_BOTTOM))
-				{
-					stack_get_slot_position (self,
-						                 SLOT_BOTTOM,
-					                         bubble_get_height (bubble),
-						                 &x,
-						                 &y);
-					if (x == -1 || y == -1)
-						g_warning ("%s(): No coords!\n",
-							   G_STRFUNC);
-					else
-						stack_allocate_slot (self,
-							             bubble,
-							             SLOT_BOTTOM);
-				}
-			}
-
-			if (sync_bubble != NULL &&
-			    bubble_is_visible (sync_bubble) &&
-			    sync_bubble == self->slots[SLOT_TOP])
-			{
-				// synchronize the sync bubble with the timeout
-				// of the bubble at the bottom
-				bubble_sync_with (sync_bubble, bubble);
-			}
-		break;
-
-		case GRAVITY_EAST:
-			// with the new placement sync. bubbles are always to be
-			// placed in the top slot (above the "half-line")
-			if (bubble_is_synchronous (bubble))
-			{
-				// verify that the top slot is really vacant
-				if (stack_is_slot_vacant (self, SLOT_TOP))
-				{
-					stack_get_slot_position (self,
-						                 SLOT_TOP,
-					                         bubble_get_height (bubble),
-						                 &x,
-						                 &y);
-					if (x == -1 || y == -1)
-						g_warning ("%s(): No coords!\n",
-							   G_STRFUNC);
-					else
-						stack_allocate_slot (self,
-							             bubble,
-							             SLOT_TOP);
-				}
-				// otherwise there's still an error in the
-				// layout- and queue-logic
-				else
-				{
-					g_warning ("%s(): Can't put sync. "
-					           "bubble in top slot!\n",
-					           G_STRFUNC);
-				}
-			}
-			// an async. bubble is always meant to be put in the
-			// bottom slot (below the "half-line")
-			else
-			{
-				// verify that the bottom slot is really vacant
-				if (stack_is_slot_vacant (self, SLOT_BOTTOM))
-				{
-					stack_get_slot_position (self,
-						                 SLOT_BOTTOM,
-					                         bubble_get_height (bubble),
-						                 &x,
-						                 &y);
-					if (x == -1 || y == -1)
-						g_warning ("%s(): No coords!\n",
-							   G_STRFUNC);
-					else
-						stack_allocate_slot (
-							self,
-							bubble,
-							SLOT_BOTTOM);
-				}
-				// otherwise there's still an error in the
-				// layout- and queue-logic
-				else
-				{
-					g_warning ("%s(): Can't put async. "
-					           "bubble in bottom slot!\n",
-					           G_STRFUNC);
-				}
-			}
-		break;
-
-		default:
-			g_warning ("Unhandled gravity!\n");
+		case SLOT_ALLOCATION_FIXED:
+			if (stack_is_slot_vacant (self, SLOT_TOP) &&
+			    bubble_is_synchronous (bubble))
+			{
+				stack_get_slot_position (self,
+						         SLOT_TOP,
+					                 bubble_get_height (bubble),
+						         &x,
+						         &y);
+				if (x == -1 || y == -1)
+					g_warning ("%s(): No coords!\n",
+						   G_STRFUNC);
+				else
+					stack_allocate_slot (self,
+							     bubble,
+							     SLOT_TOP);
+			}
+			else if (stack_is_slot_vacant (self, SLOT_BOTTOM) &&
+				 !bubble_is_synchronous (bubble))
+			{
+				stack_get_slot_position (self,
+						         SLOT_BOTTOM,
+					                 bubble_get_height (bubble),
+						         &x,
+						         &y);
+				if (x == -1 || y == -1)
+					g_warning ("%s(): No coords!\n",
+						   G_STRFUNC);
+				else
+					stack_allocate_slot (self,
+							     bubble,
+							     SLOT_BOTTOM);
+			}
+			else
+			{
+				g_warning ("%s(): Error while handling fixed "
+				           "slot-allocation!\n",
+				           G_STRFUNC);
+			}
+		break;
+
+		case SLOT_ALLOCATION_DYNAMIC:
+			if (stack_is_slot_vacant (self, SLOT_TOP) &&
+			    stack_is_slot_vacant (self, SLOT_BOTTOM))
+			{
+				stack_get_slot_position (self,
+						         SLOT_TOP,
+					                 bubble_get_height (bubble),
+						         &x,
+						         &y);
+				if (x == -1 || y == -1)
+					g_warning ("%s(): No coords!\n",
+						   G_STRFUNC);
+				else
+					stack_allocate_slot (self,
+							     bubble,
+							     SLOT_TOP);
+			}
+			else if (!stack_is_slot_vacant (self, SLOT_TOP) &&
+				 stack_is_slot_vacant (self, SLOT_BOTTOM))
+			{
+				stack_get_slot_position (self,
+						         SLOT_BOTTOM,
+					                 bubble_get_height (bubble),
+						         &x,
+						         &y);
+				if (x == -1 || y == -1)
+					g_warning ("%s(): No coords!\n",
+						   G_STRFUNC);
+				else
+				{
+					stack_allocate_slot (self,
+							     bubble,
+							     SLOT_BOTTOM);
+
+					if (sync_bubble != NULL &&
+					    bubble_is_visible (sync_bubble))
+					{
+						// synchronize the sync bubble with the timeout
+						// of the bubble at the bottom
+						bubble_sync_with (self->slots[SLOT_TOP],
+						                  self->slots[SLOT_BOTTOM]);
+					}
+				}
+			}
+			else
+			{
+				g_warning ("%s(): Error while handling dynamic "
+				           "slot-allocation!\n",
+				           G_STRFUNC);
+			}
+		break;
+
+		default :
+			g_warning ("%s(): Unhandled slot-allocation scheme!\n",
+			           G_STRFUNC);
 		break;
 	}
 

=== modified file 'src/stack.c'
--- src/stack.c	2009-09-09 22:42:11 +0000
+++ src/stack.c	2009-09-10 13:11:32 +0000
@@ -911,10 +911,25 @@
 			// top slot
 			if (slot == SLOT_BOTTOM)
 			{
-				g_assert (stack_is_slot_vacant (self, SLOT_TOP) == OCCUPIED);
-				*y += bubble_get_height (self->slots[SLOT_TOP]) +
-				      EM2PIXELS (defaults_get_bubble_vert_gap (d), d) -
-				      2 * EM2PIXELS (defaults_get_bubble_shadow_size (d), d);
+				switch (defaults_get_slot_allocation (d))
+				{
+					case SLOT_ALLOCATION_FIXED:
+						*y += EM2PIXELS (defaults_get_icon_size (d), d) +
+						      2 * EM2PIXELS (defaults_get_margin_size (d), d) +
+						      EM2PIXELS (defaults_get_bubble_vert_gap (d), d); /* +
+						      2 * EM2PIXELS (defaults_get_bubble_shadow_size (d), d);*/
+					break;
+
+					case SLOT_ALLOCATION_DYNAMIC:
+						g_assert (stack_is_slot_vacant (self, SLOT_TOP) == OCCUPIED);
+						*y += bubble_get_height (self->slots[SLOT_TOP]) +
+						      EM2PIXELS (defaults_get_bubble_vert_gap (d), d) -
+						      2 * EM2PIXELS (defaults_get_bubble_shadow_size (d), d);
+					break;
+
+					default:
+					break;
+				}
 
 			}
 		break;

=== modified file 'tests/test-defaults.c'
--- tests/test-defaults.c	2009-08-31 13:56:28 +0000
+++ tests/test-defaults.c	2009-09-10 13:11:32 +0000
@@ -164,6 +164,29 @@
         g_object_unref (G_OBJECT (defaults));
 }
 
+static void
+test_defaults_get_slot_allocation ()
+{
+        Defaults* defaults = defaults_new ();
+
+        // upon creation slot-allocation should not be unset
+        g_assert_cmpint (defaults_get_slot_allocation (defaults),
+                         !=,
+                         SLOT_ALLOCATION_NONE);
+
+        // currently the default value should be SLOT_ALLOCATION_FIXED
+        g_assert_cmpint (defaults_get_slot_allocation (defaults),
+                         ==,
+                         SLOT_ALLOCATION_FIXED);
+
+        // check if we can pass "crap" to the call without causing a crash
+        g_assert_cmpint (defaults_get_slot_allocation (NULL),
+                         ==,
+                         SLOT_ALLOCATION_NONE);
+
+        g_object_unref (G_OBJECT (defaults));
+}
+
 GTestSuite *
 test_defaults_create_test_suite (void)
 {
@@ -184,6 +207,7 @@
 	g_test_suite_add(ts, TC(test_defaults_get_stack_height));
 	g_test_suite_add(ts, TC(test_defaults_get_bubble_width));
 	g_test_suite_add(ts, TC(test_defaults_get_gravity));
+	g_test_suite_add(ts, TC(test_defaults_get_slot_allocation));
 
 	return ts;
 }