From e27005998f2cb3d61a7a95e97ff9b5bcbd3eadd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 6 Jul 2011 17:34:44 +0000 Subject: [PATCH] * Applied a patch of x-ist that implements auto hide functionality with minor coding style changes by myself. * Thanks, and sorry for the long delay! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42383 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/deskbar/BarApp.cpp | 19 ++- src/apps/deskbar/BarApp.h | 2 + src/apps/deskbar/BarView.cpp | 162 ++++++++++++++++++++----- src/apps/deskbar/BarView.h | 9 +- src/apps/deskbar/BarWindow.cpp | 25 +--- src/apps/deskbar/BarWindow.h | 2 - src/apps/deskbar/PreferencesWindow.cpp | 13 +- src/apps/deskbar/PreferencesWindow.h | 1 + src/apps/deskbar/StatusView.h | 2 + 9 files changed, 173 insertions(+), 62 deletions(-) diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index 3a5716a490..58664f75a7 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -206,6 +206,7 @@ TBarApp::SaveSettings() 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 @@ TBarApp::InitSettings() 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 @@ TBarApp::InitSettings() 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", @@ -408,19 +411,29 @@ TBarApp::MessageReceived(BMessage* message) case kAlwaysTop: fSettings.alwaysOnTop = !fSettings.alwaysOnTop; - fBarWindow->SetFeel(fSettings.alwaysOnTop ? B_FLOATING_ALL_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL); + fPreferencesWindow->PostMessage(kStateChanged); break; case kAutoRaise: - fSettings.autoRaise = !fSettings.autoRaise; + fSettings.autoRaise = fSettings.alwaysOnTop ? false : + !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; diff --git a/src/apps/deskbar/BarApp.h b/src/apps/deskbar/BarApp.h index 69961513aa..736e638a0a 100644 --- a/src/apps/deskbar/BarApp.h +++ b/src/apps/deskbar/BarApp.h @@ -81,6 +81,7 @@ const uint32 kSortRunningApps = 'SAps'; 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 @@ struct desk_settings { bool superExpando; bool expandNewTeams; bool autoRaise; + bool autoHide; bool recentAppsEnabled; bool recentDocsEnabled; bool recentFoldersEnabled; diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index cac3472ffa..6e71956535 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -110,7 +110,7 @@ TBarView::AttachedToWindow() SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); SetFont(be_plain_font); - UpdateAutoRaise(); + UpdateEventMask(); UpdatePlacement(); fTrackingHookData.fTrackingHook = MenuTrackingHook; @@ -183,16 +183,79 @@ TBarView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) if (Window() == NULL || EventMask() == 0) return; - // Auto-Raise + 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; + + // 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 (!alwaysOnTop && 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 (!alwaysOnTop && 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 + desk_settings* settings = ((TBarApp*)be_app)->Settings(); + bool alwaysOnTop = settings->alwaysOnTop; + bool autoRaise = settings->autoRaise; + bool autoHide = settings->autoHide; + bool isTopMost = Window()->Feel() == B_FLOATING_ALL_WINDOW_FEEL; + + if (!alwaysOnTop && autoRaise && isTopMost) + RaiseDeskbar(false); + + if (autoHide && !IsHidden()) + HideDeskbar(true); } } @@ -334,25 +397,39 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height) { 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 { - // top or bottom, full - fExpando->CheckItemSizes(0); - windowHeight = kHModeHeight; - windowWidth = screenFrame.Width(); + // four corners + if (fTrayLocation != 0) + windowHeight = fDragRegion->Frame().bottom; + else + windowHeight = fBarMenuBar->Frame().bottom; } } else { - // four corners - if (fTrayLocation != 0) - windowHeight = fDragRegion->Frame().bottom; - else - windowHeight = fBarMenuBar->Frame().bottom; + windowHeight = kHModeHiddenHeight; + + if (fState == kExpandoState && !fVertical) { + // top or bottom, full + fExpando->CheckItemSizes(0); + windowWidth = screenFrame.Width(); + } else + windowWidth = kHModeHiddenHeight; } *width = windowWidth; @@ -408,15 +485,14 @@ TBarView::SaveSettings() settings->showTime = ShowingClock(); fReplicantTray->RememberClockSettings(); - settings->alwaysOnTop - = (Window()->Feel() & B_FLOATING_ALL_WINDOW_FEEL) != 0; } 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 +519,7 @@ TBarView::ChangeState(int32 state, bool vertical, bool left, bool top) 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 +583,34 @@ TBarView::ChangeState(int32 state, bool vertical, bool left, bool top) } +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 diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h index 8f4e5b8685..9e165cbfe0 100644 --- a/src/apps/deskbar/BarView.h +++ b/src/apps/deskbar/BarView.h @@ -57,6 +57,8 @@ const float kMiniHeight = 46.0f; const float kHModeHeight = 21.0f; const float kMenuBarHeight = 21.0f; const float kStatusHeight = 22.0f; +const float kHModeHiddenHeight = 1.0f; +const float kMaxPreventHidingDist = 80.0f; class BShelf; class TBarMenuBar; @@ -78,11 +80,14 @@ class TBarView : public BView { 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 +141,7 @@ class TBarView : public BView { TExpandoMenuBar* ExpandoMenuBar() const; TBarMenuBar* BarMenuBar() const; TDragRegion* DragRegion() const { return fDragRegion; } - + private: friend class TBeMenu; friend class PreferencesWindow; diff --git a/src/apps/deskbar/BarWindow.cpp b/src/apps/deskbar/BarWindow.cpp index b76fca4899..90c2935a24 100644 --- a/src/apps/deskbar/BarWindow.cpp +++ b/src/apps/deskbar/BarWindow.cpp @@ -105,29 +105,6 @@ TBarWindow::TBarWindow() } -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() { @@ -182,7 +159,7 @@ TBarWindow::MenusEnded() sBeMenu->UnlockLooper(); } - fBarView->UpdateAutoRaise(); + fBarView->UpdateEventMask(); } diff --git a/src/apps/deskbar/BarWindow.h b/src/apps/deskbar/BarWindow.h index 73568f1eaf..b8da5ffac5 100644 --- a/src/apps/deskbar/BarWindow.h +++ b/src/apps/deskbar/BarWindow.h @@ -54,8 +54,6 @@ public: 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); diff --git a/src/apps/deskbar/PreferencesWindow.cpp b/src/apps/deskbar/PreferencesWindow.cpp index bb378f1bc7..3fa9f08496 100644 --- a/src/apps/deskbar/PreferencesWindow.cpp +++ b/src/apps/deskbar/PreferencesWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2009 Haiku, Inc. + * Copyright 2009-2011 Haiku, Inc. * All Rights Reserved. Distributed under the terms of the MIT License. * * Authors: @@ -62,6 +62,8 @@ PreferencesWindow::PreferencesWindow(BRect frame) 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 @@ PreferencesWindow::PreferencesWindow(BRect frame) fWindowAlwaysOnTop->SetValue(appSettings->alwaysOnTop); fWindowAutoRaise->SetValue(appSettings->autoRaise); + fWindowAutoHide->SetValue(appSettings->autoHide); _EnableDisableDependentItems(); @@ -134,6 +137,7 @@ PreferencesWindow::PreferencesWindow(BRect frame) fWindowAlwaysOnTop->SetTarget(be_app); fWindowAutoRaise->SetTarget(be_app); + fWindowAutoHide->SetTarget(be_app); // Layout fMenuBox = new BBox("fMenuBox"); @@ -196,6 +200,7 @@ PreferencesWindow::PreferencesWindow(BRect frame) .AddGroup(B_VERTICAL, 1) .Add(fWindowAlwaysOnTop) .Add(fWindowAutoRaise) + .Add(fWindowAutoHide) .AddGlue() .SetInsets(10, 10, 10, 10) .End() @@ -301,6 +306,11 @@ PreferencesWindow::_EnableDisableDependentItems() fMenuRecentFolderCount->SetEnabled(true); else fMenuRecentFolderCount->SetEnabled(false); + + if (fWindowAlwaysOnTop->Value() == B_CONTROL_ON) + fWindowAutoRaise->SetEnabled(false); + else + fWindowAutoRaise->SetEnabled(true); } @@ -310,4 +320,3 @@ PreferencesWindow::WindowActivated(bool active) if (!active && IsMinimized()) PostMessage(B_QUIT_REQUESTED); } - diff --git a/src/apps/deskbar/PreferencesWindow.h b/src/apps/deskbar/PreferencesWindow.h index a45005cee8..df50663558 100644 --- a/src/apps/deskbar/PreferencesWindow.h +++ b/src/apps/deskbar/PreferencesWindow.h @@ -57,6 +57,7 @@ private: BCheckBox* fWindowAlwaysOnTop; BCheckBox* fWindowAutoRaise; + BCheckBox* fWindowAutoHide; }; #endif // _PREFERENCES_WINDOW_H diff --git a/src/apps/deskbar/StatusView.h b/src/apps/deskbar/StatusView.h index 31fb82f305..28438e9760 100644 --- a/src/apps/deskbar/StatusView.h +++ b/src/apps/deskbar/StatusView.h @@ -197,6 +197,8 @@ public: int32 DragRegionLocation() const; void SetDragRegionLocation(int32); + + bool IsDragging() {return IsTracking();} private: TBarView* fBarView;