[gnome-panel/wip/packed-objects: 12/17] panel: Implement push move for panel objects



commit 21b2290a8001e967e3338cad8d8384bd7a793ea2
Author: Vincent Untz <vuntz gnome org>
Date:   Thu Mar 31 05:09:34 2011 +0530

    panel: Implement push move for panel objects
    
    We simply move all objects before/after us in our pack to the next pack.

 gnome-panel/panel-widget.c |  186 +++++++++++++++++++++++++-------------------
 1 files changed, 106 insertions(+), 80 deletions(-)
---
diff --git a/gnome-panel/panel-widget.c b/gnome-panel/panel-widget.c
index d0c15db..9d3c214 100644
--- a/gnome-panel/panel-widget.c
+++ b/gnome-panel/panel-widget.c
@@ -27,8 +27,6 @@
 #include "panel-globals.h"
 #include "panel-lockdown.h"
 
-#define MOVE_INCREMENT 1
-
 typedef enum {
 	PANEL_SWITCH_MOVE = 0,
 	PANEL_PUSH_MOVE
@@ -91,13 +89,6 @@ static void panel_widget_end_move           (PanelWidget      *panel);
 static gboolean panel_widget_real_focus     (GtkWidget        *widget,
                                              GtkDirectionType  direction);
 
-static gboolean panel_widget_push_applet_right (PanelWidget *panel,
-						GList       *list,
-						int          push);
-static gboolean panel_widget_push_applet_left  (PanelWidget *panel,
-						GList       *list,
-						int          push);
-
 /************************
  convenience functions
  ************************/
@@ -921,6 +912,7 @@ panel_widget_switch_applet_right (PanelWidget *panel,
 			panel_widget_move_to_pack (panel, ad, ad->pack_type + 1, -1);
 		else
 			panel_widget_move_to_pack (panel, ad, ad->pack_type + 1, 0);
+
 		emit_applet_moved (panel, ad);
 
 		panel_widget_update_positions (panel);
@@ -1019,7 +1011,7 @@ panel_widget_switch_move (PanelWidget *panel,
 		}
 	} else {
 		moved = TRUE;
-		while (moved && moveby <= - ad->cells / 2) {
+		while (moved && moveby < - ad->cells / 2) {
 			moved = panel_widget_switch_applet_left (panel, list,
 								 moveby, FALSE);
 			moveby = panel_widget_get_moveby (panel, ad);
@@ -1030,123 +1022,159 @@ panel_widget_switch_move (PanelWidget *panel,
 static int
 panel_widget_push_applet_right (PanelWidget *panel,
 				GList       *list,
-				int          push)
+				int          moveby,
+				gboolean     force_switch)
 {
-	return FALSE;
-#if 0
 	AppletData *ad;
-	AppletData *nad = NULL;
+	AppletData *nad;
+	PanelObjectPackType new_pack_type;
+	GList *l;
+	GList *last_in_pack;
+	int next_pos;
 
-	g_assert (list != NULL);
-	
 	ad = list->data;
-	if (ad->constrained + ad->min_cells + push >= panel->size)
+
+	if (ad->pack_type == PANEL_OBJECT_PACK_END)
 		return FALSE;
 
-	if (list->next)
-		nad = list->next->data;
+	/* count moveby from end of object => remove distance to go there */
+	moveby -= ad->cells / 2;
 
-	if (!nad || nad->constrained >= ad->constrained + ad->min_cells + push) {
-		ad->pos = ad->constrained += push;
-		gtk_widget_queue_resize (GTK_WIDGET (panel));
-		emit_applet_moved (panel, ad);
-		return TRUE;
+	new_pack_type = ad->pack_type + 1;
+
+	for (l = list; l && l->next; l = l->next) {
+		nad = l->next->data;
+		if (nad->pack_type != ad->pack_type)
+			break;
 	}
 
-	g_assert (list->next != NULL);
+	last_in_pack = l;
+
+	nad = last_in_pack->next ? last_in_pack->next->data : NULL;
+	next_pos = panel_widget_move_get_pos_next_pack (panel, ad, nad);
 
-	if (!panel_widget_push_applet_right (panel, list->next, push))
+	if (!force_switch &&
+	    (moveby < (next_pos - (ad->constrained + ad->cells)) / 2))
 		return FALSE;
 
-	ad->pos = ad->constrained += push;;
+	for (l = last_in_pack; l; l = l->prev) {
+		ad = l->data;
+
+		if (new_pack_type == PANEL_OBJECT_PACK_END)
+			panel_widget_move_to_pack (panel, ad, new_pack_type, -1);
+		else
+			panel_widget_move_to_pack (panel, ad, new_pack_type, 0);
+
+		emit_applet_moved (panel, ad);
+
+		if (l == list)
+			break;
+	}
+
+	panel_widget_update_positions (panel);
 	gtk_widget_queue_resize (GTK_WIDGET (panel));
-	emit_applet_moved (panel, ad);
-	
+
 	return TRUE;
-#endif
 }
 
 static int
 panel_widget_push_applet_left (PanelWidget *panel,
 			       GList       *list,
-			       int          push)
+			       int          moveby,
+			       gboolean     force_switch)
 {
-	return FALSE;
-#if 0
 	AppletData *ad;
-	AppletData *pad = NULL;
-
-	g_assert (list != NULL);
+	AppletData *pad;
+	PanelObjectPackType new_pack_type;
+	GList *l;
+	GList *first_in_pack;
+	int prev_pos;
 
 	ad = list->data;
-	if (ad->constrained - push < 0)
+
+	if (ad->pack_type == PANEL_OBJECT_PACK_START)
 		return FALSE;
 
-	if (list->prev)
-		pad = list->prev->data;
+	/* count moveby from start of object => add distance to go there */
+	moveby += ad->cells / 2;
 
-	if (!pad || pad->constrained + pad->min_cells <= ad->constrained - push) {
-		ad->pos = ad->constrained -= push;
-		gtk_widget_queue_resize (GTK_WIDGET (panel));
-		emit_applet_moved (panel, ad);
-		return TRUE;
+	new_pack_type = ad->pack_type - 1;
+
+	for (l = list; l && l->prev; l = l->prev) {
+		pad = l->prev->data;
+		if (pad->pack_type != ad->pack_type)
+			break;
 	}
 
-	g_assert (list->prev != NULL);
+	first_in_pack = l;
 
-	if (!panel_widget_push_applet_left (panel, list->prev, push))
+	pad = first_in_pack->prev ? first_in_pack->prev->data : NULL;
+	prev_pos = panel_widget_move_get_pos_prev_pack (panel, ad, pad);
+
+	if (!force_switch &&
+	    (moveby >  - ((ad->constrained - prev_pos) / 2)))
 		return FALSE;
 
-	ad->pos = ad->constrained -= push;
+	for (l = first_in_pack; l; l = l->next) {
+		ad = l->data;
+
+		panel_widget_move_to_pack (panel, ad, new_pack_type, -1);
+		emit_applet_moved (panel, ad);
+
+		if (l == list)
+			break;
+	}
+
+	panel_widget_update_positions (panel);
 	gtk_widget_queue_resize (GTK_WIDGET (panel));
-	emit_applet_moved (panel, ad);
-	
+
 	return TRUE;
-#endif
 }
 
 static void
 panel_widget_push_move (PanelWidget *panel,
 			AppletData  *ad,
-			int          moveby)
+			int          direction)
 {
-	int finalpos;
 	GList *list;
+	gboolean moved;
+	int      moveby;
+
+	/* direction is only used when we move with keybindings */
 
 	g_return_if_fail (ad != NULL);
 	g_return_if_fail (PANEL_IS_WIDGET (panel));
 
-	if (moveby == 0)
-		return;
-
 	list = g_list_find (panel->applet_list, ad);
 	g_return_if_fail (list != NULL);
 
-	finalpos = ad->constrained + moveby;
+	moveby = panel_widget_get_moveby (panel, ad);
 
-	if (ad->constrained < finalpos) {
-		AppletData *pad;
+	if (direction > 0 || moveby > ad->cells / 2) {
+		moved = TRUE;
+		while (direction > 0 ||
+		       (moved && moveby > ad->cells / 2)) {
+			moved = panel_widget_push_applet_right (panel, list,
+								moveby,
+								direction != 0);
+			moveby = panel_widget_get_moveby (panel, ad);
 
-		while (ad->constrained < finalpos)
-			if (!panel_widget_push_applet_right (panel, list, 1))
+			/* a keybinding pushes only once */
+			if (direction != 0)
 				break;
-
-                if (list->prev) {
-			pad = list->prev->data;
-			if (pad->expand_major)
-				gtk_widget_queue_resize (GTK_WIDGET (panel));
 		}
 	} else {
-		AppletData *nad;
+		moved = TRUE;
+		while (direction < 0 ||
+		       (moved && moveby < ad->cells / 2)) {
+			moved = panel_widget_push_applet_left (panel, list,
+							       moveby,
+							       direction != 0);
+			moveby = panel_widget_get_moveby (panel, ad);
 
-                while (ad->constrained > finalpos)
-			if (!panel_widget_push_applet_left (panel, list, 1))
+			/* a keybinding pushes only once */
+			if (direction != 0)
 				break;
-
-		if (list->next) {
-			nad = list->next->data;
-			if (nad->expand_major)
-				gtk_widget_queue_resize (GTK_WIDGET (panel));
 		}
 	}
 }
@@ -1932,7 +1960,6 @@ static void schedule_try_move (PanelWidget *panel, gboolean repeater);
 static void
 panel_widget_applet_move_to_cursor (PanelWidget *panel)
 {
-	int moveby;
 	int movement;
 	GtkWidget *applet;
 	AppletData *ad;
@@ -2003,8 +2030,7 @@ panel_widget_applet_move_to_cursor (PanelWidget *panel)
 		panel_widget_switch_move (panel, ad);
 		break;
 	case PANEL_PUSH_MOVE:
-		moveby = panel_widget_get_moveby (panel, ad);
-		panel_widget_push_move (panel, ad, moveby);
+		panel_widget_push_move (panel, ad, 0);
 		break;
 	}
 }
@@ -2528,7 +2554,7 @@ panel_widget_push_move_applet (PanelWidget     *panel,
                                GtkDirectionType dir)
 {
 	AppletData *applet;
-	int         increment = 0;
+	int         direction = 0;
 
 	applet = panel->currently_dragged_applet;
 	g_return_if_fail (applet);
@@ -2536,17 +2562,17 @@ panel_widget_push_move_applet (PanelWidget     *panel,
 	switch (dir) {
 	case GTK_DIR_LEFT:
 	case GTK_DIR_UP:
-		increment = -MOVE_INCREMENT;
+		direction = -1;
 		break;
 	case GTK_DIR_RIGHT:
 	case GTK_DIR_DOWN:
-		increment = MOVE_INCREMENT;
+		direction = 1;
 		break;
 	default:
 		return;
 	}
 
-	panel_widget_push_move (panel, applet, increment);
+	panel_widget_push_move (panel, applet, direction);
 }
 
 static void 



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