Index: BarWindow.h
===================================================================
--- BarWindow.h	(revision 41570)
+++ BarWindow.h	(working copy)
@@ -54,8 +54,6 @@
 	virtual void				WorkspaceActivated(int32 workspace,
 									bool activate);
 	virtual void				ScreenChanged(BRect size, color_space depth);
-	virtual void				DispatchMessage(BMessage* message,
-									BHandler* handler);
 	virtual void				MessageReceived(BMessage* message);
 	virtual void				Minimize(bool minimize);
 
Index: BarView.h
===================================================================
--- BarView.h	(revision 41570)
+++ BarView.h	(working copy)
@@ -58,6 +58,9 @@
 const float kMenuBarHeight = 21.0f;
 const float kStatusHeight = 22.0f;
 
+const float kHModeHiddenHeight = 1.0f;
+const float kMaxPreventHidingDist = 80.0f;
+
 class BShelf;
 class TBarMenuBar;
 class TExpandoMenuBar;
@@ -78,11 +81,14 @@
 		virtual void MessageReceived(BMessage* message);
 		virtual void MouseMoved(BPoint where, uint32 transit,
 			const BMessage* dragMessage);
+		virtual void MouseDown(BPoint where);
 
 		void SaveSettings();
-		void UpdateAutoRaise();
+		void UpdateEventMask();
 		void UpdatePlacement();
 		void ChangeState(int32 state, bool vertical, bool left, bool top);
+		void RaiseDeskbar(bool raise);
+		void HideDeskbar(bool hide);
 
 		bool Vertical() const;
 		bool Left() const;
@@ -136,7 +142,7 @@
 		TExpandoMenuBar* ExpandoMenuBar() const;
 		TBarMenuBar* BarMenuBar() const;
 		TDragRegion* DragRegion() const { return fDragRegion; }
-
+			
 	private:
 		friend class TBeMenu;
 		friend class PreferencesWindow;
Index: BarApp.h
===================================================================
--- BarApp.h	(revision 41570)
+++ BarApp.h	(working copy)
@@ -81,6 +81,7 @@
 const uint32 kSuperExpando = 'SprE';
 const uint32 kExpandNewTeams = 'ExTm';
 const uint32 kAutoRaise = 'AtRs';
+const uint32 kAutoHide = 'AtHd';
 const uint32 kRestartTracker = 'Trak';
 
 // from roster_private.h
@@ -110,6 +111,7 @@
 	bool superExpando;
 	bool expandNewTeams;
 	bool autoRaise;
+	bool autoHide;
 	bool recentAppsEnabled;
 	bool recentDocsEnabled;
 	bool recentFoldersEnabled;
Index: BarWindow.cpp
===================================================================
--- BarWindow.cpp	(revision 41570)
+++ BarWindow.cpp	(working copy)
@@ -106,29 +106,6 @@
 
 
 void
-TBarWindow::DispatchMessage(BMessage* message, BHandler* handler)
-{
-	// Activate the window when you click on it (ie. on the tray area,
-	// the menu part will do this automatically)
-	if (message->what == B_MOUSE_DOWN) {
-		if (!((TBarApp*)be_app)->Settings()->autoRaise)
-			Activate(true);
-
-		if (_IsFocusMessage(message)
-			&& (modifiers() & (B_CONTROL_KEY | B_COMMAND_KEY | B_OPTION_KEY
-					| B_SHIFT_KEY)) == (B_CONTROL_KEY | B_COMMAND_KEY)) {
-			// The window key was pressed - enter dragging code
-			fBarView->DragRegion()->MouseDown(
-				fBarView->DragRegion()->DragRegion().LeftTop());
-			return;
-		}
-	}
-
-	BWindow::DispatchMessage(message, handler);
-}
-
-
-void
 TBarWindow::MenusBeginning()
 {
 	BPath path;
@@ -182,7 +159,7 @@
 		sBeMenu->UnlockLooper();
 	}
 
-	fBarView->UpdateAutoRaise();
+	fBarView->UpdateEventMask();
 }
 
 
Index: PreferencesWindow.h
===================================================================
--- PreferencesWindow.h	(revision 41570)
+++ PreferencesWindow.h	(working copy)
@@ -57,6 +57,7 @@
 
 			BCheckBox*		fWindowAlwaysOnTop;
 			BCheckBox*		fWindowAutoRaise;
+			BCheckBox*		fWindowAutoHide;
 };
 
 #endif	// _PREFERENCES_WINDOW_H
Index: BarView.cpp
===================================================================
--- BarView.cpp	(revision 41570)
+++ BarView.cpp	(working copy)
@@ -110,7 +110,7 @@
 	SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
 	SetFont(be_plain_font);
 
-	UpdateAutoRaise();
+	UpdateEventMask();
 	UpdatePlacement();
 
 	fTrackingHookData.fTrackingHook = MenuTrackingHook;
@@ -182,22 +182,92 @@
 {
 	if (Window() == NULL || EventMask() == 0)
 		return;
+	
+	desk_settings* settings = ((TBarApp*)be_app)->Settings();
+	bool alwaysOnTop = settings->alwaysOnTop;
+	bool autoRaise = settings->autoRaise;
+	bool autoHide = settings->autoHide;
+		
+	if (!autoRaise && !autoHide)
+		return;
+		
+	if (DragRegion()->IsDragging()) {
+		return;
+	}
 
+	bool isTopMost = Window()->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
+	bool isHidden = IsHidden();
+	
 	// Auto-Raise
-
 	where = ConvertToScreen(where);
 	BScreen screen(Window());
-	BRect frame = screen.Frame();
-	if (where.x == frame.left || where.x == frame.right
-		|| where.y == frame.top || where.y == frame.bottom) {
-		// cursor is on screen edge
-		if (Window()->Frame().Contains(where))
-			Window()->Activate();
+	BRect screenFrame = screen.Frame();
+	if ((where.x == screenFrame.left || where.x == screenFrame.right
+		|| where.y == screenFrame.top || where.y == screenFrame.bottom)
+		&& Window()->Frame().Contains(where)) {
+		// cursor is on a screen edge within the window frame
+
+		if (autoRaise && !isTopMost) {
+			RaiseDeskbar(true);
+		}
+		
+		if (autoHide && isHidden) {
+			HideDeskbar(false);
+		}
+	} else {
+		// cursor is not on screen edge
+		BRect preventHideArea = Window()->Frame().InsetByCopy(
+			-kMaxPreventHidingDist, -kMaxPreventHidingDist);
+
+		if (preventHideArea.Contains(where))
+			return;
+			
+		// cursor to bar distance above threshold
+		if (autoRaise && isTopMost) {
+			RaiseDeskbar(false);
+		}
+		
+		if (autoHide && !isHidden) {
+			HideDeskbar(true);
+		}
 	}
 }
 
 
 void
+TBarView::MouseDown(BPoint where)
+{
+	where = ConvertToScreen(where);
+
+	if (Window()->Frame().Contains(where)) {
+		Window()->Activate();
+
+		if ((modifiers() & (B_CONTROL_KEY | B_COMMAND_KEY | B_OPTION_KEY
+					| B_SHIFT_KEY)) == (B_CONTROL_KEY | B_COMMAND_KEY)) {
+			// The window key was pressed - enter dragging code
+			DragRegion()->MouseDown(
+				DragRegion()->DragRegion().LeftTop());
+			return;
+		}
+	} else {
+		// hide deskbar if required
+		bool autoRaise = ((TBarApp*)be_app)->Settings()->autoRaise;
+		bool autoHide = ((TBarApp*)be_app)->Settings()->autoHide;
+		bool isTopMost = Window()->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
+		bool isHidden = IsHidden();		
+		
+		if (autoRaise && isTopMost) {
+			RaiseDeskbar(false);
+		}
+		
+		if (autoHide && !isHidden) {
+			HideDeskbar(true);
+		}
+	}
+}
+
+
+void
 TBarView::PlaceBeMenu()
 {
 	// top or bottom, full
@@ -334,27 +404,43 @@
 {
 	float windowHeight = 0;
 	float windowWidth = sMinimumWindowWidth;
-	if (fState == kFullState) {
-		windowHeight = screenFrame.bottom;
-		windowWidth = fBarMenuBar->Frame().Width();
-	} else if (fState == kExpandoState) {
-		if (fVertical) {
-			// top left or right
-			windowHeight = fExpando->Frame().bottom;
+	bool calcHiddenSize = ((TBarApp*)be_app)->Settings()->autoHide
+								&& IsHidden() && !DragRegion()->IsDragging();
+	
+	if (!calcHiddenSize)
+	{
+		if (fState == kFullState) {
+			windowHeight = screenFrame.bottom;
+			windowWidth = fBarMenuBar->Frame().Width();
+		} else if (fState == kExpandoState) {
+			if (fVertical) {
+				// top left or right
+				windowHeight = fExpando->Frame().bottom;
+			} else {
+				// top or bottom, full
+				fExpando->CheckItemSizes(0);
+				windowHeight = kHModeHeight;	
+				windowWidth = screenFrame.Width();
+			}
 		} else {
+			// four corners
+			if (fTrayLocation != 0)
+				windowHeight = fDragRegion->Frame().bottom;
+			else
+				windowHeight = fBarMenuBar->Frame().bottom;
+		}
+	} else {
+		windowHeight = kHModeHiddenHeight;
+		
+		if (fState == kExpandoState && !fVertical) {
 			// top or bottom, full
 			fExpando->CheckItemSizes(0);
-			windowHeight = kHModeHeight;
 			windowWidth = screenFrame.Width();
+		} else {
+			windowWidth = kHModeHiddenHeight;
 		}
-	} else {
-		// four corners
-		if (fTrayLocation != 0)
-			windowHeight = fDragRegion->Frame().bottom;
-		else
-			windowHeight = fBarMenuBar->Frame().bottom;
 	}
-
+	
 	*width = windowWidth;
 	*height = windowHeight;
 }
@@ -414,9 +500,10 @@
 
 
 void
-TBarView::UpdateAutoRaise()
+TBarView::UpdateEventMask()
 {
-	if (((TBarApp*)be_app)->Settings()->autoRaise)
+	if (((TBarApp*)be_app)->Settings()->autoRaise ||
+		((TBarApp*)be_app)->Settings()->autoHide)
 		SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
 	else
 		SetEventMask(0);
@@ -443,7 +530,7 @@
 	fTop = top;
 
 	// Send a message to the preferences window to let it know to enable
-	// or disabled preference items
+	// or disable preference items
 	if (stateChanged || vertSwap)
 		be_app->PostMessage(kStateChanged);
 
@@ -507,6 +594,33 @@
 }
 
 
+void
+TBarView::RaiseDeskbar(bool raise)
+{
+	if (raise)
+		Window()->SetFeel(B_FLOATING_ALL_WINDOW_FEEL);
+	else
+		Window()->SetFeel(B_NORMAL_WINDOW_FEEL);
+}
+
+void
+TBarView::HideDeskbar(bool hide)
+{
+	BScreen screen(Window());
+	BRect screenFrame = screen.Frame();
+	
+	if (hide) {
+		Hide();
+		PositionWindow(screenFrame);
+		SizeWindow(screenFrame);
+	} else {
+		Show();
+		SizeWindow(screenFrame);
+		PositionWindow(screenFrame);
+	}
+}
+
+
 // window placement functions
 
 bool
Index: BarApp.cpp
===================================================================
--- BarApp.cpp	(revision 41570)
+++ BarApp.cpp	(working copy)
@@ -206,6 +206,7 @@
 		storedSettings.AddBool("superExpando", fSettings.superExpando);
 		storedSettings.AddBool("expandNewTeams", fSettings.expandNewTeams);
 		storedSettings.AddBool("autoRaise", fSettings.autoRaise);
+		storedSettings.AddBool("autoHide", fSettings.autoHide);
 		storedSettings.AddBool("recentAppsEnabled",
 			fSettings.recentAppsEnabled);
 		storedSettings.AddBool("recentDocsEnabled",
@@ -241,6 +242,7 @@
 	settings.superExpando = false;
 	settings.expandNewTeams = false;
 	settings.autoRaise = false;
+	settings.autoHide = false;
 	settings.recentAppsEnabled = true;
 	settings.recentDocsEnabled = true;
 	settings.recentFoldersEnabled = true;
@@ -290,6 +292,7 @@
 			storedSettings.FindBool("superExpando", &settings.superExpando);
 			storedSettings.FindBool("expandNewTeams", &settings.expandNewTeams);
 			storedSettings.FindBool("autoRaise", &settings.autoRaise);
+			storedSettings.FindBool("autoHide", &settings.autoHide);
 			storedSettings.FindBool("recentAppsEnabled",
 				&settings.recentAppsEnabled);
 			storedSettings.FindBool("recentDocsEnabled",
@@ -417,10 +420,19 @@
 			fSettings.autoRaise = !fSettings.autoRaise;
 
 			fBarWindow->Lock();
-			BarView()->UpdateAutoRaise();
+			BarView()->UpdateEventMask();
 			fBarWindow->Unlock();
 			break;
 
+		case kAutoHide:
+			fSettings.autoHide = !fSettings.autoHide;
+
+			fBarWindow->Lock();
+			BarView()->UpdateEventMask();
+			BarView()->HideDeskbar(fSettings.autoHide);
+			fBarWindow->Unlock();
+			break;
+			
 		case kTrackerFirst:
 			fSettings.trackerAlwaysFirst = !fSettings.trackerAlwaysFirst;
 
Index: StatusView.h
===================================================================
--- StatusView.h	(revision 41570)
+++ StatusView.h	(working copy)
@@ -197,6 +197,8 @@
 
 	int32 DragRegionLocation() const;
 	void SetDragRegionLocation(int32);
+	
+	bool IsDragging() {return IsTracking();}
 
 private:
 	TBarView* fBarView;
Index: PreferencesWindow.cpp
===================================================================
--- PreferencesWindow.cpp	(revision 41570)
+++ PreferencesWindow.cpp	(working copy)
@@ -62,6 +62,8 @@
 		new BMessage(kAlwaysTop));
 	fWindowAutoRaise = new BCheckBox(B_TRANSLATE("Auto-raise"),
 		new BMessage(kAutoRaise));
+	fWindowAutoHide = new BCheckBox(B_TRANSLATE("Auto-hide"),
+		new BMessage(kAutoHide));
 
 	BTextView* docTextView = fMenuRecentDocumentCount->TextView();
 	BTextView* appTextView = fMenuRecentApplicationCount->TextView();
@@ -122,6 +124,7 @@
 
 	fWindowAlwaysOnTop->SetValue(appSettings->alwaysOnTop);
 	fWindowAutoRaise->SetValue(appSettings->autoRaise);
+	fWindowAutoHide->SetValue(appSettings->autoHide);
 
 	_EnableDisableDependentItems();
 
@@ -134,6 +137,7 @@
 
 	fWindowAlwaysOnTop->SetTarget(be_app);
 	fWindowAutoRaise->SetTarget(be_app);
+	fWindowAutoHide->SetTarget(be_app);	
 
 	// Layout
 	fMenuBox = new BBox("fMenuBox");
@@ -196,6 +200,7 @@
 		.AddGroup(B_VERTICAL, 1)
 			.Add(fWindowAlwaysOnTop)
 			.Add(fWindowAutoRaise)
+			.Add(fWindowAutoHide)
 			.AddGlue()
 			.SetInsets(10, 10, 10, 10)
 			.End()
@@ -310,4 +315,3 @@
 	if (!active && IsMinimized())
 		PostMessage(B_QUIT_REQUESTED);
 }
-
