Index: src/apps/terminal/TermWindow.cpp
===================================================================
--- src/apps/terminal/TermWindow.cpp	(revision 30153)
+++ src/apps/terminal/TermWindow.cpp	(working copy)
@@ -125,6 +125,13 @@
 		fWindow->_RemoveTab(index);
 	}
 
+	virtual void TabRenameFinished(int32 index)
+	{
+		SmartTabView::TabRenameFinished(index);
+		fWindow->UpdateSessionWindowTitle(index);
+		TabAt(Selection())->View()->MakeFocus();
+	}
+
 private:
 	TermWindow*	fWindow;
 };
@@ -184,6 +191,7 @@
 		session->windowTitle = title;
 		BTab* tab = fTabView->TabAt(index);
 		tab->SetLabel(session->windowTitle.String());
+		fTabView->Invalidate(fTabView->TabFrame(index));
 		if (index == fTabView->Selection())
 			SetTitle(session->windowTitle.String());
 	}
@@ -200,6 +208,18 @@
 
 
 void
+TermWindow::UpdateSessionWindowTitle(int32 index)
+{
+	Session* session = (Session*) fSessions.ItemAt(index);
+	if (session != NULL) {
+		session->windowTitle = fTabView->TabAt(index)->Label();
+		if (index == fTabView->Selection())
+			SetTitle(session->windowTitle.String());
+	}
+}
+
+
+void
 TermWindow::_InitWindow()
 {
 	// make menu bar
Index: src/apps/terminal/SmartTabView.h
===================================================================
--- src/apps/terminal/SmartTabView.h	(revision 30153)
+++ src/apps/terminal/SmartTabView.h	(working copy)
@@ -11,39 +11,43 @@
 #include <TabView.h>
 
 class BPopUpMenu;
+class BTextControl;
 class SmartTabView : public BTabView {
 public:
-	SmartTabView(BRect frame, const char *name,
-			button_width width = B_WIDTH_AS_USUAL, 
-			uint32 resizingMode = B_FOLLOW_ALL,
-			uint32 flags = B_FULL_UPDATE_ON_RESIZE |
-					B_WILL_DRAW | B_NAVIGABLE_JUMP |
-					B_FRAME_EVENTS | B_NAVIGABLE);
-	virtual ~SmartTabView();
+							SmartTabView(BRect frame, const char *name,
+								button_width width = B_WIDTH_AS_USUAL, 
+								uint32 resizingMode = B_FOLLOW_ALL,
+								uint32 flags = B_FULL_UPDATE_ON_RESIZE |
+									B_WILL_DRAW | B_NAVIGABLE_JUMP |
+									B_FRAME_EVENTS | B_NAVIGABLE);
+	virtual 				~SmartTabView();
 
-			void SetInsets(float left, float top, float right, float bottom);
+			void 			SetInsets(float left, float top, float right, float bottom);
 
-	virtual void MouseDown(BPoint where);
+	virtual void 			MouseDown(BPoint where);
 
-	virtual void AttachedToWindow();
-	virtual void AllAttached();
+	virtual void 			AttachedToWindow();
+	virtual void 			AllAttached();
 
-	virtual void MessageReceived(BMessage *message);
+	virtual void 			MessageReceived(BMessage *message);
 
-	virtual	void Select(int32 tab);
+	virtual	void 			Select(int32 tab);
 
-	virtual	void RemoveAndDeleteTab(int32 index);
+	virtual	void 			AddTab(BView *target, BTab *tab = NULL);
+	virtual	void			RenameTab(int32 index);
+	virtual	void 			RemoveAndDeleteTab(int32 index);
+	virtual BTab* 			RemoveTab(int32 index);
 
-	virtual	void AddTab(BView *target, BTab *tab = NULL);
-	virtual BTab* RemoveTab(int32 index);
+	virtual BRect 			DrawTabs();
 
-	virtual BRect DrawTabs();
+protected:
+	virtual void			TabRenameFinished(int32 index);
 
 private:
-		int32 _ClickedTabIndex(const BPoint &point);	
+			int32 			_ClickedTabIndex(const BPoint &point);	
 
-private:
-	BRect	fInsets;
+			BRect			fInsets;
+			BTextControl*	fRenameTabControl;
 };
 
 #endif // __SMARTTABVIEW_H
Index: src/apps/terminal/TermScrollView.cpp
===================================================================
--- src/apps/terminal/TermScrollView.cpp	(revision 30153)
+++ src/apps/terminal/TermScrollView.cpp	(working copy)
@@ -58,3 +58,13 @@
 TermScrollView::~TermScrollView()
 {
 }
+
+
+void
+TermScrollView::MakeFocus(bool focused)
+{
+	BScrollView::MakeFocus(focused);
+	if (focused && fVerticalScrollBar != NULL 
+		&& fVerticalScrollBar->Target() != NULL)
+		fVerticalScrollBar->Target()->MakeFocus(focused);
+}
Index: src/apps/terminal/TermWindow.h
===================================================================
--- src/apps/terminal/TermWindow.h	(revision 30153)
+++ src/apps/terminal/TermWindow.h	(working copy)
@@ -54,6 +54,7 @@
 			void	SetSessionWindowTitle(TermView* termView,
 						const char* title);
 			void	SessionChanged();
+			void	UpdateSessionWindowTitle(int32 index);
 
 protected:
 	virtual void	MessageReceived(BMessage *message);
Index: src/apps/terminal/SmartTabView.cpp
===================================================================
--- src/apps/terminal/SmartTabView.cpp	(revision 30153)
+++ src/apps/terminal/SmartTabView.cpp	(working copy)
@@ -13,17 +13,20 @@
 #include <Messenger.h>
 #include <PopUpMenu.h>
 #include <Screen.h>
+#include <TextControl.h>
 #include <Window.h>
 
 #include <stdio.h>
 
 const static uint32 kCloseTab = 'ClTb';
+const static uint32 kTabRenamed = 'TbRn';
 
 SmartTabView::SmartTabView(BRect frame, const char *name, button_width width, 
 				uint32 resizingMode, uint32 flags)
 	:
 	BTabView(frame, name, width, resizingMode, flags),
-	fInsets(0, 0, 0, 0)
+	fInsets(0, 0, 0, 0),
+	fRenameTabControl(NULL)
 {
 	// Resize the container view to fill the complete tab view for single-tab
 	// mode. Later, when more than one tab is added, we shrink the container
@@ -59,7 +62,14 @@
 		if (tabIndex >= 0) {		
 			int32 buttons;
 			Window()->CurrentMessage()->FindInt32("buttons", &buttons);
-			if (buttons & B_SECONDARY_MOUSE_BUTTON) {	
+			if (buttons & B_PRIMARY_MOUSE_BUTTON) {
+				int32 clicks;
+				Window()->CurrentMessage()->FindInt32("clicks", &clicks);
+				if (clicks == 2) {
+					RenameTab(tabIndex);
+					handled = true;
+				}
+			} else if (buttons & B_SECONDARY_MOUSE_BUTTON) {	
 				BMessage *message = new BMessage(kCloseTab);
 				message->AddInt32("index", tabIndex);
 				
@@ -108,6 +118,13 @@
 				RemoveAndDeleteTab(tabIndex);
 			break;
 		}		
+		case kTabRenamed:
+		{
+			int32 tabIndex;
+			if (message->FindInt32("index", &tabIndex) != B_OK)
+				tabIndex = -1;
+			TabRenameFinished(tabIndex);
+		}
 		default:
 			BTabView::MessageReceived(message);
 			break;	
@@ -200,6 +217,51 @@
 }
 
 
+void
+SmartTabView::RenameTab(int32 index)
+{
+	if (!Window()->LockLooper())
+		return;
+	if (fRenameTabControl != NULL)
+		TabRenameFinished(-1);
+
+	BMessage *renamedMessage = new BMessage(kTabRenamed);
+	if (renamedMessage != NULL
+		&& renamedMessage->AddInt32("index", index) == B_OK) {
+		fRenameTabControl = new BTextControl(TabFrame(index), "renameTab", NULL,
+			TabAt(index)->Label(), renamedMessage);
+		if (fRenameTabControl != NULL) {
+			fRenameTabControl->SetTarget(BMessenger(this));
+			AddChild(fRenameTabControl);
+			fRenameTabControl->MakeFocus();
+		}
+	}
+
+	Window()->UnlockLooper();
+}
+
+
+void
+SmartTabView::TabRenameFinished(int32 index)
+{
+	if (!Window()->LockLooper())
+		return;
+	
+	if (fRenameTabControl != NULL) {
+		if (index >= 0) {
+			BTab* tab = TabAt(index);
+			if (tab != NULL)
+				tab->SetLabel(fRenameTabControl->Text());
+		}
+		RemoveChild(fRenameTabControl);
+		delete fRenameTabControl;
+		fRenameTabControl = NULL;
+	}
+
+	Window()->UnlockLooper();
+}
+
+
 BRect
 SmartTabView::DrawTabs()
 {
Index: src/apps/terminal/TermScrollView.h
===================================================================
--- src/apps/terminal/TermScrollView.h	(revision 30153)
+++ src/apps/terminal/TermScrollView.h	(working copy)
@@ -14,6 +14,8 @@
 									BView* target,
 									uint32 resizingMode = B_FOLLOW_ALL);
 								~TermScrollView();
+
+		virtual	void			MakeFocus(bool focused = true);
 };
 
 
