* 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
This commit is contained in:
Axel Dörfler
2011-07-06 17:34:44 +00:00
parent 13bec72c73
commit e27005998f
9 changed files with 173 additions and 62 deletions
+16 -3
View File
@@ -206,6 +206,7 @@ TBarApp::SaveSettings()
storedSettings.AddBool("superExpando", fSettings.superExpando); storedSettings.AddBool("superExpando", fSettings.superExpando);
storedSettings.AddBool("expandNewTeams", fSettings.expandNewTeams); storedSettings.AddBool("expandNewTeams", fSettings.expandNewTeams);
storedSettings.AddBool("autoRaise", fSettings.autoRaise); storedSettings.AddBool("autoRaise", fSettings.autoRaise);
storedSettings.AddBool("autoHide", fSettings.autoHide);
storedSettings.AddBool("recentAppsEnabled", storedSettings.AddBool("recentAppsEnabled",
fSettings.recentAppsEnabled); fSettings.recentAppsEnabled);
storedSettings.AddBool("recentDocsEnabled", storedSettings.AddBool("recentDocsEnabled",
@@ -241,6 +242,7 @@ TBarApp::InitSettings()
settings.superExpando = false; settings.superExpando = false;
settings.expandNewTeams = false; settings.expandNewTeams = false;
settings.autoRaise = false; settings.autoRaise = false;
settings.autoHide = false;
settings.recentAppsEnabled = true; settings.recentAppsEnabled = true;
settings.recentDocsEnabled = true; settings.recentDocsEnabled = true;
settings.recentFoldersEnabled = true; settings.recentFoldersEnabled = true;
@@ -290,6 +292,7 @@ TBarApp::InitSettings()
storedSettings.FindBool("superExpando", &settings.superExpando); storedSettings.FindBool("superExpando", &settings.superExpando);
storedSettings.FindBool("expandNewTeams", &settings.expandNewTeams); storedSettings.FindBool("expandNewTeams", &settings.expandNewTeams);
storedSettings.FindBool("autoRaise", &settings.autoRaise); storedSettings.FindBool("autoRaise", &settings.autoRaise);
storedSettings.FindBool("autoHide", &settings.autoHide);
storedSettings.FindBool("recentAppsEnabled", storedSettings.FindBool("recentAppsEnabled",
&settings.recentAppsEnabled); &settings.recentAppsEnabled);
storedSettings.FindBool("recentDocsEnabled", storedSettings.FindBool("recentDocsEnabled",
@@ -408,19 +411,29 @@ TBarApp::MessageReceived(BMessage* message)
case kAlwaysTop: case kAlwaysTop:
fSettings.alwaysOnTop = !fSettings.alwaysOnTop; fSettings.alwaysOnTop = !fSettings.alwaysOnTop;
fBarWindow->SetFeel(fSettings.alwaysOnTop ? fBarWindow->SetFeel(fSettings.alwaysOnTop ?
B_FLOATING_ALL_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL); B_FLOATING_ALL_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL);
fPreferencesWindow->PostMessage(kStateChanged);
break; break;
case kAutoRaise: case kAutoRaise:
fSettings.autoRaise = !fSettings.autoRaise; fSettings.autoRaise = fSettings.alwaysOnTop ? false :
!fSettings.autoRaise;
fBarWindow->Lock(); fBarWindow->Lock();
BarView()->UpdateAutoRaise(); BarView()->UpdateEventMask();
fBarWindow->Unlock(); fBarWindow->Unlock();
break; break;
case kAutoHide:
fSettings.autoHide = !fSettings.autoHide;
fBarWindow->Lock();
BarView()->UpdateEventMask();
BarView()->HideDeskbar(fSettings.autoHide);
fBarWindow->Unlock();
break;
case kTrackerFirst: case kTrackerFirst:
fSettings.trackerAlwaysFirst = !fSettings.trackerAlwaysFirst; fSettings.trackerAlwaysFirst = !fSettings.trackerAlwaysFirst;
+2
View File
@@ -81,6 +81,7 @@ const uint32 kSortRunningApps = 'SAps';
const uint32 kSuperExpando = 'SprE'; const uint32 kSuperExpando = 'SprE';
const uint32 kExpandNewTeams = 'ExTm'; const uint32 kExpandNewTeams = 'ExTm';
const uint32 kAutoRaise = 'AtRs'; const uint32 kAutoRaise = 'AtRs';
const uint32 kAutoHide = 'AtHd';
const uint32 kRestartTracker = 'Trak'; const uint32 kRestartTracker = 'Trak';
// from roster_private.h // from roster_private.h
@@ -110,6 +111,7 @@ struct desk_settings {
bool superExpando; bool superExpando;
bool expandNewTeams; bool expandNewTeams;
bool autoRaise; bool autoRaise;
bool autoHide;
bool recentAppsEnabled; bool recentAppsEnabled;
bool recentDocsEnabled; bool recentDocsEnabled;
bool recentFoldersEnabled; bool recentFoldersEnabled;
+133 -29
View File
@@ -110,7 +110,7 @@ TBarView::AttachedToWindow()
SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
SetFont(be_plain_font); SetFont(be_plain_font);
UpdateAutoRaise(); UpdateEventMask();
UpdatePlacement(); UpdatePlacement();
fTrackingHookData.fTrackingHook = MenuTrackingHook; fTrackingHookData.fTrackingHook = MenuTrackingHook;
@@ -183,16 +183,79 @@ TBarView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
if (Window() == NULL || EventMask() == 0) if (Window() == NULL || EventMask() == 0)
return; 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); where = ConvertToScreen(where);
BScreen screen(Window()); BScreen screen(Window());
BRect frame = screen.Frame(); BRect screenFrame = screen.Frame();
if (where.x == frame.left || where.x == frame.right if ((where.x == screenFrame.left || where.x == screenFrame.right
|| where.y == frame.top || where.y == frame.bottom) { || where.y == screenFrame.top || where.y == screenFrame.bottom)
// cursor is on screen edge && Window()->Frame().Contains(where)) {
if (Window()->Frame().Contains(where)) // cursor is on a screen edge within the window frame
Window()->Activate();
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 windowHeight = 0;
float windowWidth = sMinimumWindowWidth; float windowWidth = sMinimumWindowWidth;
if (fState == kFullState) { bool calcHiddenSize = ((TBarApp*)be_app)->Settings()->autoHide
windowHeight = screenFrame.bottom; && IsHidden() && !DragRegion()->IsDragging();
windowWidth = fBarMenuBar->Frame().Width();
} else if (fState == kExpandoState) { if (!calcHiddenSize) {
if (fVertical) { if (fState == kFullState) {
// top left or right windowHeight = screenFrame.bottom;
windowHeight = fExpando->Frame().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 { } else {
// top or bottom, full // four corners
fExpando->CheckItemSizes(0); if (fTrayLocation != 0)
windowHeight = kHModeHeight; windowHeight = fDragRegion->Frame().bottom;
windowWidth = screenFrame.Width(); else
windowHeight = fBarMenuBar->Frame().bottom;
} }
} else { } else {
// four corners windowHeight = kHModeHiddenHeight;
if (fTrayLocation != 0)
windowHeight = fDragRegion->Frame().bottom; if (fState == kExpandoState && !fVertical) {
else // top or bottom, full
windowHeight = fBarMenuBar->Frame().bottom; fExpando->CheckItemSizes(0);
windowWidth = screenFrame.Width();
} else
windowWidth = kHModeHiddenHeight;
} }
*width = windowWidth; *width = windowWidth;
@@ -408,15 +485,14 @@ TBarView::SaveSettings()
settings->showTime = ShowingClock(); settings->showTime = ShowingClock();
fReplicantTray->RememberClockSettings(); fReplicantTray->RememberClockSettings();
settings->alwaysOnTop
= (Window()->Feel() & B_FLOATING_ALL_WINDOW_FEEL) != 0;
} }
void 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); SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
else else
SetEventMask(0); SetEventMask(0);
@@ -443,7 +519,7 @@ TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)
fTop = top; fTop = top;
// Send a message to the preferences window to let it know to enable // Send a message to the preferences window to let it know to enable
// or disabled preference items // or disable preference items
if (stateChanged || vertSwap) if (stateChanged || vertSwap)
be_app->PostMessage(kStateChanged); 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 // window placement functions
bool bool
+7 -2
View File
@@ -57,6 +57,8 @@ const float kMiniHeight = 46.0f;
const float kHModeHeight = 21.0f; const float kHModeHeight = 21.0f;
const float kMenuBarHeight = 21.0f; const float kMenuBarHeight = 21.0f;
const float kStatusHeight = 22.0f; const float kStatusHeight = 22.0f;
const float kHModeHiddenHeight = 1.0f;
const float kMaxPreventHidingDist = 80.0f;
class BShelf; class BShelf;
class TBarMenuBar; class TBarMenuBar;
@@ -78,11 +80,14 @@ class TBarView : public BView {
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void MouseMoved(BPoint where, uint32 transit, virtual void MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage); const BMessage* dragMessage);
virtual void MouseDown(BPoint where);
void SaveSettings(); void SaveSettings();
void UpdateAutoRaise(); void UpdateEventMask();
void UpdatePlacement(); void UpdatePlacement();
void ChangeState(int32 state, bool vertical, bool left, bool top); void ChangeState(int32 state, bool vertical, bool left, bool top);
void RaiseDeskbar(bool raise);
void HideDeskbar(bool hide);
bool Vertical() const; bool Vertical() const;
bool Left() const; bool Left() const;
@@ -136,7 +141,7 @@ class TBarView : public BView {
TExpandoMenuBar* ExpandoMenuBar() const; TExpandoMenuBar* ExpandoMenuBar() const;
TBarMenuBar* BarMenuBar() const; TBarMenuBar* BarMenuBar() const;
TDragRegion* DragRegion() const { return fDragRegion; } TDragRegion* DragRegion() const { return fDragRegion; }
private: private:
friend class TBeMenu; friend class TBeMenu;
friend class PreferencesWindow; friend class PreferencesWindow;
+1 -24
View File
@@ -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 void
TBarWindow::MenusBeginning() TBarWindow::MenusBeginning()
{ {
@@ -182,7 +159,7 @@ TBarWindow::MenusEnded()
sBeMenu->UnlockLooper(); sBeMenu->UnlockLooper();
} }
fBarView->UpdateAutoRaise(); fBarView->UpdateEventMask();
} }
-2
View File
@@ -54,8 +54,6 @@ public:
virtual void WorkspaceActivated(int32 workspace, virtual void WorkspaceActivated(int32 workspace,
bool activate); bool activate);
virtual void ScreenChanged(BRect size, color_space depth); virtual void ScreenChanged(BRect size, color_space depth);
virtual void DispatchMessage(BMessage* message,
BHandler* handler);
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void Minimize(bool minimize); virtual void Minimize(bool minimize);
+11 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009 Haiku, Inc. * Copyright 2009-2011 Haiku, Inc.
* All Rights Reserved. Distributed under the terms of the MIT License. * All Rights Reserved. Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -62,6 +62,8 @@ PreferencesWindow::PreferencesWindow(BRect frame)
new BMessage(kAlwaysTop)); new BMessage(kAlwaysTop));
fWindowAutoRaise = new BCheckBox(B_TRANSLATE("Auto-raise"), fWindowAutoRaise = new BCheckBox(B_TRANSLATE("Auto-raise"),
new BMessage(kAutoRaise)); new BMessage(kAutoRaise));
fWindowAutoHide = new BCheckBox(B_TRANSLATE("Auto-hide"),
new BMessage(kAutoHide));
BTextView* docTextView = fMenuRecentDocumentCount->TextView(); BTextView* docTextView = fMenuRecentDocumentCount->TextView();
BTextView* appTextView = fMenuRecentApplicationCount->TextView(); BTextView* appTextView = fMenuRecentApplicationCount->TextView();
@@ -122,6 +124,7 @@ PreferencesWindow::PreferencesWindow(BRect frame)
fWindowAlwaysOnTop->SetValue(appSettings->alwaysOnTop); fWindowAlwaysOnTop->SetValue(appSettings->alwaysOnTop);
fWindowAutoRaise->SetValue(appSettings->autoRaise); fWindowAutoRaise->SetValue(appSettings->autoRaise);
fWindowAutoHide->SetValue(appSettings->autoHide);
_EnableDisableDependentItems(); _EnableDisableDependentItems();
@@ -134,6 +137,7 @@ PreferencesWindow::PreferencesWindow(BRect frame)
fWindowAlwaysOnTop->SetTarget(be_app); fWindowAlwaysOnTop->SetTarget(be_app);
fWindowAutoRaise->SetTarget(be_app); fWindowAutoRaise->SetTarget(be_app);
fWindowAutoHide->SetTarget(be_app);
// Layout // Layout
fMenuBox = new BBox("fMenuBox"); fMenuBox = new BBox("fMenuBox");
@@ -196,6 +200,7 @@ PreferencesWindow::PreferencesWindow(BRect frame)
.AddGroup(B_VERTICAL, 1) .AddGroup(B_VERTICAL, 1)
.Add(fWindowAlwaysOnTop) .Add(fWindowAlwaysOnTop)
.Add(fWindowAutoRaise) .Add(fWindowAutoRaise)
.Add(fWindowAutoHide)
.AddGlue() .AddGlue()
.SetInsets(10, 10, 10, 10) .SetInsets(10, 10, 10, 10)
.End() .End()
@@ -301,6 +306,11 @@ PreferencesWindow::_EnableDisableDependentItems()
fMenuRecentFolderCount->SetEnabled(true); fMenuRecentFolderCount->SetEnabled(true);
else else
fMenuRecentFolderCount->SetEnabled(false); 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()) if (!active && IsMinimized())
PostMessage(B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
} }
+1
View File
@@ -57,6 +57,7 @@ private:
BCheckBox* fWindowAlwaysOnTop; BCheckBox* fWindowAlwaysOnTop;
BCheckBox* fWindowAutoRaise; BCheckBox* fWindowAutoRaise;
BCheckBox* fWindowAutoHide;
}; };
#endif // _PREFERENCES_WINDOW_H #endif // _PREFERENCES_WINDOW_H
+2
View File
@@ -197,6 +197,8 @@ public:
int32 DragRegionLocation() const; int32 DragRegionLocation() const;
void SetDragRegionLocation(int32); void SetDragRegionLocation(int32);
bool IsDragging() {return IsTracking();}
private: private:
TBarView* fBarView; TBarView* fBarView;