Ticket #4880: DeskbarAutoHideFeature.diff

File DeskbarAutoHideFeature.diff, 13.3 KB (added by x-ist, 13 years ago)

Style cleanup and readded B_AVOID_FRONT flag to TBarWindow again.

  • src/apps/deskbar/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
  • src/apps/deskbar/BarView.h

     
    5757const float kHModeHeight = 21.0f;
    5858const float kMenuBarHeight = 21.0f;
    5959const float kStatusHeight = 22.0f;
     60const float kHModeHiddenHeight = 1.0f;
     61const float kMaxPreventHidingDist = 80.0f;
    6062
    6163class BShelf;
    6264class TBarMenuBar;
     
    7880        virtual void MessageReceived(BMessage* message);
    7981        virtual void MouseMoved(BPoint where, uint32 transit,
    8082            const BMessage* dragMessage);
     83        virtual void MouseDown(BPoint where);
    8184
    8285        void SaveSettings();
    83         void UpdateAutoRaise();
     86        void UpdateEventMask();
    8487        void UpdatePlacement();
    8588        void ChangeState(int32 state, bool vertical, bool left, bool top);
     89        void RaiseDeskbar(bool raise);
     90        void HideDeskbar(bool hide);
    8691
    8792        bool Vertical() const;
    8893        bool Left() const;
     
    136141        TExpandoMenuBar* ExpandoMenuBar() const;
    137142        TBarMenuBar* BarMenuBar() const;
    138143        TDragRegion* DragRegion() const { return fDragRegion; }
    139 
     144           
    140145    private:
    141146        friend class TBeMenu;
    142147        friend class PreferencesWindow;
  • src/apps/deskbar/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;
  • src/apps/deskbar/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
  • src/apps/deskbar/PreferencesWindow.h

     
    5757
    5858            BCheckBox*      fWindowAlwaysOnTop;
    5959            BCheckBox*      fWindowAutoRaise;
     60            BCheckBox*      fWindowAutoHide;
    6061};
    6162
    6263#endif  // _PREFERENCES_WINDOW_H
  • src/apps/deskbar/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;
    185196
     197    bool isTopMost = Window()->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
     198   
    186199    // Auto-Raise
    187 
    188200    where = ConvertToScreen(where);
    189201    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();
     202    BRect screenFrame = screen.Frame();
     203    if ((where.x == screenFrame.left || where.x == screenFrame.right
     204        || where.y == screenFrame.top || where.y == screenFrame.bottom)
     205            && Window()->Frame().Contains(where)) {
     206            // cursor is on a screen edge within the window frame
     207
     208        if (!alwaysOnTop && autoRaise && !isTopMost)
     209            RaiseDeskbar(true);
     210       
     211        if (autoHide && IsHidden())
     212            HideDeskbar(false);
     213    } else {
     214        // cursor is not on screen edge
     215        BRect preventHideArea = Window()->Frame().InsetByCopy(
     216            -kMaxPreventHidingDist, -kMaxPreventHidingDist);
     217
     218        if (preventHideArea.Contains(where))
     219            return;
     220           
     221        // cursor to bar distance above threshold
     222        if (!alwaysOnTop && autoRaise && isTopMost)
     223            RaiseDeskbar(false);
     224       
     225        if (autoHide && !IsHidden())
     226            HideDeskbar(true);
    196227    }
    197228}
    198229
    199230
    200231void
     232TBarView::MouseDown(BPoint where)
     233{
     234    where = ConvertToScreen(where);
     235
     236    if (Window()->Frame().Contains(where)) {
     237        Window()->Activate();
     238
     239        if ((modifiers() & (B_CONTROL_KEY | B_COMMAND_KEY | B_OPTION_KEY
     240                    | B_SHIFT_KEY)) == (B_CONTROL_KEY | B_COMMAND_KEY)) {
     241            // The window key was pressed - enter dragging code
     242            DragRegion()->MouseDown(
     243                DragRegion()->DragRegion().LeftTop());
     244            return;
     245        }
     246    } else {
     247        // hide deskbar if required
     248        desk_settings* settings = ((TBarApp*)be_app)->Settings();
     249        bool alwaysOnTop = settings->alwaysOnTop;
     250        bool autoRaise = settings->autoRaise;
     251        bool autoHide = settings->autoHide;
     252        bool isTopMost = Window()->Feel() == B_FLOATING_ALL_WINDOW_FEEL;       
     253       
     254        if (!alwaysOnTop && autoRaise && isTopMost)
     255            RaiseDeskbar(false);
     256       
     257        if (autoHide && !IsHidden())
     258            HideDeskbar(true);
     259    }
     260}
     261
     262
     263void
    201264TBarView::PlaceBeMenu()
    202265{
    203266    // top or bottom, full
     
    334397{
    335398    float windowHeight = 0;
    336399    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;
     400    bool calcHiddenSize = ((TBarApp*)be_app)->Settings()->autoHide
     401                                && IsHidden() && !DragRegion()->IsDragging();
     402   
     403    if (!calcHiddenSize)
     404    {
     405        if (fState == kFullState) {
     406            windowHeight = screenFrame.bottom;
     407            windowWidth = fBarMenuBar->Frame().Width();
     408        } else if (fState == kExpandoState) {
     409            if (fVertical)
     410                // top left or right
     411                windowHeight = fExpando->Frame().bottom;
     412            else {
     413                // top or bottom, full
     414                fExpando->CheckItemSizes(0);
     415                windowHeight = kHModeHeight;   
     416                windowWidth = screenFrame.Width();
     417            }
    344418        } else {
     419            // four corners
     420            if (fTrayLocation != 0)
     421                windowHeight = fDragRegion->Frame().bottom;
     422            else
     423                windowHeight = fBarMenuBar->Frame().bottom;
     424        }
     425    } else {
     426        windowHeight = kHModeHiddenHeight;
     427       
     428        if (fState == kExpandoState && !fVertical) {
    345429            // top or bottom, full
    346430            fExpando->CheckItemSizes(0);
    347             windowHeight = kHModeHeight;
    348431            windowWidth = screenFrame.Width();
    349         }
    350     } else {
    351         // four corners
    352         if (fTrayLocation != 0)
    353             windowHeight = fDragRegion->Frame().bottom;
    354         else
    355             windowHeight = fBarMenuBar->Frame().bottom;
     432        } else
     433            windowWidth = kHModeHiddenHeight;
    356434    }
    357 
     435   
    358436    *width = windowWidth;
    359437    *height = windowHeight;
    360438}
     
    408486    settings->showTime = ShowingClock();
    409487
    410488    fReplicantTray->RememberClockSettings();
    411     settings->alwaysOnTop
    412         = (Window()->Feel() & B_FLOATING_ALL_WINDOW_FEEL) != 0;
    413489}
    414490
    415491
    416492void
    417 TBarView::UpdateAutoRaise()
     493TBarView::UpdateEventMask()
    418494{
    419     if (((TBarApp*)be_app)->Settings()->autoRaise)
     495    if (((TBarApp*)be_app)->Settings()->autoRaise
     496        || ((TBarApp*)be_app)->Settings()->autoHide)
    420497        SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
    421498    else
    422499        SetEventMask(0);
     
    443520    fTop = top;
    444521
    445522    // Send a message to the preferences window to let it know to enable
    446     // or disabled preference items
     523    // or disable preference items
    447524    if (stateChanged || vertSwap)
    448525        be_app->PostMessage(kStateChanged);
    449526
     
    507584}
    508585
    509586
     587void
     588TBarView::RaiseDeskbar(bool raise)
     589{
     590    if (raise)
     591        Window()->SetFeel(B_FLOATING_ALL_WINDOW_FEEL);
     592    else
     593        Window()->SetFeel(B_NORMAL_WINDOW_FEEL);
     594}
     595
     596
     597void
     598TBarView::HideDeskbar(bool hide)
     599{
     600    BScreen screen(Window());
     601    BRect screenFrame = screen.Frame();
     602   
     603    if (hide) {
     604        Hide();
     605        PositionWindow(screenFrame);
     606        SizeWindow(screenFrame);
     607    } else {
     608        Show();
     609        SizeWindow(screenFrame);
     610        PositionWindow(screenFrame);
     611    }
     612}
     613
     614
    510615// window placement functions
    511616
    512617bool
  • src/apps/deskbar/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",
     
    408411
    409412        case kAlwaysTop:
    410413            fSettings.alwaysOnTop = !fSettings.alwaysOnTop;
    411 
    412414            fBarWindow->SetFeel(fSettings.alwaysOnTop ?
    413415                B_FLOATING_ALL_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL);
     416            fPreferencesWindow->PostMessage(kStateChanged);
    414417            break;
    415418
    416419        case kAutoRaise:
    417             fSettings.autoRaise = !fSettings.autoRaise;
     420            fSettings.autoRaise = fSettings.alwaysOnTop ? false :
     421                !fSettings.autoRaise;
    418422
    419423            fBarWindow->Lock();
    420             BarView()->UpdateAutoRaise();
     424            BarView()->UpdateEventMask();
    421425            fBarWindow->Unlock();
    422426            break;
    423427
     428        case kAutoHide:
     429            fSettings.autoHide = !fSettings.autoHide;
     430
     431            fBarWindow->Lock();
     432            BarView()->UpdateEventMask();
     433            BarView()->HideDeskbar(fSettings.autoHide);
     434            fBarWindow->Unlock();
     435            break;
     436           
    424437        case kTrackerFirst:
    425438            fSettings.trackerAlwaysFirst = !fSettings.trackerAlwaysFirst;
    426439
  • src/apps/deskbar/StatusView.h

     
    197197
    198198    int32 DragRegionLocation() const;
    199199    void SetDragRegionLocation(int32);
     200   
     201    bool IsDragging() {return IsTracking();}
    200202
    201203private:
    202204    TBarView* fBarView;
  • src/apps/deskbar/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()
     
    301306        fMenuRecentFolderCount->SetEnabled(true);
    302307    else
    303308        fMenuRecentFolderCount->SetEnabled(false);
     309
     310    if (fWindowAlwaysOnTop->Value() == B_CONTROL_ON)
     311        fWindowAutoRaise->SetEnabled(false);
     312    else
     313        fWindowAutoRaise->SetEnabled(true);
    304314}
    305315
    306316
     
    310320    if (!active && IsMinimized())
    311321        PostMessage(B_QUIT_REQUESTED);
    312322}
    313