Ticket #4880: DeskBarAutoHideFeature.diff
File DeskBarAutoHideFeature.diff, 13.4 KB (added by , 13 years ago) |
---|
-
BarWindow.h
54 54 virtual void WorkspaceActivated(int32 workspace, 55 55 bool activate); 56 56 virtual void ScreenChanged(BRect size, color_space depth); 57 virtual void DispatchMessage(BMessage* message,58 BHandler* handler);59 57 virtual void MessageReceived(BMessage* message); 60 58 virtual void Minimize(bool minimize); 61 59 -
BarView.h
57 57 const float kHModeHeight = 21.0f; 58 58 const float kMenuBarHeight = 21.0f; 59 59 const float kStatusHeight = 22.0f; 60 const float kHModeHiddenHeight = 1.0f; 61 const float kMaxPreventHidingDist = 80.0f; 60 62 61 63 class BShelf; 62 64 class TBarMenuBar; … … 78 80 virtual void MessageReceived(BMessage* message); 79 81 virtual void MouseMoved(BPoint where, uint32 transit, 80 82 const BMessage* dragMessage); 83 virtual void MouseDown(BPoint where); 81 84 82 85 void SaveSettings(); 83 void Update AutoRaise();86 void UpdateEventMask(); 84 87 void UpdatePlacement(); 85 88 void ChangeState(int32 state, bool vertical, bool left, bool top); 89 void RaiseDeskbar(bool raise); 90 void HideDeskbar(bool hide); 86 91 87 92 bool Vertical() const; 88 93 bool Left() const; … … 136 141 TExpandoMenuBar* ExpandoMenuBar() const; 137 142 TBarMenuBar* BarMenuBar() const; 138 143 TDragRegion* DragRegion() const { return fDragRegion; } 139 144 140 145 private: 141 146 friend class TBeMenu; 142 147 friend class PreferencesWindow; -
BarApp.h
81 81 const uint32 kSuperExpando = 'SprE'; 82 82 const uint32 kExpandNewTeams = 'ExTm'; 83 83 const uint32 kAutoRaise = 'AtRs'; 84 const uint32 kAutoHide = 'AtHd'; 84 85 const uint32 kRestartTracker = 'Trak'; 85 86 86 87 // from roster_private.h … … 110 111 bool superExpando; 111 112 bool expandNewTeams; 112 113 bool autoRaise; 114 bool autoHide; 113 115 bool recentAppsEnabled; 114 116 bool recentDocsEnabled; 115 117 bool recentFoldersEnabled; -
BarWindow.cpp
89 89 B_TRANSLATE_SYSTEM_NAME("Deskbar"), B_BORDERED_WINDOW, 90 90 B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_CLOSABLE 91 91 | B_NOT_MINIMIZABLE | B_NOT_MOVABLE | B_NOT_RESIZABLE 92 | B_A VOID_FRONT | B_ASYNCHRONOUS_CONTROLS,92 | B_ASYNCHRONOUS_CONTROLS, 93 93 B_ALL_WORKSPACES) 94 94 { 95 95 desk_settings* settings = ((TBarApp*)be_app)->Settings(); … … 106 106 107 107 108 108 void 109 TBarWindow::DispatchMessage(BMessage* message, BHandler* handler)110 {111 // Activate the window when you click on it (ie. on the tray area,112 // the menu part will do this automatically)113 if (message->what == B_MOUSE_DOWN) {114 if (!((TBarApp*)be_app)->Settings()->autoRaise)115 Activate(true);116 117 if (_IsFocusMessage(message)118 && (modifiers() & (B_CONTROL_KEY | B_COMMAND_KEY | B_OPTION_KEY119 | B_SHIFT_KEY)) == (B_CONTROL_KEY | B_COMMAND_KEY)) {120 // The window key was pressed - enter dragging code121 fBarView->DragRegion()->MouseDown(122 fBarView->DragRegion()->DragRegion().LeftTop());123 return;124 }125 }126 127 BWindow::DispatchMessage(message, handler);128 }129 130 131 void132 109 TBarWindow::MenusBeginning() 133 110 { 134 111 BPath path; … … 182 159 sBeMenu->UnlockLooper(); 183 160 } 184 161 185 fBarView->Update AutoRaise();162 fBarView->UpdateEventMask(); 186 163 } 187 164 188 165 -
PreferencesWindow.h
57 57 58 58 BCheckBox* fWindowAlwaysOnTop; 59 59 BCheckBox* fWindowAutoRaise; 60 BCheckBox* fWindowAutoHide; 60 61 }; 61 62 62 63 #endif // _PREFERENCES_WINDOW_H -
BarView.cpp
110 110 SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); 111 111 SetFont(be_plain_font); 112 112 113 Update AutoRaise();113 UpdateEventMask(); 114 114 UpdatePlacement(); 115 115 116 116 fTrackingHookData.fTrackingHook = MenuTrackingHook; … … 182 182 { 183 183 if (Window() == NULL || EventMask() == 0) 184 184 return; 185 186 desk_settings* settings = ((TBarApp*)be_app)->Settings(); 187 bool alwaysOnTop = settings->alwaysOnTop; 188 bool autoRaise = settings->autoRaise; 189 bool autoHide = settings->autoHide; 190 191 if (!autoRaise && !autoHide) 192 return; 193 194 if (DragRegion()->IsDragging()) { 195 return; 196 } 185 197 198 bool isTopMost = Window()->Feel() == B_FLOATING_ALL_WINDOW_FEEL; 199 bool isHidden = IsHidden(); 200 186 201 // Auto-Raise 187 188 202 where = ConvertToScreen(where); 189 203 BScreen screen(Window()); 190 BRect frame = screen.Frame(); 191 if (where.x == frame.left || where.x == frame.right 192 || where.y == frame.top || where.y == frame.bottom) { 193 // cursor is on screen edge 194 if (Window()->Frame().Contains(where)) 195 Window()->Activate(); 204 BRect screenFrame = screen.Frame(); 205 if ((where.x == screenFrame.left || where.x == screenFrame.right 206 || where.y == screenFrame.top || where.y == screenFrame.bottom) 207 && Window()->Frame().Contains(where)) { 208 // cursor is on a screen edge within the window frame 209 210 if (!alwaysOnTop && autoRaise && !isTopMost) { 211 RaiseDeskbar(true); 212 } 213 214 if (autoHide && isHidden) { 215 HideDeskbar(false); 216 } 217 } else { 218 // cursor is not on screen edge 219 BRect preventHideArea = Window()->Frame().InsetByCopy( 220 -kMaxPreventHidingDist, -kMaxPreventHidingDist); 221 222 if (preventHideArea.Contains(where)) 223 return; 224 225 // cursor to bar distance above threshold 226 if (!alwaysOnTop && autoRaise && isTopMost) { 227 RaiseDeskbar(false); 228 } 229 230 if (autoHide && !isHidden) { 231 HideDeskbar(true); 232 } 196 233 } 197 234 } 198 235 199 236 200 237 void 238 TBarView::MouseDown(BPoint where) 239 { 240 where = ConvertToScreen(where); 241 242 if (Window()->Frame().Contains(where)) { 243 Window()->Activate(); 244 245 if ((modifiers() & (B_CONTROL_KEY | B_COMMAND_KEY | B_OPTION_KEY 246 | B_SHIFT_KEY)) == (B_CONTROL_KEY | B_COMMAND_KEY)) { 247 // The window key was pressed - enter dragging code 248 DragRegion()->MouseDown( 249 DragRegion()->DragRegion().LeftTop()); 250 return; 251 } 252 } else { 253 // hide deskbar if required 254 desk_settings* settings = ((TBarApp*)be_app)->Settings(); 255 bool alwaysOnTop = settings->alwaysOnTop; 256 bool autoRaise = settings->autoRaise; 257 bool autoHide = settings->autoHide; 258 bool isTopMost = Window()->Feel() == B_FLOATING_ALL_WINDOW_FEEL; 259 bool isHidden = IsHidden(); 260 261 if (!alwaysOnTop && autoRaise && isTopMost) { 262 RaiseDeskbar(false); 263 } 264 265 if (autoHide && !isHidden) { 266 HideDeskbar(true); 267 } 268 } 269 } 270 271 272 void 201 273 TBarView::PlaceBeMenu() 202 274 { 203 275 // top or bottom, full … … 334 406 { 335 407 float windowHeight = 0; 336 408 float windowWidth = sMinimumWindowWidth; 337 if (fState == kFullState) { 338 windowHeight = screenFrame.bottom; 339 windowWidth = fBarMenuBar->Frame().Width(); 340 } else if (fState == kExpandoState) { 341 if (fVertical) { 342 // top left or right 343 windowHeight = fExpando->Frame().bottom; 409 bool calcHiddenSize = ((TBarApp*)be_app)->Settings()->autoHide 410 && IsHidden() && !DragRegion()->IsDragging(); 411 412 if (!calcHiddenSize) 413 { 414 if (fState == kFullState) { 415 windowHeight = screenFrame.bottom; 416 windowWidth = fBarMenuBar->Frame().Width(); 417 } else if (fState == kExpandoState) { 418 if (fVertical) { 419 // top left or right 420 windowHeight = fExpando->Frame().bottom; 421 } else { 422 // top or bottom, full 423 fExpando->CheckItemSizes(0); 424 windowHeight = kHModeHeight; 425 windowWidth = screenFrame.Width(); 426 } 344 427 } else { 428 // four corners 429 if (fTrayLocation != 0) 430 windowHeight = fDragRegion->Frame().bottom; 431 else 432 windowHeight = fBarMenuBar->Frame().bottom; 433 } 434 } else { 435 windowHeight = kHModeHiddenHeight; 436 437 if (fState == kExpandoState && !fVertical) { 345 438 // top or bottom, full 346 439 fExpando->CheckItemSizes(0); 347 windowHeight = kHModeHeight;348 440 windowWidth = screenFrame.Width(); 441 } else { 442 windowWidth = kHModeHiddenHeight; 349 443 } 350 } else {351 // four corners352 if (fTrayLocation != 0)353 windowHeight = fDragRegion->Frame().bottom;354 else355 windowHeight = fBarMenuBar->Frame().bottom;356 444 } 357 445 358 446 *width = windowWidth; 359 447 *height = windowHeight; 360 448 } … … 408 496 settings->showTime = ShowingClock(); 409 497 410 498 fReplicantTray->RememberClockSettings(); 411 settings->alwaysOnTop412 = (Window()->Feel() & B_FLOATING_ALL_WINDOW_FEEL) != 0;413 499 } 414 500 415 501 416 502 void 417 TBarView::Update AutoRaise()503 TBarView::UpdateEventMask() 418 504 { 419 if (((TBarApp*)be_app)->Settings()->autoRaise) 505 if (((TBarApp*)be_app)->Settings()->autoRaise 506 || ((TBarApp*)be_app)->Settings()->autoHide) 420 507 SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY); 421 508 else 422 509 SetEventMask(0); … … 443 530 fTop = top; 444 531 445 532 // Send a message to the preferences window to let it know to enable 446 // or disable dpreference items533 // or disable preference items 447 534 if (stateChanged || vertSwap) 448 535 be_app->PostMessage(kStateChanged); 449 536 … … 507 594 } 508 595 509 596 597 void 598 TBarView::RaiseDeskbar(bool raise) 599 { 600 if (raise) 601 Window()->SetFeel(B_FLOATING_ALL_WINDOW_FEEL); 602 else 603 Window()->SetFeel(B_NORMAL_WINDOW_FEEL); 604 } 605 606 607 void 608 TBarView::HideDeskbar(bool hide) 609 { 610 BScreen screen(Window()); 611 BRect screenFrame = screen.Frame(); 612 613 if (hide) { 614 Hide(); 615 PositionWindow(screenFrame); 616 SizeWindow(screenFrame); 617 } else { 618 Show(); 619 SizeWindow(screenFrame); 620 PositionWindow(screenFrame); 621 } 622 } 623 624 510 625 // window placement functions 511 626 512 627 bool -
BarApp.cpp
206 206 storedSettings.AddBool("superExpando", fSettings.superExpando); 207 207 storedSettings.AddBool("expandNewTeams", fSettings.expandNewTeams); 208 208 storedSettings.AddBool("autoRaise", fSettings.autoRaise); 209 storedSettings.AddBool("autoHide", fSettings.autoHide); 209 210 storedSettings.AddBool("recentAppsEnabled", 210 211 fSettings.recentAppsEnabled); 211 212 storedSettings.AddBool("recentDocsEnabled", … … 241 242 settings.superExpando = false; 242 243 settings.expandNewTeams = false; 243 244 settings.autoRaise = false; 245 settings.autoHide = false; 244 246 settings.recentAppsEnabled = true; 245 247 settings.recentDocsEnabled = true; 246 248 settings.recentFoldersEnabled = true; … … 290 292 storedSettings.FindBool("superExpando", &settings.superExpando); 291 293 storedSettings.FindBool("expandNewTeams", &settings.expandNewTeams); 292 294 storedSettings.FindBool("autoRaise", &settings.autoRaise); 295 storedSettings.FindBool("autoHide", &settings.autoHide); 293 296 storedSettings.FindBool("recentAppsEnabled", 294 297 &settings.recentAppsEnabled); 295 298 storedSettings.FindBool("recentDocsEnabled", … … 408 411 409 412 case kAlwaysTop: 410 413 fSettings.alwaysOnTop = !fSettings.alwaysOnTop; 411 412 414 fBarWindow->SetFeel(fSettings.alwaysOnTop ? 413 415 B_FLOATING_ALL_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL); 416 fPreferencesWindow->PostMessage(kStateChanged); 414 417 break; 415 418 416 419 case kAutoRaise: 417 fSettings.autoRaise = !fSettings.autoRaise; 420 if (fSettings.alwaysOnTop) 421 fSettings.autoRaise = false; 422 else 423 fSettings.autoRaise = !fSettings.autoRaise; 418 424 419 425 fBarWindow->Lock(); 420 BarView()->Update AutoRaise();426 BarView()->UpdateEventMask(); 421 427 fBarWindow->Unlock(); 422 428 break; 423 429 430 case kAutoHide: 431 fSettings.autoHide = !fSettings.autoHide; 432 433 fBarWindow->Lock(); 434 BarView()->UpdateEventMask(); 435 BarView()->HideDeskbar(fSettings.autoHide); 436 fBarWindow->Unlock(); 437 break; 438 424 439 case kTrackerFirst: 425 440 fSettings.trackerAlwaysFirst = !fSettings.trackerAlwaysFirst; 426 441 -
StatusView.h
197 197 198 198 int32 DragRegionLocation() const; 199 199 void SetDragRegionLocation(int32); 200 201 bool IsDragging() {return IsTracking();} 200 202 201 203 private: 202 204 TBarView* fBarView; -
PreferencesWindow.cpp
62 62 new BMessage(kAlwaysTop)); 63 63 fWindowAutoRaise = new BCheckBox(B_TRANSLATE("Auto-raise"), 64 64 new BMessage(kAutoRaise)); 65 fWindowAutoHide = new BCheckBox(B_TRANSLATE("Auto-hide"), 66 new BMessage(kAutoHide)); 65 67 66 68 BTextView* docTextView = fMenuRecentDocumentCount->TextView(); 67 69 BTextView* appTextView = fMenuRecentApplicationCount->TextView(); … … 122 124 123 125 fWindowAlwaysOnTop->SetValue(appSettings->alwaysOnTop); 124 126 fWindowAutoRaise->SetValue(appSettings->autoRaise); 127 fWindowAutoHide->SetValue(appSettings->autoHide); 125 128 126 129 _EnableDisableDependentItems(); 127 130 … … 134 137 135 138 fWindowAlwaysOnTop->SetTarget(be_app); 136 139 fWindowAutoRaise->SetTarget(be_app); 140 fWindowAutoHide->SetTarget(be_app); 137 141 138 142 // Layout 139 143 fMenuBox = new BBox("fMenuBox"); … … 196 200 .AddGroup(B_VERTICAL, 1) 197 201 .Add(fWindowAlwaysOnTop) 198 202 .Add(fWindowAutoRaise) 203 .Add(fWindowAutoHide) 199 204 .AddGlue() 200 205 .SetInsets(10, 10, 10, 10) 201 206 .End() … … 301 306 fMenuRecentFolderCount->SetEnabled(true); 302 307 else 303 308 fMenuRecentFolderCount->SetEnabled(false); 309 310 if (fWindowAlwaysOnTop->Value() == B_CONTROL_ON) 311 fWindowAutoRaise->SetEnabled(false); 312 else 313 fWindowAutoRaise->SetEnabled(true); 304 314 } 305 315 306 316 … … 310 320 if (!active && IsMinimized()) 311 321 PostMessage(B_QUIT_REQUESTED); 312 322 } 313