Index: src/terminal-notebook.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-notebook.c,v
retrieving revision 1.8
diff -u -B -r1.8 terminal-notebook.c
--- src/terminal-notebook.c	30 Jan 2006 04:15:18 -0000	1.8
+++ src/terminal-notebook.c	8 May 2006 12:35:43 -0000
@@ -35,42 +35,21 @@
 
 struct _TerminalNotebookPrivate
 {
-  gulong   motion_notify_handler_id;
-  gulong   grab_notify_handler_id;
-  gulong   toplevel_grab_broken_handler_id;
-  gulong   toplevel_motion_notify_handler_id;
-  gulong   toplevel_button_release_handler_id;
-  gint     x_start, y_start;
-  gboolean drag_in_progress;
   GtkTooltips *tooltips;
 };
 
 static void terminal_notebook_init           (TerminalNotebook *notebook);
 static void terminal_notebook_class_init     (TerminalNotebookClass *klass);
 static void terminal_notebook_finalize       (GObject *object);
-static void move_tab_to_another_notebook     (TerminalNotebook *src,
-                                              TerminalNotebook *dest,
-                                              GdkEventMotion   *event,
-                                              int               dest_position);
-static void move_tab                         (TerminalNotebook *notebook,
-                                              int               dest_position);
-          
-/* Local variables */
-static GdkCursor *cursor = NULL;
-
-enum
-{
-  TAB_ADDED,
-  TAB_REMOVED,
-  TABS_REORDERED,
-  TAB_DETACHED,
-  TAB_DELETE,
-  LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = { 0 };
+static int  terminal_notebook_insert_page    (GtkNotebook *notebook,
+                                              GtkWidget *child,
+                                              GtkWidget *tab_label,
+                                              GtkWidget *menu_label,
+                                              int position);
+static void terminal_notebook_remove         (GtkContainer *container,
+                                              GtkWidget *tab_widget);
 
-static GObjectClass *parent_class = NULL;
+static GObjectClass *parent_class;
 
 GType
 terminal_notebook_get_type (void)
@@ -91,11 +70,11 @@
           0, /* n_preallocs */
           (GInstanceInitFunc) terminal_notebook_init
         };
-  
+
       type = g_type_register_static (GTK_TYPE_NOTEBOOK,
                                      "TerminalNotebook",
                                      &our_info, 0);
-  
+
     }
 
   return type;
@@ -105,54 +84,19 @@
 terminal_notebook_class_init (TerminalNotebookClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
+  GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass);
 
   parent_class = g_type_class_peek_parent (klass);
 
   object_class->finalize = terminal_notebook_finalize;
-
-  signals[TAB_ADDED] =
-    g_signal_new ("tab_added",
-                  G_OBJECT_CLASS_TYPE (object_class),
-                  G_SIGNAL_RUN_FIRST,
-                  G_STRUCT_OFFSET (TerminalNotebookClass, tab_added),
-                  NULL, NULL,
-                  g_cclosure_marshal_VOID__OBJECT,
-                  G_TYPE_NONE,
-                  1,
-                  TERMINAL_TYPE_SCREEN);
-  signals[TAB_REMOVED] =
-    g_signal_new ("tab_removed",
-                  G_OBJECT_CLASS_TYPE (object_class),
-                  G_SIGNAL_RUN_FIRST,
-                  G_STRUCT_OFFSET (TerminalNotebookClass, tab_removed),
-                  NULL, NULL,
-                  g_cclosure_marshal_VOID__OBJECT,
-                  G_TYPE_NONE,
-                  1,
-                  TERMINAL_TYPE_SCREEN);
-  signals[TAB_DETACHED] =
-    g_signal_new ("tab_detached",
-                  G_OBJECT_CLASS_TYPE (object_class),
-                  G_SIGNAL_RUN_FIRST,
-                  G_STRUCT_OFFSET (TerminalNotebookClass, tab_detached),
-                  NULL, NULL,
-                  g_cclosure_marshal_VOID__OBJECT,
-                  G_TYPE_NONE,
-                  1,
-                  TERMINAL_TYPE_SCREEN);
-  signals[TABS_REORDERED] =
-    g_signal_new ("tabs_reordered",
-                  G_OBJECT_CLASS_TYPE (object_class),
-                  G_SIGNAL_RUN_FIRST,
-                  G_STRUCT_OFFSET (TerminalNotebookClass, tabs_reordered),
-                  NULL, NULL,
-                  g_cclosure_marshal_VOID__VOID,
-                  G_TYPE_NONE,
-                  0);
+  container_class->remove = terminal_notebook_remove;
+  notebook_class->insert_page = terminal_notebook_insert_page;
 
   g_type_class_add_private (object_class, sizeof(TerminalNotebookPrivate));
 }
 
+/* FIXME remove when gtknotebook's func for this becomes public, bug #... */
 static TerminalNotebook *
 find_notebook_at_pointer (gint abs_x, gint abs_y)
 {
@@ -209,27 +153,34 @@
       return AFTER_ALL_TABS;
     }
 
+  /* For some reason unfullscreen + quick click can
+     cause a wrong click event to be reported to the tab */
+  if (!is_in_notebook_window(notebook, abs_x, abs_y))
+    {
+      return NOT_IN_APP_WINDOWS;
+    }
+
   while ((page = gtk_notebook_get_nth_page (nb, page_num)))
     {
       GtkWidget *screen;
       gint max_x, max_y;
       gint x_root, y_root;
-  
+
       screen = gtk_notebook_get_tab_label (nb, page);
       g_return_val_if_fail (screen != NULL, -1);
-  
+
       if (!GTK_WIDGET_MAPPED (GTK_WIDGET (screen)))
        {
          page_num++;
          continue;
        }
-  
+
       gdk_window_get_origin (GDK_WINDOW (screen->window),
                              &x_root, &y_root);
-  
+
       max_x = x_root + screen->allocation.x + screen->allocation.width;
       max_y = y_root + screen->allocation.y + screen->allocation.height;
-  
+
       if (((tab_pos == GTK_POS_TOP) || (tab_pos == GTK_POS_BOTTOM))
           &&(abs_x<=max_x))
         {
@@ -240,33 +191,12 @@
         {
           return page_num;
         }
-  
+
       page_num++;
     }
   return AFTER_ALL_TABS;
 }
 
-static gint find_notebook_and_tab_at_pos (gint abs_x, gint abs_y,
-                                          TerminalNotebook **notebook,
-                                          gint *page_num)
-{
-  *notebook = find_notebook_at_pointer (abs_x, abs_y);
-  if (*notebook == NULL)
-    {
-      return NOT_IN_APP_WINDOWS;
-    }
-  *page_num = find_tab_num_at_pos (*notebook, abs_x, abs_y);
-
-  if (*page_num < 0)
-    {
-      return *page_num;
-    }
-  else
-    {
-      return 0;
-    }
-}
-
 void
 terminal_notebook_move_tab (TerminalNotebook *src,
                             TerminalNotebook *dest,
@@ -277,11 +207,6 @@
     {
       gtk_notebook_reorder_child
         (GTK_NOTEBOOK (src), GTK_WIDGET (screen), dest_position);
-      
-      if (src->priv->drag_in_progress == FALSE)
-        {
-          g_signal_emit (G_OBJECT (src), signals[TABS_REORDERED], 0);
-        }
     }
   else
     {
@@ -290,325 +215,23 @@
       /* make sure the screen isn't destroyed while we move it */
       g_object_ref (screen);
 
-      terminal_notebook_remove_tab (src, screen);
+      gtk_container_remove (GTK_CONTAINER (src), GTK_WIDGET (screen));
 
       /* Set new window for screen so TerminalScreen widget realize function
        * works.
        */
       toplevel = gtk_widget_get_toplevel (GTK_WIDGET (dest));
-      
+
       g_assert (GTK_WIDGET_TOPLEVEL (toplevel));
       g_assert (TERMINAL_IS_WINDOW (toplevel));
 
       terminal_screen_set_window (screen, TERMINAL_WINDOW(toplevel));
-   
+
       terminal_notebook_add_tab (dest, screen, dest_position, TRUE);
       g_object_unref (screen);
     }
 }
 
-static void
-drag_stop (TerminalNotebook *notebook,
-           guint32 time)
-{
-  TerminalNotebookPrivate *priv = notebook->priv;
-  GtkWidget *widget = GTK_WIDGET (notebook);
-  GtkWidget *toplevel, *child;
-
-  if (priv->drag_in_progress)
-    {
-      toplevel = gtk_widget_get_toplevel (widget);
-      g_return_if_fail (GTK_WIDGET_TOPLEVEL (toplevel));
-
-      child = gtk_bin_get_child (GTK_BIN (toplevel));
-      g_return_if_fail (child != NULL);
-
-      /* disconnect the signals before ungrabbing! */
-      if (priv->toplevel_grab_broken_handler_id != 0)
-        {
-          g_signal_handler_disconnect (toplevel,
-                                       priv->toplevel_grab_broken_handler_id);
-          priv->toplevel_grab_broken_handler_id = 0;
-        }
-      if (priv->grab_notify_handler_id != 0)
-        {
-          g_signal_handler_disconnect (notebook,
-                                       priv->grab_notify_handler_id);
-          priv->grab_notify_handler_id = 0;
-        }
-      if (priv->toplevel_motion_notify_handler_id != 0)
-        {
-          g_signal_handler_disconnect (toplevel,
-                                       priv->toplevel_motion_notify_handler_id);
-          priv->toplevel_motion_notify_handler_id = 0;
-        }
-      if (priv->toplevel_button_release_handler_id != 0)
-        {
-          g_signal_handler_disconnect (toplevel,
-                                       priv->toplevel_button_release_handler_id);
-          priv->toplevel_button_release_handler_id = 0;
-        }
-
-      /* ungrab the pointer if it's grabbed */
-      /* FIXME multihead */
-      if (gdk_pointer_is_grabbed ())
-        {
-          gdk_pointer_ungrab (time);
-        }
-
-      gtk_grab_remove (toplevel);
-
-      g_signal_emit (G_OBJECT (notebook), signals[TABS_REORDERED], 0);
-    }
-
-  if (priv->motion_notify_handler_id != 0)
-    {
-      g_signal_handler_disconnect (notebook,
-                                   priv->motion_notify_handler_id);
-      priv->motion_notify_handler_id = 0;
-    }
-
-  priv->drag_in_progress = FALSE;
-}
-
-static gboolean
-grab_broken_event_cb (GtkWidget *widget,
-                      GdkEventGrabBroken *event,
-                      TerminalNotebook *notebook)
-{
-  drag_stop (notebook, GDK_CURRENT_TIME /* FIXME? */);
-
-  return FALSE;
-}
-
-static void
-grab_notify_cb (GtkWidget *widget,
-                gboolean was_grabbed,
-                TerminalNotebook *notebook)
-{
-  drag_stop (notebook, GDK_CURRENT_TIME /* FIXME? */);
-}
-
-static gboolean
-toplevel_motion_notify_cb (GtkWidget *toplevel,
-                           GdkEventMotion *event,
-                           TerminalNotebook *notebook)
-{
-  TerminalNotebook *dest = NULL;
-  int page_num, result;
-
-  result = find_notebook_and_tab_at_pos ((gint)event->x_root,
-                                         (gint)event->y_root,
-                                         &dest, &page_num);
-
-  if (result != NOT_IN_APP_WINDOWS)
-    {
-      if (dest != notebook)
-        {
-          move_tab_to_another_notebook (notebook, dest,
-                                        event, page_num);
-        }
-      else
-        {
-          g_assert (page_num >= -1);
-          move_tab (notebook, page_num);
-        }
-    }
-
-  return FALSE;
-}
-
-static gboolean
-toplevel_button_release_cb (GtkWidget *toplevel,
-                            GdkEventButton *event,
-                            TerminalNotebook *notebook)
-{
-  TerminalNotebookPrivate *priv = notebook->priv;
-
-  if (priv->drag_in_progress)
-    {
-      gint cur_page_num;
-      GtkWidget *cur_page;
-
-      cur_page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
-      cur_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook),
-                                            cur_page_num);
-
-      if (!is_in_notebook_window (notebook, event->x_root, event->y_root)
-          && gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) > 1)
-        {
-          /* Tab was detached */
-          g_signal_emit (G_OBJECT (notebook),
-                         signals[TAB_DETACHED], 0, cur_page);
-        }
-    }
-
-  /* This must be called even if a drag isn't happening */
-  drag_stop (notebook, event->time);
-
-  return FALSE;
-}
-
-static gboolean
-drag_start (TerminalNotebook *notebook,
-            guint32 time)
-{
-  TerminalNotebookPrivate *priv = notebook->priv;
-  GtkWidget *widget = GTK_WIDGET (notebook);
-  GtkWidget *toplevel, *child;
-
-  /* FIXME multihead */
-  if (priv->drag_in_progress || gdk_pointer_is_grabbed ()) return FALSE;
-
-  priv->drag_in_progress = TRUE;
-
-  /* get a new cursor, if necessary */
-  /* FIXME multi-head */
-  if (!cursor) cursor = gdk_cursor_new (GDK_FLEUR);
-
-  toplevel = gtk_widget_get_toplevel (widget);
-  g_return_val_if_fail (GTK_WIDGET_TOPLEVEL (toplevel), FALSE);
-
-  child = gtk_bin_get_child (GTK_BIN (toplevel));
-  g_return_val_if_fail (child != NULL, FALSE);
-
-  /* grab the pointer */
-  gtk_grab_add (toplevel);
-
-  /* FIXME multi-head */
-  if (gdk_pointer_grab (toplevel->window,
-                        FALSE,
-                        GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
-                        NULL, cursor, time) != GDK_GRAB_SUCCESS)
-    {
-      drag_stop (notebook, time);
-      return FALSE;
-    }
-
-  g_return_val_if_fail (priv->toplevel_grab_broken_handler_id == 0, FALSE);
-  g_return_val_if_fail (priv->toplevel_motion_notify_handler_id == 0, FALSE);
-  g_return_val_if_fail (priv->toplevel_button_release_handler_id == 0, FALSE);
-  g_return_val_if_fail (priv->grab_notify_handler_id == 0, FALSE);
-
-  priv->toplevel_grab_broken_handler_id =
-    g_signal_connect (toplevel, "grab-broken-event",
-                      G_CALLBACK (grab_broken_event_cb), notebook);
-  priv->toplevel_motion_notify_handler_id =
-    g_signal_connect (toplevel, "motion-notify-event",
-                      G_CALLBACK (toplevel_motion_notify_cb), notebook);
-  priv->toplevel_button_release_handler_id =
-    g_signal_connect (toplevel, "button-release-event",
-                      G_CALLBACK (toplevel_button_release_cb), notebook);
-  priv->grab_notify_handler_id =
-    g_signal_connect (notebook, "grab-notify",
-                      G_CALLBACK (grab_notify_cb), notebook);
-
-  return TRUE;
-}
-
-
-
-/* this function is only called during dnd, we don't need to emit TABS_REORDERED
- * here, instead we do it on drag_stop
- */
-static void
-move_tab (TerminalNotebook *notebook,
-          int dest_position)
-{
-  gint cur_page_num;
-
-  cur_page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
-
-  if (dest_position != cur_page_num)
-    {
-      GtkWidget *cur_tab;
-      
-      cur_tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook),
-                                           cur_page_num);
-      terminal_notebook_move_tab (TERMINAL_NOTEBOOK (notebook), NULL,
-                                  TERMINAL_SCREEN (cur_tab),
-                                  dest_position);
-    }
-}
-
-static gboolean
-motion_notify_cb (TerminalNotebook *notebook,
-                  GdkEventMotion *event,
-                  gpointer data)
-{
-  TerminalNotebookPrivate *priv = notebook->priv;
-
-  if (priv->drag_in_progress == FALSE)
-    {
-      if (gtk_drag_check_threshold (GTK_WIDGET (notebook),
-                                    notebook->priv->x_start,
-                                    notebook->priv->y_start,
-                                    event->x_root, event->y_root))
-        {
-          return drag_start (notebook, event->time);
-        }
-
-      return FALSE;
-    }
-
-  return FALSE;
-}
-
-
-static void
-move_tab_to_another_notebook (TerminalNotebook *src,
-                              TerminalNotebook *dest,
-                              GdkEventMotion *event,
-                              int dest_position)
-{
-  GtkWidget *screen;
-  int cur_page;
-
-  /* This is getting tricky, the screen was dragged in a notebook
-   * in another window of the same app, we move the screen
-   * to that new notebook, and let this notebook handle the
-   * drag
-  */
-  g_assert (TERMINAL_IS_NOTEBOOK (dest));
-  g_assert (dest != src);
-
-  cur_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (src));
-  screen = gtk_notebook_get_nth_page (GTK_NOTEBOOK (src), cur_page);
-
-  /* stop drag in origin window */
-  /* ungrab the pointer if it's grabbed */
-  drag_stop (src, event->time);
-  if (gdk_pointer_is_grabbed ())
-    {
-      gdk_pointer_ungrab (event->time);
-    }
-  gtk_grab_remove (GTK_WIDGET (src));
-
-  terminal_notebook_move_tab (src, dest, TERMINAL_SCREEN (screen),
-                              dest_position);
-
-  /* start drag handling in dest notebook */
-
-  dest->priv->motion_notify_handler_id =
-    g_signal_connect (G_OBJECT (dest),
-                      "motion-notify-event",
-                      G_CALLBACK (motion_notify_cb),
-                      NULL);
-
-  drag_start (dest, event->time);
-}
-
-static gboolean
-button_release_cb (TerminalNotebook *notebook,
-                   GdkEventButton *event,
-                   gpointer data)
-{
-  /* This must be called even if a drag isn't happening */
-  drag_stop (notebook, event->time);
-
-  return FALSE;
-}
-
 static gboolean
 button_press_cb (TerminalNotebook *notebook,
                  GdkEventButton *event,
@@ -618,22 +241,9 @@
                                           event->x_root,
                                           event->y_root);
 
-  if (notebook->priv->drag_in_progress)
-    {
-      return TRUE;
-    }
-
-  if ((event->button == 1) && (event->type == GDK_BUTTON_PRESS)
-      && (tab_clicked >= 0))
-    {
-      notebook->priv->x_start = event->x_root;
-      notebook->priv->y_start = event->y_root;
-      notebook->priv->motion_notify_handler_id =
-        g_signal_connect (G_OBJECT (notebook),
-                          "motion-notify-event",
-                          G_CALLBACK (motion_notify_cb), NULL);
-    }
-  else if (GDK_BUTTON_PRESS == event->type && 3 == event->button)
+  if (event->type == GDK_BUTTON_PRESS &&
+      event->button == 3) /*&&
+      (event->state && gtk_accelerator_get_default_mod_mask()) == 0)*/
     {
       if (tab_clicked == -1)
         {
@@ -642,23 +252,14 @@
            */
           return TRUE;
         }
-      else
-        {
-          /* switch to the page the mouse is over, but don't consume the event
-           */
-          gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), tab_clicked);
-        }
+
+      /* switch to the page the mouse is over, but don't consume the event */
+      gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), tab_clicked);
     }
 
   return FALSE;
 }
 
-GtkWidget *
-terminal_notebook_new (void)
-{
-  return GTK_WIDGET (g_object_new (TERMINAL_TYPE_NOTEBOOK, NULL));
-}
-
 /*
  * update_tabs_visibility: Hide tabs if there is only one screen
  * and the pref is not set.
@@ -689,10 +290,6 @@
 
   g_signal_connect (notebook, "button-press-event",
                     (GCallback)button_press_cb, NULL);
-  g_signal_connect (notebook, "button-release-event",
-                    (GCallback)button_release_cb, NULL);
-  gtk_widget_add_events (GTK_WIDGET (notebook), GDK_BUTTON1_MOTION_MASK);
-
 }
 
 static void
@@ -721,16 +318,13 @@
 close_button_clicked_cb (GtkWidget *widget, TerminalScreen *screen)
 {
   GtkWidget *notebook;
-
   notebook = gtk_widget_get_parent (GTK_WIDGET (screen));
-  terminal_notebook_remove_tab (TERMINAL_NOTEBOOK (notebook), screen);
+
+  gtk_container_remove (GTK_CONTAINER (notebook), GTK_WIDGET (screen));
 }
 
-void
-terminal_notebook_add_tab (TerminalNotebook *nb,
-                           TerminalScreen *screen,
-                           int position,
-                           gboolean jump_to)
+static GtkWidget *
+build_tab_label (TerminalNotebook *nb, TerminalScreen *screen)
 {
   const char *title;
   GtkWidget *hbox, *label, *label_ebox, *close_button, *image;
@@ -738,8 +332,6 @@
   GtkSettings *settings;
   gint w, h;
 
-  g_return_if_fail (TERMINAL_IS_SCREEN (screen));
-
   hbox = gtk_hbox_new (FALSE, 4);
 
   title = terminal_screen_get_title (screen);
@@ -776,8 +368,8 @@
   gtk_tooltips_set_tip (nb->priv->tooltips, close_button, _("Close tab"), NULL);
 
   g_signal_connect (G_OBJECT (close_button), "clicked",
-		    G_CALLBACK (close_button_clicked_cb),
-		    screen);
+                    G_CALLBACK (close_button_clicked_cb),
+                    screen);
 
   gtk_widget_show (label);
   gtk_widget_show (label_ebox);
@@ -785,63 +377,99 @@
   gtk_widget_show (close_button);
   gtk_widget_show (hbox);
 
-  update_tabs_visibility (nb, TRUE);
+  return hbox;
+}
 
-  gtk_notebook_insert_page (GTK_NOTEBOOK (nb), GTK_WIDGET (screen),
-			    hbox, position);
+static int
+terminal_notebook_insert_page (GtkNotebook *gnotebook,
+                               GtkWidget *tab_widget,
+                               GtkWidget *tab_label,
+                               GtkWidget *menu_label,
+                               int position)
+{
+  TerminalNotebook *notebook = TERMINAL_NOTEBOOK (gnotebook);
 
-  gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (nb),
+  /* Destroy passed-in tab label */
+  if (tab_label != NULL)
+    {
+      g_object_ref_sink (tab_label);
+      g_object_unref (tab_label);
+    }
+
+  g_assert (TERMINAL_IS_SCREEN (tab_widget));
+
+  tab_label = build_tab_label (notebook, TERMINAL_SCREEN (tab_widget));
+
+  update_tabs_visibility (notebook, TRUE);
+
+  position = GTK_NOTEBOOK_CLASS (parent_class)->insert_page (gnotebook,
+                                                             tab_widget,
+                                                             tab_label,
+                                                             menu_label,
+                                                             position);
+
+  gtk_notebook_set_tab_reorderable (gnotebook, tab_widget, TRUE);
+
+  return position;
+}
+
+int
+terminal_notebook_add_tab (TerminalNotebook *notebook,
+                           TerminalScreen *screen,
+                           int position,
+                           gboolean jump_to)
+{
+  g_return_val_if_fail (TERMINAL_IS_SCREEN (screen), -1);
+
+  position = gtk_notebook_insert_page (GTK_NOTEBOOK (notebook),
+                                       GTK_WIDGET (screen),
+                                       NULL,
+                                       position);
+
+  gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (notebook),
                                       GTK_WIDGET (screen),
                                       TRUE, TRUE, GTK_PACK_START);
 
   g_signal_connect (G_OBJECT (screen),
                     "title-changed",
                     G_CALLBACK (sync_label),
-                    nb);
-
-  g_signal_emit (G_OBJECT (nb), signals[TAB_ADDED], 0, screen);
+                    notebook);
 
+  /* FIXME gtk bug! */
   /* The signal handler may have reordered the tabs */
-  position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (screen));
+  position = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), GTK_WIDGET (screen));
 
   if (jump_to)
     {
-      gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), position);
+      gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), position);
+      /* FIXME: We don't need this in gnome-terminal while it's needed in epiphany? */
       g_object_set_data (G_OBJECT (screen), "jump_to",
                          GINT_TO_POINTER (jump_to));
 
     }
+
+  return position;
 }
 
-void
-terminal_notebook_remove_tab (TerminalNotebook *nb,
-                              TerminalScreen *screen)
+static void
+terminal_notebook_remove (GtkContainer *container,
+                          GtkWidget *tab_widget)
 {
+  GtkNotebook *gnotebook = GTK_NOTEBOOK (container);
+  TerminalNotebook *notebook = TERMINAL_NOTEBOOK (container);
+  GtkWidget *tab_label;
   int position, curr;
-  GtkWidget *label;
-
-  g_return_if_fail (TERMINAL_IS_NOTEBOOK (nb));
-  g_return_if_fail (TERMINAL_IS_SCREEN (screen));
-
-  position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (screen));
-  curr = gtk_notebook_get_current_page (GTK_NOTEBOOK (nb));
-
-  label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (nb), GTK_WIDGET (screen));
-
-  g_signal_handlers_disconnect_by_func (screen,
-                                        G_CALLBACK (sync_label), nb);
 
-  /**
-   * we ref the screen so that it's still alive while the tabs_removed
-   * signal is processed.
-   */
-  g_object_ref (screen);
+  g_assert (TERMINAL_IS_SCREEN (tab_widget));
 
-  gtk_notebook_remove_page (GTK_NOTEBOOK (nb), position);
+  position = gtk_notebook_page_num (gnotebook, tab_widget);
+  curr = gtk_notebook_get_current_page (gnotebook);
+  tab_label = gtk_notebook_get_tab_label (gnotebook, tab_widget);
 
-  update_tabs_visibility (nb, FALSE);
+  g_signal_handlers_disconnect_by_func (tab_widget,
+                                        G_CALLBACK (sync_label), notebook);
 
-  g_signal_emit (G_OBJECT (nb), signals[TAB_REMOVED], 0, screen);
+  GTK_CONTAINER_CLASS (parent_class)->remove (container, tab_widget);
 
-  g_object_unref (screen);
+  update_tabs_visibility (notebook, FALSE);
 }
Index: src/terminal-notebook.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-notebook.h,v
retrieving revision 1.1
diff -u -B -r1.1 terminal-notebook.h
--- src/terminal-notebook.h	20 Nov 2005 19:13:35 -0000	1.1
+++ src/terminal-notebook.h	8 May 2006 12:35:43 -0000
@@ -55,28 +55,16 @@
   GtkNotebookClass parent_class;
 
   /* Signals */
-  void     (* tab_added)      (TerminalNotebook *notebook,
-                               TerminalScreen   *screen);
-  void     (* tab_removed)    (TerminalNotebook *notebook,
-                               TerminalScreen   *screen);
-  void     (* tab_detached)   (TerminalNotebook *notebook,
-                               TerminalScreen   *screen);
-  void     (* tabs_reordered) (TerminalNotebook *notebook);
   gboolean (* tab_delete)     (TerminalNotebook *notebook,
                                TerminalScreen   *screen);
 };
 
 GType           terminal_notebook_get_type       (void);
 
-GtkWidget      *terminal_notebook_new            (void);
-
-void            terminal_notebook_add_tab        (TerminalNotebook *nb,
+int             terminal_notebook_add_tab        (TerminalNotebook *notebook,
                                                   TerminalScreen   *screen,
-                                                  int               positionl,
+                                                  int               position,
                                                   gboolean          jump_to);
-
-void            terminal_notebook_remove_tab     (TerminalNotebook *nb,
-                                                  TerminalScreen   *screen);
 
 void            terminal_notebook_move_tab       (TerminalNotebook *src,
                                                   TerminalNotebook *dest,
Index: src/terminal-window.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-window.c,v
retrieving revision 1.126
diff -u -B -r1.126 terminal-window.c
--- src/terminal-window.c	1 Apr 2006 20:03:58 -0000	1.126
+++ src/terminal-window.c	8 May 2006 12:35:44 -0000
@@ -36,7 +36,7 @@
 #include <libsn/sn-launchee.h>
 
 struct _TerminalWindowPrivate
-{  
+{
   GtkWidget *main_vbox;
   GtkWidget *menubar;
   GtkWidget *notebook;
@@ -116,20 +116,26 @@
                                              int              page_num,
                                              TerminalWindow  *window);
 
-static void notebook_tab_added_callback     (GtkWidget       *notebook,
+static void notebook_page_added_callback    (GtkWidget       *notebook,
                                              TerminalScreen  *screen,
+                                             guint           position,
                                              TerminalWindow  *window);
 
-static void notebook_tab_detached_callback  (GtkWidget       *notebook,
+#if 0
+static void notebook_page_detached_callback (GtkWidget       *notebook,
                                              TerminalScreen  *screen,
                                              TerminalWindow  *window);
+#endif
 
-static void notebook_tab_removed_callback   (GtkWidget       *notebook,
+static void notebook_page_removed_callback  (GtkWidget       *notebook,
                                              TerminalScreen  *screen,
+                                             guint           position,
                                              TerminalWindow  *window);
 
-static void notebook_tabs_reordered_callback (GtkWidget      *notebook,
-                                              TerminalWindow *window);
+static void notebook_page_reordered_callback(GtkWidget      *notebook,
+                                             GtkWidget      *tab,
+                                             guint          position,
+                                             TerminalWindow *window);
 
 static void config_change_notify            (GConfClient *client,
                                              guint        cnxn_id,
@@ -216,7 +222,7 @@
 static void about_callback                (GtkWidget      *menuitem,
                                            TerminalWindow *window);
 
-static gboolean window_state_event_callback (GtkWidget            *widget, 
+static gboolean window_state_event_callback (GtkWidget            *widget,
                                              GdkEventWindowState  *event,
                                              gpointer              user_data);
 
@@ -244,7 +250,7 @@
   static GType object_type = 0;
 
   g_type_init ();
-  
+
   if (!object_type)
     {
       static const GTypeInfo object_info =
@@ -259,12 +265,12 @@
         0,              /* n_preallocs */
         (GInstanceInitFunc) terminal_window_init,
       };
-      
+
       object_type = g_type_register_static (GTK_TYPE_WINDOW,
                                             "TerminalWindow",
-                                            &object_info, 0);      
+                                            &object_info, 0);
     }
-  
+
   return object_type;
 }
 
@@ -276,13 +282,13 @@
                  gpointer    data)
 {
   GtkWidget *menu_item;
-  
+
   menu_item = gtk_menu_item_new_with_mnemonic (text);
 
   if (accel_path)
     gtk_menu_item_set_accel_path (GTK_MENU_ITEM (menu_item),
                                   accel_path);
-  
+
   gtk_widget_show (menu_item);
   gtk_menu_shell_append (GTK_MENU_SHELL (menu),
                          menu_item);
@@ -323,7 +329,7 @@
                                  gpointer     user_data)
 {
   GConfValue *value = gconf_entry_get_value (entry);
-  
+
   if (value && value->type == GCONF_VALUE_BOOL)
     menuitem_icon_visibility (user_data, gconf_value_get_bool (value));
 }
@@ -380,7 +386,7 @@
 }
 
 static GtkWidget *
-append_check_menuitem (GtkWidget  *menu, 
+append_check_menuitem (GtkWidget  *menu,
                        const char *text,
                        const char *accel_path,
                        gboolean    active,
@@ -404,7 +410,7 @@
 
   return menu_item;
 }
-                       
+
 static void
 fill_in_config_picker_submenu (TerminalWindow *window)
 {
@@ -424,24 +430,24 @@
                                  NULL);
       return;
     }
-  
+
   gtk_widget_set_sensitive (window->priv->choose_config_menuitem, TRUE);
 
-  accel_group = terminal_accels_get_group_for_widget (GTK_WIDGET (window));  
-  
+  accel_group = terminal_accels_get_group_for_widget (GTK_WIDGET (window));
+
   menu = gtk_menu_new ();
   gtk_menu_set_accel_group (GTK_MENU (menu), accel_group);
   gtk_menu_item_set_submenu (GTK_MENU_ITEM (window->priv->choose_config_menuitem),
                              menu);
-  
+
   group = NULL;
   tmp = profiles;
   while (tmp != NULL)
     {
       TerminalProfile *profile;
-      
+
       profile = tmp->data;
-      
+
       /* Profiles can go away while the menu is up. */
       g_object_ref (G_OBJECT (profile));
 
@@ -451,25 +457,25 @@
       gtk_widget_show (menu_item);
       gtk_menu_shell_append (GTK_MENU_SHELL (menu),
                              menu_item);
-      
+
       if (profile == terminal_screen_get_profile (window->priv->active_term))
         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
                                         TRUE);
-      
+
       g_signal_connect (G_OBJECT (menu_item),
                         "toggled",
                         G_CALLBACK (change_configuration_callback),
                         window);
-      
+
       g_object_set_data_full (G_OBJECT (menu_item),
                               "profile",
                               profile,
                               (GDestroyNotify) g_object_unref);
-      
+
       tmp = tmp->next;
     }
 
-  g_list_free (profiles);  
+  g_list_free (profiles);
 }
 
 static char *
@@ -495,16 +501,16 @@
 }
 
 static void
-fill_in_new_term_submenu_real(GtkWidget *menuitem, 
+fill_in_new_term_submenu_real(GtkWidget *menuitem,
                               TerminalWindow *window,
-                              const char *accel, 
-                              TerminalProfile *current_profile, 
-                              GCallback callback) 
+                              const char *accel,
+                              TerminalProfile *current_profile,
+                              GCallback callback)
 {
   GList *profiles;
 
   gtk_widget_set_sensitive (menuitem, TRUE);
-  
+
   /* remove older signal handler and accelerator */
   g_signal_handlers_disconnect_by_func (G_OBJECT (menuitem), G_CALLBACK (callback), window);
   gtk_menu_item_set_accel_path (GTK_MENU_ITEM (menuitem), NULL);
@@ -525,7 +531,7 @@
 
       g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK (callback), window);
       g_object_ref (G_OBJECT (current_profile));
-      g_object_set_data_full (G_OBJECT (menuitem), "profile", current_profile, (GDestroyNotify) g_object_unref);  
+      g_object_set_data_full (G_OBJECT (menuitem), "profile", current_profile, (GDestroyNotify) g_object_unref);
       gtk_menu_item_set_accel_path (GTK_MENU_ITEM (menuitem), accel);
     }
   else
@@ -536,7 +542,7 @@
       GList *tmp;
       int i;
 
-      accel_group = terminal_accels_get_group_for_widget (GTK_WIDGET (window));  
+      accel_group = terminal_accels_get_group_for_widget (GTK_WIDGET (window));
 
       /* New submenu */
       new_sub_menu = gtk_menu_new ();
@@ -549,9 +555,9 @@
       gtk_menu_shell_append (GTK_MENU_SHELL (new_sub_menu), menu_item);
       g_signal_connect (G_OBJECT (menu_item), "activate", G_CALLBACK (callback), window);
       g_object_ref (G_OBJECT (current_profile));
-      g_object_set_data_full (G_OBJECT (menu_item), "profile", current_profile, (GDestroyNotify) g_object_unref);  
+      g_object_set_data_full (G_OBJECT (menu_item), "profile", current_profile, (GDestroyNotify) g_object_unref);
       gtk_menu_item_set_accel_path (GTK_MENU_ITEM (menu_item), accel);
-      
+
       /* separator */
       menu_item = gtk_separator_menu_item_new ();
       gtk_widget_show (menu_item);
@@ -561,9 +567,9 @@
         {
           TerminalProfile *profile;
           char *escaped_name, *str;
-          
+
           profile = tmp->data;
-          
+
           /* Profiles can go away while the menu is up. */
           g_object_ref (G_OBJECT (profile));
 
@@ -579,13 +585,13 @@
           /* item for new window */
           menu_item = gtk_menu_item_new_with_mnemonic (str);
           gtk_widget_show (menu_item);
-          gtk_menu_shell_append (GTK_MENU_SHELL (new_sub_menu), menu_item);      
-          g_signal_connect (G_OBJECT (menu_item), "activate", G_CALLBACK (callback), window);      
+          gtk_menu_shell_append (GTK_MENU_SHELL (new_sub_menu), menu_item);
+          g_signal_connect (G_OBJECT (menu_item), "activate", G_CALLBACK (callback), window);
           g_object_set_data_full (G_OBJECT (menu_item), "profile", profile, (GDestroyNotify) g_object_unref);
 
           g_free (str);
           g_free (escaped_name);
-          
+
         }
 
       g_list_free (profiles);
@@ -604,13 +610,13 @@
 
   /* if current_profile is still NULL, this will change it to a default */
   current_profile = terminal_profile_get_for_new_term (current_profile);
-  
-  fill_in_new_term_submenu_real (window->priv->new_window_menuitem, 
+
+  fill_in_new_term_submenu_real (window->priv->new_window_menuitem,
                                  window,
                                  ACCEL_PATH_NEW_WINDOW,
                                  current_profile,
                                  G_CALLBACK (new_window_callback));
-  fill_in_new_term_submenu_real (window->priv->new_tab_menuitem, 
+  fill_in_new_term_submenu_real (window->priv->new_tab_menuitem,
                                  window,
                                  ACCEL_PATH_NEW_TAB,
                                  current_profile,
@@ -630,7 +636,7 @@
 
   if (!terminal_widget_supports_dynamic_encoding ())
     return;
-  
+
   if (window->priv->active_term == NULL)
     {
       gtk_widget_set_sensitive (window->priv->encoding_menuitem, FALSE);
@@ -638,7 +644,7 @@
                                  NULL);
       return;
     }
-  
+
   gtk_widget_set_sensitive (window->priv->encoding_menuitem, TRUE);
 
   menu = gtk_menu_new ();
@@ -647,7 +653,7 @@
 
   w = terminal_screen_get_widget (window->priv->active_term);
   charset = terminal_widget_get_encoding (w);
-  
+
   group = NULL;
   encodings = terminal_get_active_encodings ();
   tmp = encodings;
@@ -655,11 +661,11 @@
     {
       TerminalEncoding *e;
       char *name;
-      
+
       e = tmp->data;
 
       name = g_strdup_printf ("%s (%s)", e->name, e->charset);
-      
+
       menu_item = gtk_radio_menu_item_new_with_label (group, name);
 
       g_free (name);
@@ -668,11 +674,11 @@
       gtk_widget_show (menu_item);
       gtk_menu_shell_append (GTK_MENU_SHELL (menu),
                              menu_item);
-      
+
       if (strcmp (e->charset, charset) == 0)
         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
                                         TRUE);
-      
+
       g_signal_connect (G_OBJECT (menu_item),
                         "toggled",
                         G_CALLBACK (change_encoding_callback),
@@ -682,7 +688,7 @@
                               "encoding",
                               g_strdup (e->charset),
                               (GDestroyNotify) g_free);
-      
+
       tmp = tmp->next;
     }
 
@@ -694,7 +700,7 @@
   menu_item = gtk_separator_menu_item_new ();
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
   gtk_widget_show (menu_item);
-  
+
   append_menuitem (menu, _("_Add or Remove..."), NULL,
                    G_CALLBACK (add_encoding_callback),
                    window);
@@ -713,7 +719,7 @@
   TerminalScreen *screen;
   double ignored;
   double current_zoom;
-  
+
   screen = window->priv->active_term;
   if (screen == NULL)
     return;
@@ -758,26 +764,26 @@
   GError *error;
   gboolean menus_have_icons;
 
-  g_signal_connect (G_OBJECT (window), "delete_event", 
+  g_signal_connect (G_OBJECT (window), "delete_event",
                     G_CALLBACK(terminal_window_delete_event),
                     NULL);
 
   gtk_window_set_title (GTK_WINDOW (window), _("Terminal"));
   client = gconf_client_get_default();
-  
+
   window->priv = g_new0 (TerminalWindowPrivate, 1);
   window->priv->terms = NULL;
   window->priv->active_term = NULL;
   window->priv->menubar = gtk_menu_bar_new ();
   window->priv->menubar_visible = FALSE;
-  
+
   window->priv->main_vbox = gtk_vbox_new (FALSE, 0);
-  window->priv->notebook = terminal_notebook_new ();
-  
+  window->priv->notebook = GTK_WIDGET (g_object_new (TERMINAL_TYPE_NOTEBOOK, NULL));
+
   window->priv->old_char_width = -1;
   window->priv->old_char_height = -1;
   window->priv->old_geometry_widget = NULL;
-  
+
   window->priv->use_mnemonics = TRUE;
   window->priv->using_mnemonics = FALSE;
 
@@ -792,41 +798,43 @@
       g_error_free (error);
       menus_have_icons = TRUE;
     }
- 
+
   g_signal_connect (window->priv->menubar,
 		    "can_activate_accel",
 		    G_CALLBACK (gtk_true),
 		    NULL);
-  
+
   accel_group = terminal_accels_get_group_for_widget (GTK_WIDGET (window));
   gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
-  
+
   gtk_notebook_set_scrollable (GTK_NOTEBOOK (window->priv->notebook),
-                               TRUE);                                      
-  
+                               TRUE);
+
   g_signal_connect_after (G_OBJECT (window->priv->notebook),
                           "switch_page",
                           G_CALLBACK (notebook_page_selected_callback),
                           window);
 
   g_signal_connect_after (G_OBJECT (window->priv->notebook),
-                          "tab_added",
-                          G_CALLBACK (notebook_tab_added_callback),
+                          "page_added",
+                          G_CALLBACK (notebook_page_added_callback),
                           window);
 
+#if 0
   g_signal_connect_after (G_OBJECT (window->priv->notebook),
                           "tab_detached",
                           G_CALLBACK (notebook_tab_detached_callback),
                           window);
+#endif
 
   g_signal_connect_after (G_OBJECT (window->priv->notebook),
-                          "tab_removed",
-                          G_CALLBACK (notebook_tab_removed_callback),
+                          "page_removed",
+                          G_CALLBACK (notebook_page_removed_callback),
                           window);
-  
+
   g_signal_connect_after (G_OBJECT (window->priv->notebook),
-                          "tabs_reordered",
-                          G_CALLBACK (notebook_tabs_reordered_callback),
+                          "page_reordered",
+                          G_CALLBACK (notebook_page_reordered_callback),
                           window);
 
   gtk_container_add (GTK_CONTAINER (window),
@@ -838,13 +846,13 @@
 
   gtk_box_pack_end (GTK_BOX (window->priv->main_vbox),
                     window->priv->notebook,
-                    TRUE, TRUE, 0);  
-  
+                    TRUE, TRUE, 0);
+
   mi = append_menuitem (window->priv->menubar,
                         "", NULL,
                         NULL, NULL);
   window->priv->file_menuitem = mi;
-  
+
   menu = gtk_menu_new ();
   gtk_menu_set_accel_group (GTK_MENU (menu),
                             accel_group);
@@ -855,7 +863,7 @@
 
   window->priv->new_tab_menuitem =
     append_menuitem (menu, _("Open Ta_b"), NULL, NULL, NULL);
-  
+
   mi = gtk_separator_menu_item_new ();
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
 
@@ -864,19 +872,19 @@
    */
   append_menuitem (menu, _("New _Profile..."), ACCEL_PATH_NEW_PROFILE,
 		   G_CALLBACK (new_configuration_callback), window);
-  
+
   mi = gtk_separator_menu_item_new ();
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
 
-  window->priv->close_tab_menuitem = 
+  window->priv->close_tab_menuitem =
     append_menuitem (menu, _("C_lose Tab"), ACCEL_PATH_CLOSE_TAB,
                      G_CALLBACK (close_tab_callback),
                      window);
-  
+
   append_menuitem (menu, _("_Close Window"), ACCEL_PATH_CLOSE_WINDOW,
                    G_CALLBACK (close_window_callback),
                    window);
-  
+
   mi = append_menuitem (window->priv->menubar,
                         "", NULL,
                         NULL, NULL);
@@ -900,12 +908,12 @@
                            G_CALLBACK (paste_callback),
                            window);
   menuitem_icon_visibility (window->priv->paste_menuitem, menus_have_icons);
-  g_signal_connect (G_OBJECT (mi), "activate", 
+  g_signal_connect (G_OBJECT (mi), "activate",
                     G_CALLBACK (edit_menu_activate_callback), window);
 
   mi = gtk_separator_menu_item_new ();
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
-  
+
   append_menuitem (menu, _("P_rofiles..."), NULL,
                    G_CALLBACK (manage_configurations_callback), window);
 
@@ -915,7 +923,7 @@
   window->priv->edit_config_menuitem =
     append_menuitem (menu, _("C_urrent Profile..."), NULL,
                      G_CALLBACK (edit_configuration_callback), window);
-  
+
   mi = append_menuitem (window->priv->menubar,
                         "", NULL,
                         NULL, NULL);
@@ -925,7 +933,7 @@
   gtk_menu_set_accel_group (GTK_MENU (menu),
                             accel_group);
   gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), menu);
-  
+
   /* This is a check menu item so that the togglability is evident, but when it is not checked,
    * it won't be seen, of course, because the menubar will be then hidden. */
   mi = append_check_menuitem (menu, _("Show Menu_bar"), ACCEL_PATH_TOGGLE_MENUBAR, FALSE,
@@ -958,16 +966,16 @@
   menuitem_icon_visibility (window->priv->zoom_normal_menuitem, menus_have_icons);
 
   update_zoom_items (window);
-  
+
   mi = append_menuitem (window->priv->menubar,
                         "", NULL,
                         NULL, NULL);
-  window->priv->terminal_menuitem = mi;  
+  window->priv->terminal_menuitem = mi;
 
   g_signal_connect (G_OBJECT (mi), "activate",
                     G_CALLBACK (terminal_menu_opened_callback),
                     window);
-  
+
   menu = gtk_menu_new ();
   gtk_menu_set_accel_group (GTK_MENU (menu),
                             accel_group);
@@ -977,7 +985,7 @@
   window->priv->choose_config_menuitem =
     append_menuitem (menu, _("Change _Profile"), NULL,
                      NULL, NULL);
-  
+
   append_menuitem (menu, _("_Set Title..."), ACCEL_PATH_SET_TERMINAL_TITLE,
                    G_CALLBACK (set_title_callback), window);
 
@@ -1005,7 +1013,7 @@
                         "", NULL,
                         NULL, NULL);
   window->priv->go_menuitem = mi;
-  
+
   menu = gtk_menu_new ();
   window->priv->go_menu = menu;
   gtk_menu_set_accel_group (GTK_MENU (menu),
@@ -1015,7 +1023,7 @@
   mi = append_menuitem (menu, _("_Previous Tab"), ACCEL_PATH_PREV_TAB,
                         G_CALLBACK (previous_tab_callback), window);
   window->priv->previous_tab_menuitem = mi;
-  
+
   mi = append_menuitem (menu, _("_Next Tab"), ACCEL_PATH_NEXT_TAB,
                         G_CALLBACK (next_tab_callback), window);
   window->priv->next_tab_menuitem = mi;
@@ -1030,7 +1038,7 @@
   mi = append_menuitem (menu, _("Move Tab to the _Left"), ACCEL_PATH_MOVE_TAB_LEFT,
                         G_CALLBACK (move_left_tab_callback), window);
   window->priv->move_left_tab_menuitem = mi;
-  
+
   mi = append_menuitem (menu, _("Move Tab to the _Right"), ACCEL_PATH_MOVE_TAB_RIGHT,
                         G_CALLBACK (move_right_tab_callback), window);
   window->priv->move_right_tab_menuitem = mi;
@@ -1044,12 +1052,12 @@
 
   mi = gtk_separator_menu_item_new ();
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
-  
+
   mi = append_menuitem (window->priv->menubar,
                         "", NULL,
                         NULL, NULL);
   window->priv->help_menuitem = mi;
-  
+
   menu = gtk_menu_new ();
   gtk_menu_set_accel_group (GTK_MENU (menu),
                             accel_group);
@@ -1064,19 +1072,19 @@
   gtk_menu_item_set_accel_path (GTK_MENU_ITEM (mi),
                                 ACCEL_PATH_HELP);
 
-  
+
   mi = append_stock_menuitem (menu, GTK_STOCK_ABOUT, NULL,
                               G_CALLBACK (about_callback), window);
   set_menuitem_text (mi, _("_About"), FALSE);
   menuitem_icon_visibility (mi, menus_have_icons);
-  
+
   terminal_window_reread_profile_list (window);
-  
+
   terminal_window_set_menubar_visible (window, TRUE);
-  window->priv->use_default_menubar_visibility = TRUE;  
+  window->priv->use_default_menubar_visibility = TRUE;
 
   reset_menubar_labels (window);
-  
+
   gtk_widget_show_all (window->priv->main_vbox);
 }
 
@@ -1086,9 +1094,9 @@
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-  
+
   parent_class = g_type_class_peek_parent (klass);
-  
+
   object_class->finalize = terminal_window_finalize;
   gtk_object_class->destroy = terminal_window_destroy;
   widget_class->show = terminal_window_show;
@@ -1107,14 +1115,14 @@
 
   if (window->priv->conf)
     g_object_unref (G_OBJECT (window->priv->conf));
-  
+
   if (window->priv->icon)
     g_object_unref (G_OBJECT (window->priv->icon));
 
   g_free (window->priv->startup_id);
-  
+
   g_free (window->priv);
-  
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -1130,7 +1138,7 @@
 
   g_list_free (window->priv->tab_menuitems);
   window->priv->tab_menuitems = NULL;
-  
+
   /* to handle multiple destroy, FIXME some fields are missing */
   window->priv->menubar = NULL;
   window->priv->notebook = NULL;
@@ -1140,8 +1148,8 @@
   window->priv->edit_config_menuitem = NULL;
   window->priv->choose_config_menuitem = NULL;
   window->priv->encoding_menuitem = NULL;
-  
-  GTK_OBJECT_CLASS (parent_class)->destroy (object);  
+
+  GTK_OBJECT_CLASS (parent_class)->destroy (object);
 }
 
 static gboolean
@@ -1174,12 +1182,12 @@
   SnLauncheeContext *context;
   GdkScreen *screen;
   GdkDisplay *display;
-  
+
   window = TERMINAL_WINDOW (widget);
 
   if (!GTK_WIDGET_REALIZED (widget))
     gtk_widget_realize (widget);
-  
+
   context = NULL;
   sn_display = NULL;
   if (window->priv->startup_id != NULL)
@@ -1188,14 +1196,14 @@
       /* FIXME In principle all transient children of this
        * window should get the same startup_id
        */
-      
+
       screen = gtk_window_get_screen (GTK_WINDOW (window));
       display = gdk_screen_get_display (screen);
-      
+
       sn_display = sn_display_new (gdk_x11_display_get_xdisplay (display),
                                    sn_error_trap_push,
                                    sn_error_trap_pop);
-      
+
       context = sn_launchee_context_new (sn_display,
                                          gdk_screen_get_number (screen),
                                          window->priv->startup_id);
@@ -1219,7 +1227,7 @@
           gdk_x11_window_set_user_time (widget->window, timestamp);
         }
     }
-  
+
   GTK_WIDGET_CLASS (parent_class)->show (widget);
 
   if (context != NULL)
@@ -1243,7 +1251,7 @@
   TerminalWindow *window;
   GError *err;
   gboolean use_mnemonics;
-  
+
   window = g_object_new (TERMINAL_TYPE_WINDOW, NULL);
   g_signal_connect (G_OBJECT (window), "realize", G_CALLBACK (terminal_window_realized_callback), NULL);
 
@@ -1264,7 +1272,7 @@
     {
       window->priv->use_mnemonics = use_mnemonics;
     }
-  
+
   err = NULL;
   window->priv->notify_id =
     gconf_client_notify_add (window->priv->conf,
@@ -1272,7 +1280,7 @@
                              config_change_notify,
                              window,
                              NULL, &err);
-  
+
   if (err)
     {
       g_printerr (_("There was an error subscribing to notification of terminal window configuration changes. (%s)\n"),
@@ -1282,7 +1290,7 @@
 
   reset_menubar_labels (window);
   reset_tab_menuitems (window);
-  
+
   return window;
 }
 
@@ -1292,7 +1300,7 @@
   gboolean single;
 
   single = g_list_length (window->priv->terms) == 1;
-    
+
   gtk_notebook_set_show_border (GTK_NOTEBOOK (window->priv->notebook), !single);
 }
 
@@ -1311,8 +1319,8 @@
                         TerminalWindow *window)
 {
   GtkWidget *mi;
-  
-  if (screen == window->priv->active_term) 
+
+  if (screen == window->priv->active_term)
     {
     gtk_window_set_title (GTK_WINDOW (window),
                           terminal_screen_get_title (screen));
@@ -1360,7 +1368,7 @@
   notebook = window->priv->notebook;
   num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
   page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
-  
+
   gtk_widget_set_sensitive (window->priv->previous_tab_menuitem,
                             page_num > 0);
 
@@ -1400,11 +1408,11 @@
                             TerminalScreen *screen)
 {
   TerminalWindow *old;
- 
+
   old = terminal_screen_get_window (screen);
 
   if (old == window)
-    return;  
+    return;
 
   g_object_ref (G_OBJECT (screen)); /* make our own new refcount */
 
@@ -1434,11 +1442,11 @@
   g_return_if_fail (terminal_screen_get_window (screen) == window);
 
   window->priv->terms = g_list_remove (window->priv->terms, screen);
-  
+
   terminal_screen_set_window (screen, NULL);
-  
-  terminal_notebook_remove_tab (TERMINAL_NOTEBOOK (window->priv->notebook),
-                                screen);
+
+  gtk_container_remove (GTK_CONTAINER (window->priv->notebook),
+                        GTK_WIDGET (screen));
 }
 
 GList*
@@ -1447,7 +1455,7 @@
   return g_list_copy (window->priv->terms);
 }
 
-int    
+int
 terminal_window_get_screen_count (TerminalWindow *window)
 {
   return g_list_length (window->priv->terms);
@@ -1461,15 +1469,15 @@
    * this side effect must happen before we short-circuit below.
    */
   window->priv->use_default_menubar_visibility = FALSE;
-  
+
   if (setting == window->priv->menubar_visible)
     return;
 
   window->priv->menubar_visible = setting;
   gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (window->priv->show_menubar_menuitem), setting);
-  
+
   if (window->priv->menubar_visible)
-    {      
+    {
       gtk_widget_show (window->priv->menubar);
     }
   else
@@ -1532,7 +1540,7 @@
   /* be sure our geometry is up-to-date */
   terminal_window_update_geometry (window);
   widget = terminal_screen_get_widget (screen);
-  
+
   app = gtk_widget_get_toplevel (widget);
   g_assert (app != NULL);
 
@@ -1544,7 +1552,7 @@
            toplevel_request.width, toplevel_request.height,
            widget_request.width, widget_request.height);
 #endif
-  
+
   w = toplevel_request.width - widget_request.width;
   h = toplevel_request.height - widget_request.height;
 
@@ -1555,9 +1563,9 @@
     grid_width = force_grid_width;
   if (force_grid_height >= 0)
     grid_height = force_grid_height;
-  
+
   terminal_widget_get_padding (widget, &xpad, &ypad);
-  
+
   w += xpad + char_width * grid_width;
   h += ypad + char_height * grid_height;
 
@@ -1580,12 +1588,12 @@
 {
   GtkWidget *widget;
   TerminalProfile *profile;
-  
+
   if (window->priv->active_term == screen)
     return;
-  
+
   widget = terminal_screen_get_widget (screen);
-  
+
   profile = terminal_screen_get_profile (screen);
 
   if (!GTK_WIDGET_REALIZED (widget))
@@ -1595,7 +1603,7 @@
 
   terminal_window_update_geometry (window);
   terminal_window_update_icon (window);
-  
+
   /* Override menubar setting if it wasn't restored from session */
   if (window->priv->use_default_menubar_visibility)
     {
@@ -1617,9 +1625,9 @@
   g_fprintf (stderr,"setting size after flipping notebook pages\n");
 #endif
   terminal_window_set_size (window, screen, TRUE);
-  
+
   update_copy_sensitivity (window);
-  
+
   fill_in_config_picker_submenu (window);
   fill_in_new_term_submenus (window);
   fill_in_encoding_menu (window);
@@ -1677,7 +1685,7 @@
   GtkWidget *menu_item;
   int old_grid_width, old_grid_height;
   GtkWidget *old_widget;
-  
+
   old_widget = NULL;
   old_grid_width = -1;
   old_grid_height = -1;
@@ -1687,7 +1695,7 @@
 
   old_widget = terminal_screen_get_widget (window->priv->active_term);
   terminal_widget_get_size (old_widget, &old_grid_width, &old_grid_height);
-  
+
   page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook),
                                            page_num);
 
@@ -1706,9 +1714,9 @@
   g_fprintf (stderr,"setting size in switch_page handler\n");
 #endif
   terminal_window_set_size_force_grid (window, screen, TRUE, old_grid_width, old_grid_height);
-  
+
   update_tab_sensitivity (window);
-  
+
   menu_item = screen_get_menuitem (screen);
   if (menu_item &&
       screen == window->priv->active_term)
@@ -1717,25 +1725,26 @@
 }
 
 static void
-notebook_tab_added_callback (GtkWidget       *notebook,
-                               TerminalScreen  *screen,
-                               TerminalWindow  *window)
+notebook_page_added_callback (GtkWidget       *notebook,
+                              TerminalScreen  *screen,
+                              guint           position,
+                              TerminalWindow  *window)
 {
   GtkWidget *term;
 
   /* Moved from another window */
   if (find_screen (window, screen) == NULL) {
     g_object_ref (G_OBJECT (screen)); /* make our own new refcount */
-  
+
     /* keep this list in same order as tabs in notebook,
      * so that terminal_window_list_screens() returns screens
      * in tab order
      */
     window->priv->terms = g_list_append (window->priv->terms, screen);
-  
+
     terminal_screen_set_window (screen, window);
   }
-  
+
   g_signal_connect (G_OBJECT (screen),
                     "profile_set",
                     G_CALLBACK (profile_set_callback),
@@ -1762,7 +1771,7 @@
 
   reset_tab_menuitems (window);
   update_tab_sensitivity (window);
-  
+
   term = terminal_screen_get_widget (screen);
 
   /* ZvtTerm is a broken POS and requires this realize to get
@@ -1774,7 +1783,7 @@
     /* Match size to current active screen */
     int current_width, current_height;
     if (window->priv->active_term)
-      terminal_widget_get_size (terminal_screen_get_widget(window->priv->active_term), 
+      terminal_widget_get_size (terminal_screen_get_widget(window->priv->active_term),
                                 &current_width, &current_height);
     else
       {
@@ -1784,12 +1793,13 @@
 
     terminal_widget_set_size (term, current_width, current_height);
   }
-  
+
   /* Make the first-added screen the active one */
   if (window->priv->active_term == NULL)
     terminal_window_set_active (window, screen);
 }
 
+#if 0
 static void
 notebook_tab_detached_callback (GtkWidget       *notebook,
                                 TerminalScreen  *screen,
@@ -1801,20 +1811,22 @@
 
   detach_tab (screen, window);
 }
+#endif
 
 static void
-notebook_tab_removed_callback (GtkWidget       *notebook,
-                               TerminalScreen  *screen,
-                               TerminalWindow  *window)
-{  
+notebook_page_removed_callback (GtkWidget       *notebook,
+                                TerminalScreen  *screen,
+                                guint           position,
+                                TerminalWindow  *window)
+{
   /* Called from terminal_notebook_move_tab() */
   if (find_screen (window, screen) != NULL) {
     g_assert (terminal_screen_get_window (screen) == window);
-  
+
     window->priv->terms = g_list_remove (window->priv->terms, screen);
     terminal_screen_set_window (screen, NULL);
   }
-  
+
   g_signal_handlers_disconnect_by_func (G_OBJECT (screen),
                                         G_CALLBACK (profile_set_callback),
                                         window);
@@ -1832,7 +1844,7 @@
                                         window);
 
   screen_set_menuitem (screen, NULL);
-  
+
   update_notebook (window);
 
   reset_tab_menuitems (window);
@@ -1844,8 +1856,10 @@
 }
 
 static void
-notebook_tabs_reordered_callback (GtkWidget       *notebook,
-                                 TerminalWindow  *window)
+notebook_page_reordered_callback (GtkWidget       *notebook,
+                                  GtkWidget       *tab,
+                                  guint           position,
+                                  TerminalWindow  *window)
 {
 	reset_tab_menuitems(window);
 }
@@ -1868,9 +1882,9 @@
       gtk_window_set_icon (GTK_WINDOW (window), NULL);
       return;
     }
-  
+
   new_icon = terminal_profile_get_icon (profile);
-  
+
   if (window->priv->icon != new_icon)
     {
       if (new_icon)
@@ -1889,46 +1903,46 @@
 terminal_window_update_geometry (TerminalWindow *window)
 {
   GdkGeometry hints;
-  GtkWidget *widget;  
+  GtkWidget *widget;
   int char_width;
   int char_height;
-  
+
   if (window->priv->active_term == NULL)
     return;
-  
+
   widget = terminal_screen_get_widget (window->priv->active_term);
-  
+
   /* We set geometry hints from the active term; best thing
    * I can think of to do. Other option would be to try to
    * get some kind of union of all hints from all terms in the
    * window, but that doesn't make too much sense.
    */
   terminal_widget_get_cell_size (widget, &char_width, &char_height);
-  
+
   if (char_width != window->priv->old_char_width ||
       char_height != window->priv->old_char_height ||
       widget != (GtkWidget*) window->priv->old_geometry_widget)
     {
       int xpad, ypad;
-      
+
       /* FIXME Since we're using xthickness/ythickness to compute
        * padding we need to change the hints when the theme changes.
        */
       terminal_widget_get_padding (widget, &xpad, &ypad);
-      
+
       hints.base_width = xpad;
       hints.base_height = ypad;
 
 #define MIN_WIDTH_CHARS 4
 #define MIN_HEIGHT_CHARS 2
-      
+
       hints.width_inc = char_width;
       hints.height_inc = char_height;
 
       /* min size is min size of just the geometry widget, remember. */
       hints.min_width = hints.base_width + hints.width_inc * MIN_WIDTH_CHARS;
       hints.min_height = hints.base_height + hints.height_inc * MIN_HEIGHT_CHARS;
-      
+
       gtk_window_set_geometry_hints (GTK_WINDOW (window),
                                      widget,
                                      &hints,
@@ -1945,7 +1959,7 @@
                hints.width_inc,
                hints.height_inc);
 #endif
-      
+
       window->priv->old_char_width = hints.width_inc;
       window->priv->old_char_height = hints.height_inc;
       window->priv->old_geometry_widget = widget;
@@ -1974,10 +1988,10 @@
   window = TERMINAL_WINDOW (user_data);
 
   val = gconf_entry_get_value (entry);
-  
+
   if (strcmp (gconf_entry_get_key (entry),
               CONF_GLOBAL_PREFIX"/use_mnemonics") == 0)
-    {      
+    {
       if (val && val->type == GCONF_VALUE_BOOL)
         {
           window->priv->use_mnemonics = gconf_value_get_bool (val);
@@ -1999,10 +2013,10 @@
     {
       const char *label;
       char *no_mnemonic;
-      
+
       label = NULL;
       no_mnemonic = NULL;
-      
+
       if (strip_mnemonic)
         {
           const char *src;
@@ -2019,7 +2033,7 @@
                   *dest = *src;
                   ++dest;
                 }
-              
+
               ++src;
             }
           *dest = '\0';
@@ -2035,7 +2049,7 @@
         gtk_label_set_text (GTK_LABEL (child), label);
       else
         gtk_label_set_text_with_mnemonic (GTK_LABEL (child), label);
-      
+
       if (no_mnemonic)
         g_free (no_mnemonic);
     }
@@ -2075,7 +2089,7 @@
   TerminalScreen *screen;
   GSList *group;
   gboolean single_page;
-  
+
   tmp = window->priv->tab_menuitems;
   while (tmp != NULL)
     {
@@ -2087,39 +2101,39 @@
   window->priv->tab_menuitems = NULL;
 
   single_page = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->priv->notebook)) == 1;
-  
+
   group = NULL;
   i = 0;
   while (TRUE) /* should probably make us somewhat nervous */
     {
       GtkWidget *page;
       char *accel_path;
-      
+
       page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->priv->notebook),
                                         i);
 
       if (page == NULL)
         break;
-      
+
       screen = TERMINAL_SCREEN (page);
 
       menu_item = gtk_radio_menu_item_new_with_label (group,
                                                       terminal_screen_get_title (screen));
       group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_item));
-      
+
       if (i < N_TABS_WITH_ACCEL && !single_page)
         accel_path = g_strdup_printf (FORMAT_ACCEL_PATH_SWITCH_TO_TAB,
                                       i + 1);
       else
         accel_path = NULL;
-      
+
       if (accel_path)
         {
           gtk_menu_item_set_accel_path (GTK_MENU_ITEM (menu_item),
 					accel_path);
 	  g_free (accel_path);
 	}
-      
+
       gtk_widget_show (menu_item);
       gtk_menu_shell_append (GTK_MENU_SHELL (window->priv->go_menu),
                              menu_item);
@@ -2127,15 +2141,15 @@
       if (screen == window->priv->active_term)
         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
                                         TRUE);
-      
+
       g_object_set_data (G_OBJECT (menu_item),
                          "notebook-page",
                          GINT_TO_POINTER (i));
-      
+
       g_signal_connect (G_OBJECT (menu_item),
                         "activate",
                         G_CALLBACK (change_tab_callback),
-                        window);      
+                        window);
 
       window->priv->tab_menuitems =
         g_list_prepend (window->priv->tab_menuitems,
@@ -2143,7 +2157,7 @@
 
       /* so we can keep the title updated */
       screen_set_menuitem (screen, menu_item);
-      
+
       ++i;
     }
 }
@@ -2155,7 +2169,7 @@
   g_return_if_fail (GTK_WIDGET_REALIZED (window));
 
   window->priv->fullscreen = setting;
-  
+
   if (setting)
     gtk_window_fullscreen (GTK_WINDOW (window));
   else
@@ -2177,7 +2191,7 @@
                      TerminalWindow *window)
 {
   TerminalProfile *profile;
-  
+
   profile = g_object_get_data (G_OBJECT (menuitem),
                                "profile");
 
@@ -2187,7 +2201,7 @@
     {
       char *name;
       const char *dir;
-      
+
       name = gdk_screen_make_display_name (gtk_widget_get_screen (menuitem));
       dir = terminal_screen_get_working_dir (window->priv->active_term);
 
@@ -2218,7 +2232,7 @@
                   TerminalWindow *window)
 {
   TerminalProfile *profile;
-  
+
   profile = g_object_get_data (G_OBJECT (menuitem),
                                "profile");
 
@@ -2274,7 +2288,7 @@
                                    GTK_MESSAGE_WARNING,
                                    GTK_BUTTONS_NONE,
                                    msg);
-  gtk_window_set_title (GTK_WINDOW(dialog), ""); 
+  gtk_window_set_title (GTK_WINDOW(dialog), "");
   g_free (msg);
   g_free (msg1);
 
@@ -2314,7 +2328,7 @@
   if (window->priv->active_term)
     {
       widget = terminal_screen_get_widget (window->priv->active_term);
-      
+
       terminal_widget_copy_clipboard (widget);
     }
 }
@@ -2330,7 +2344,7 @@
       widget = terminal_screen_get_widget (window->priv->active_term);
 
       terminal_widget_paste_clipboard (widget);
-    }  
+    }
 }
 
 static void
@@ -2352,7 +2366,7 @@
 
   if (window->priv->active_term == NULL)
     return;
-  
+
   profile = g_object_get_data (G_OBJECT (menu_item),
                                "profile");
 
@@ -2407,7 +2421,7 @@
 }
 
 static gboolean
-window_state_event_callback (GtkWidget            *widget, 
+window_state_event_callback (GtkWidget            *widget,
                              GdkEventWindowState  *event,
                              gpointer              user_data)
 {
@@ -2425,7 +2439,7 @@
     window->priv->fullscreen = new_state;
     gtk_check_menu_item_set_active (menu_item, new_state);
     }
-  
+
   /* Call any other handlers there may be */
   return FALSE;
 }
@@ -2453,7 +2467,7 @@
                          double *found)
 {
   int i;
-  
+
   i = 0;
   while (i < (int) G_N_ELEMENTS (zoom_factors))
     {
@@ -2463,10 +2477,10 @@
           *found = zoom_factors[i];
           return TRUE;
         }
-      
+
       ++i;
     }
-  
+
   return FALSE;
 }
 
@@ -2475,7 +2489,7 @@
                           double *found)
 {
   int i;
-  
+
   i = (int) G_N_ELEMENTS (zoom_factors) - 1;
   while (i >= 0)
     {
@@ -2485,7 +2499,7 @@
           *found = zoom_factors[i];
           return TRUE;
         }
-      
+
       --i;
     }
 
@@ -2498,12 +2512,12 @@
 {
   double current;
   TerminalScreen *screen;
-  
+
   screen = window->priv->active_term;
 
   if (screen == NULL)
     return;
-  
+
   current = terminal_screen_get_font_scale (screen);
 
   if (find_larger_zoom_factor (current, &current))
@@ -2519,12 +2533,12 @@
 {
   double current;
   TerminalScreen *screen;
-  
+
   screen = window->priv->active_term;
 
   if (screen == NULL)
     return;
-  
+
   current = terminal_screen_get_font_scale (screen);
 
   if (find_smaller_zoom_factor (current, &current))
@@ -2539,7 +2553,7 @@
                       TerminalWindow *window)
 {
   TerminalScreen *screen;
-  
+
   screen = window->priv->active_term;
 
   if (screen == NULL)
@@ -2565,7 +2579,7 @@
 {
   const char *charset;
   GtkWidget *widget;
-  
+
   if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menu_item)))
     return;
 
@@ -2690,48 +2704,40 @@
 move_left_tab_callback(GtkWidget      *menuitem,
                        TerminalWindow *window)
 {
+  GtkWidget *child;
   GtkNotebook *notebook;
-  gint page_num,last_page;
-  GtkWidget *page; 
+  gint page_num;
 
   notebook = GTK_NOTEBOOK (window->priv->notebook);
   page_num = gtk_notebook_get_current_page (notebook);
-  last_page = gtk_notebook_get_n_pages (notebook) - 1;
-  page = gtk_notebook_get_nth_page (notebook, page_num);
-  
-  if (page_num == 0)
-    terminal_notebook_move_tab (TERMINAL_NOTEBOOK (notebook), NULL,
-                                TERMINAL_SCREEN (page), last_page);
-  else
-    terminal_notebook_move_tab (TERMINAL_NOTEBOOK (notebook), NULL,
-                                TERMINAL_SCREEN (page), page_num-1);
 
-  update_tab_sensitivity (window);
-  reset_tab_menuitems (window);
+  if (page_num < 1) return; // FIXME: Do we want this?
+
+  child = gtk_notebook_get_nth_page (notebook, page_num);
+  gtk_notebook_reorder_child (notebook, child, page_num - 1);
+
+  update_tab_sensitivity (window); // FIXME: Do we really need this?
+  reset_tab_menuitems (window);    // FIXME: This probably gets caught in callback
 }
 
 static void
 move_right_tab_callback(GtkWidget      *menuitem,
                         TerminalWindow *window)
 {
+  GtkWidget *child;
   GtkNotebook *notebook;
-  gint page_num,last_page;
-  GtkWidget *page; 
+  gint page_num, n_pages;
 
   notebook = GTK_NOTEBOOK (window->priv->notebook);
   page_num = gtk_notebook_get_current_page (notebook);
-  last_page = gtk_notebook_get_n_pages (notebook) - 1;
-  page = gtk_notebook_get_nth_page (notebook, page_num);
-  
-  if (page_num == last_page)
-    terminal_notebook_move_tab (TERMINAL_NOTEBOOK (notebook), NULL,
-                                TERMINAL_SCREEN (page), 0);
-  else
-    terminal_notebook_move_tab (TERMINAL_NOTEBOOK (notebook), NULL,
-                                TERMINAL_SCREEN (page), page_num+1);
+  n_pages = gtk_notebook_get_n_pages (notebook) - 1;
+  if (page_num > n_pages - 1) return; // FIXME: Do we want this?
 
-  update_tab_sensitivity (window);
-  reset_tab_menuitems (window);
+  child = gtk_notebook_get_nth_page (notebook, page_num);
+  gtk_notebook_reorder_child (notebook, child, page_num + 1);
+
+  update_tab_sensitivity (window); // FIXME: Do we really need this?
+  reset_tab_menuitems (window);    // FIXME: This probably gets caught in callback
 }
 
 static void
@@ -2764,12 +2770,12 @@
 {
   GtkNotebook *notebook;
   gint page_num;
-  GtkWidget *page; 
+  GtkWidget *page;
 
   notebook = GTK_NOTEBOOK (window->priv->notebook);
   page_num = gtk_notebook_get_current_page (notebook);
   page = gtk_notebook_get_nth_page (notebook, page_num);
-  
+
   detach_tab (TERMINAL_SCREEN (page), window);
 }
 
@@ -2780,11 +2786,11 @@
   if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menuitem)))
     {
       int page_num;
-      
+
       page_num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem),
                                                      "notebook-page"));
 
-  
+
       gtk_notebook_set_current_page (GTK_NOTEBOOK (window->priv->notebook),
                                      page_num);
     }
@@ -2857,7 +2863,7 @@
       TerminalWindow *window;
 
       window = TERMINAL_WINDOW (data);
-      
+
       /* When the default changes, we get a settings change
        * on the old default and the new. We only rebuild
        * the menu on the notify for the new default.
@@ -2873,7 +2879,7 @@
 {
   GList *profiles;
   GList *tmp;
-  
+
   profiles = terminal_profile_get_list ();
 
   tmp = profiles;
@@ -2884,13 +2890,13 @@
       g_signal_handlers_disconnect_by_func (G_OBJECT (profile),
                                             G_CALLBACK (default_profile_changed),
                                             window);
-      
+
       g_signal_connect_object (G_OBJECT (profile),
                                "changed",
                                G_CALLBACK (default_profile_changed),
                                G_OBJECT (window),
                                0);
-      
+
       tmp = tmp->next;
     }
 
@@ -2901,7 +2907,7 @@
 terminal_window_reread_profile_list (TerminalWindow *window)
 {
   monitor_profiles_for_is_default_change (window);
-  
+
   fill_in_config_picker_submenu (window);
   fill_in_new_term_submenus (window);
 }
