Ticket #4880: DesbarAutoHideFeature.2.diff

File DesbarAutoHideFeature.2.diff, 12.1 KB (added by x-ist, 13 years ago)
  • BarWindow.h

     
    5454    virtual void                WorkspaceActivated(int32 workspace,
    5555                                    bool activate);
    5656    virtual void                ScreenChanged(BRect size, color_space depth);
    57     virtual void                DispatchMessage(BMessage* message,
    58                                     BHandler* handler);
    5957    virtual void                MessageReceived(BMessage* message);
    6058    virtual void                Minimize(bool minimize);
    6159
  • BarView.h

     
    5858const float kMenuBarHeight = 21.0f;
    5959const float kStatusHeight = 22.0f;
    6060
     61const float kHModeHiddenHeight = 1.0f;
     62const float kMaxPreventHidingDist = 80.0f;
     63
    6164class BShelf;
    6265class TBarMenuBar;
    6366class TExpandoMenuBar;
     
    7881        virtual void MessageReceived(BMessage* message);
    7982        virtual void MouseMoved(BPoint where, uint32 transit,
    8083            const BMessage* dragMessage);
     84        virtual void MouseDown(BPoint where);
    8185
    8286        void SaveSettings();
    83         void UpdateAutoRaise();
     87        void UpdateEventMask();
    8488        void UpdatePlacement();
    8589        void ChangeState(int32 state, bool vertical, bool left, bool top);
     90        void RaiseDeskbar(bool raise);
     91        void HideDeskbar(bool hide);
    8692
    8793        bool Vertical() const;
    8894        bool Left() const;
     
    136142        TExpandoMenuBar* ExpandoMenuBar() const;
    137143        TBarMenuBar* BarMenuBar() const;
    138144        TDragRegion* DragRegion() const { return fDragRegion; }
    139 
     145           
    140146    private:
    141147        friend class TBeMenu;
    142148        friend class PreferencesWindow;
  • BarApp.h

     
    8181const uint32 kSuperExpando = 'SprE';
    8282const uint32 kExpandNewTeams = 'ExTm';
    8383const uint32 kAutoRaise = 'AtRs';
     84const uint32 kAutoHide = 'AtHd';
    8485const uint32 kRestartTracker = 'Trak';
    8586
    8687// from roster_private.h
     
    110111    bool superExpando;
    111112    bool expandNewTeams;
    112113    bool autoRaise;
     114    bool autoHide;
    113115    bool recentAppsEnabled;
    114116    bool recentDocsEnabled;
    115117    bool recentFoldersEnabled;
  • BarWindow.cpp

     
    106106
    107107
    108108void
    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_KEY
    119                     | B_SHIFT_KEY)) == (B_CONTROL_KEY | B_COMMAND_KEY)) {
    120             // The window key was pressed - enter dragging code
    121             fBarView->DragRegion()->MouseDown(
    122                 fBarView->DragRegion()->DragRegion().LeftTop());
    123             return;
    124         }
    125     }
    126 
    127     BWindow::DispatchMessage(message, handler);
    128 }
    129 
    130 
    131 void
    132109TBarWindow::MenusBeginning()
    133110{
    134111    BPath path;
     
    182159        sBeMenu->UnlockLooper();
    183160    }
    184161
    185     fBarView->UpdateAutoRaise();
     162    fBarView->UpdateEventMask();
    186163}
    187164
    188165
  • PreferencesWindow.h

     
    5757
    5858            BCheckBox*      fWindowAlwaysOnTop;
    5959            BCheckBox*      fWindowAutoRaise;
     60            BCheckBox*      fWindowAutoHide;
    6061};
    6162
    6263#endif  // _PREFERENCES_WINDOW_H
  • BarView.cpp

     
    110110    SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
    111111    SetFont(be_plain_font);
    112112
    113     UpdateAutoRaise();
     113    UpdateEventMask();
    114114    UpdatePlacement();
    115115
    116116    fTrackingHookData.fTrackingHook = MenuTrackingHook;
     
    182182{
    183183    if (Window() == NULL || EventMask() == 0)
    184184        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    }
    185197
     198    bool isTopMost = Window()->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
     199    bool isHidden = IsHidden();
     200   
    186201    // Auto-Raise
    187 
    188202    where = ConvertToScreen(where);
    189203    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 (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 (autoRaise && isTopMost) {
     227            RaiseDeskbar(false);
     228        }
     229       
     230        if (autoHide && !isHidden) {
     231            HideDeskbar(true);
     232        }
    196233    }
    197234}
    198235
    199236
    200237void
     238TBarView::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        bool autoRaise = ((TBarApp*)be_app)->Settings()->autoRaise;
     255        bool autoHide = ((TBarApp*)be_app)->Settings()->autoHide;
     256        bool isTopMost = Window()->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
     257        bool isHidden = IsHidden();     
     258       
     259        if (autoRaise && isTopMost) {
     260            RaiseDeskbar(false);
     261        }
     262       
     263        if (autoHide && !isHidden) {
     264            HideDeskbar(true);
     265        }
     266    }
     267}
     268
     269
     270void
    201271TBarView::PlaceBeMenu()
    202272{
    203273    // top or bottom, full
     
    334404{
    335405    float windowHeight = 0;
    336406    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;
     407    bool calcHiddenSize = ((TBarApp*)be_app)->Settings()->autoHide
     408                                && IsHidden() && !DragRegion()->IsDragging();
     409   
     410    if (!calcHiddenSize)
     411    {
     412        if (fState == kFullState) {
     413            windowHeight = screenFrame.bottom;
     414            windowWidth = fBarMenuBar->Frame().Width();
     415        } else if (fState == kExpandoState) {
     416            if (fVertical) {
     417                // top left or right
     418                windowHeight = fExpando->Frame().bottom;
     419            } else {
     420                // top or bottom, full
     421                fExpando->CheckItemSizes(0);
     422                windowHeight = kHModeHeight;   
     423                windowWidth = screenFrame.Width();
     424            }
    344425        } else {
     426            // four corners
     427            if (fTrayLocation != 0)
     428                windowHeight = fDragRegion->Frame().bottom;
     429            else
     430                windowHeight = fBarMenuBar->Frame().bottom;
     431        }
     432    } else {
     433        windowHeight = kHModeHiddenHeight;
     434       
     435        if (fState == kExpandoState && !fVertical) {
    345436            // top or bottom, full
    346437            fExpando->CheckItemSizes(0);
    347             windowHeight = kHModeHeight;
    348438            windowWidth = screenFrame.Width();
     439        } else {
     440            windowWidth = kHModeHiddenHeight;
    349441        }
    350     } else {
    351         // four corners
    352         if (fTrayLocation != 0)
    353             windowHeight = fDragRegion->Frame().bottom;
    354         else
    355             windowHeight = fBarMenuBar->Frame().bottom;
    356442    }
    357 
     443   
    358444    *width = windowWidth;
    359445    *height = windowHeight;
    360446}
     
    414500
    415501
    416502void
    417 TBarView::UpdateAutoRaise()
     503TBarView::UpdateEventMask()
    418504{
    419     if (((TBarApp*)be_app)->Settings()->autoRaise)
     505    if (((TBarApp*)be_app)->Settings()->autoRaise ||
     506        ((TBarApp*)be_app)->Settings()->autoHide)
    420507        SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
    421508    else
    422509        SetEventMask(0);
     
    443530    fTop = top;
    444531
    445532    // Send a message to the preferences window to let it know to enable
    446     // or disabled preference items
     533    // or disable preference items
    447534    if (stateChanged || vertSwap)
    448535        be_app->PostMessage(kStateChanged);
    449536
     
    507594}
    508595
    509596
     597void
     598TBarView::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
     606void
     607TBarView::HideDeskbar(bool hide)
     608{
     609    BScreen screen(Window());
     610    BRect screenFrame = screen.Frame();
     611   
     612    if (hide) {
     613        Hide();
     614        PositionWindow(screenFrame);
     615        SizeWindow(screenFrame);
     616    } else {
     617        Show();
     618        SizeWindow(screenFrame);
     619        PositionWindow(screenFrame);
     620    }
     621}
     622
     623
    510624// window placement functions
    511625
    512626bool
  • BarApp.cpp

     
    206206        storedSettings.AddBool("superExpando", fSettings.superExpando);
    207207        storedSettings.AddBool("expandNewTeams", fSettings.expandNewTeams);
    208208        storedSettings.AddBool("autoRaise", fSettings.autoRaise);
     209        storedSettings.AddBool("autoHide", fSettings.autoHide);
    209210        storedSettings.AddBool("recentAppsEnabled",
    210211            fSettings.recentAppsEnabled);
    211212        storedSettings.AddBool("recentDocsEnabled",
     
    241242    settings.superExpando = false;
    242243    settings.expandNewTeams = false;
    243244    settings.autoRaise = false;
     245    settings.autoHide = false;
    244246    settings.recentAppsEnabled = true;
    245247    settings.recentDocsEnabled = true;
    246248    settings.recentFoldersEnabled = true;
     
    290292            storedSettings.FindBool("superExpando", &settings.superExpando);
    291293            storedSettings.FindBool("expandNewTeams", &settings.expandNewTeams);
    292294            storedSettings.FindBool("autoRaise", &settings.autoRaise);
     295            storedSettings.FindBool("autoHide", &settings.autoHide);
    293296            storedSettings.FindBool("recentAppsEnabled",
    294297                &settings.recentAppsEnabled);
    295298            storedSettings.FindBool("recentDocsEnabled",
     
    417420            fSettings.autoRaise = !fSettings.autoRaise;
    418421
    419422            fBarWindow->Lock();
    420             BarView()->UpdateAutoRaise();
     423            BarView()->UpdateEventMask();
    421424            fBarWindow->Unlock();
    422425            break;
    423426
     427        case kAutoHide:
     428            fSettings.autoHide = !fSettings.autoHide;
     429
     430            fBarWindow->Lock();
     431            BarView()->UpdateEventMask();
     432            BarView()->HideDeskbar(fSettings.autoHide);
     433            fBarWindow->Unlock();
     434            break;
     435           
    424436        case kTrackerFirst:
    425437            fSettings.trackerAlwaysFirst = !fSettings.trackerAlwaysFirst;
    426438
  • StatusView.h

     
    197197
    198198    int32 DragRegionLocation() const;
    199199    void SetDragRegionLocation(int32);
     200   
     201    bool IsDragging() {return IsTracking();}
    200202
    201203private:
    202204    TBarView* fBarView;
  • PreferencesWindow.cpp

     
    6262        new BMessage(kAlwaysTop));
    6363    fWindowAutoRaise = new BCheckBox(B_TRANSLATE("Auto-raise"),
    6464        new BMessage(kAutoRaise));
     65    fWindowAutoHide = new BCheckBox(B_TRANSLATE("Auto-hide"),
     66        new BMessage(kAutoHide));
    6567
    6668    BTextView* docTextView = fMenuRecentDocumentCount->TextView();
    6769    BTextView* appTextView = fMenuRecentApplicationCount->TextView();
     
    122124
    123125    fWindowAlwaysOnTop->SetValue(appSettings->alwaysOnTop);
    124126    fWindowAutoRaise->SetValue(appSettings->autoRaise);
     127    fWindowAutoHide->SetValue(appSettings->autoHide);
    125128
    126129    _EnableDisableDependentItems();
    127130
     
    134137
    135138    fWindowAlwaysOnTop->SetTarget(be_app);
    136139    fWindowAutoRaise->SetTarget(be_app);
     140    fWindowAutoHide->SetTarget(be_app);
    137141
    138142    // Layout
    139143    fMenuBox = new BBox("fMenuBox");
     
    196200        .AddGroup(B_VERTICAL, 1)
    197201            .Add(fWindowAlwaysOnTop)
    198202            .Add(fWindowAutoRaise)
     203            .Add(fWindowAutoHide)
    199204            .AddGlue()
    200205            .SetInsets(10, 10, 10, 10)
    201206            .End()
     
    310315    if (!active && IsMinimized())
    311316        PostMessage(B_QUIT_REQUESTED);
    312317}
    313