Ticket #2782: tab-snap.patch

File tab-snap.patch, 2.5 KB (added by sdeken, 22 months ago)

Snap windows to edges of screen

  • src/servers/app/Window.h

     
    251251            void                _ObeySizeLimits(); 
    252252            void                _PropagatePosition(); 
    253253 
     254            void                _AlterDeltaForSnap(BPoint& delta) const; 
     255 
    254256            BString             fTitle; 
    255257            // TODO: no fp rects anywhere 
    256258            BRect               fFrame; 
  • src/servers/app/Window.cpp

     
    10161016        if (!(Flags() & B_NOT_MOVABLE)) { 
    10171017            BPoint oldLeftTop = fFrame.LeftTop(); 
    10181018 
     1019            _AlterDeltaForSnap(delta); 
    10191020            fDesktop->MoveWindowBy(this, delta.x, delta.y); 
    10201021 
    10211022            // constrain delta to true change in size 
     
    10771078    } 
    10781079} 
    10791080 
     1081void 
     1082Window::_AlterDeltaForSnap(BPoint& delta) const 
     1083{ 
     1084    // Alter the delta (which is a proposed offset used while dragging a 
     1085    // window) so that the frame of the window 'snaps' to the edges of the 
     1086    // desktop. 
    10801087 
     1088    // TODO: preferences to alter this behavior (on/off, snap distance) 
     1089    // TODO: allow user to override this behavior in a reasonable way 
     1090 
     1091    BRect frame = fFrame; 
     1092    BPoint offsetWithinFrame; 
     1093    // TODO: Obtain the usable area (not covered by the tracker) 
     1094    BRect screenFrame = fDesktop->ActiveScreen()->Frame(); 
     1095 
     1096    if (fDecorator) { 
     1097        BRegion reg; 
     1098        fDecorator->GetFootprint(&reg); 
     1099        frame = reg.Frame(); 
     1100        offsetWithinFrame.x = fFrame.left - frame.left; 
     1101        offsetWithinFrame.y = fFrame.top - frame.top; 
     1102    } 
     1103 
     1104    frame.OffsetBy(delta); 
     1105 
     1106    if (frame.top < screenFrame.top + 4 
     1107        && frame.top > screenFrame.top - 4) { 
     1108        frame.bottom -= frame.top; 
     1109        frame.top = 0; 
     1110    } 
     1111 
     1112    if (frame.left < screenFrame.left + 4 
     1113        && frame.left > screenFrame.left - 4) { 
     1114        frame.right -= frame.left; 
     1115        frame.left = 0; 
     1116    } 
     1117 
     1118    if (frame.bottom > screenFrame.bottom - 4 
     1119        && frame.bottom < screenFrame.bottom + 4) { 
     1120        frame.top -= frame.bottom - screenFrame.bottom; 
     1121        frame.bottom = screenFrame.bottom; 
     1122    } 
     1123 
     1124    if (frame.right > screenFrame.right - 4 
     1125        && frame.right < screenFrame.right + 4) { 
     1126        frame.left -= frame.right - screenFrame.right; 
     1127        frame.right = screenFrame.right; 
     1128    } 
     1129 
     1130    frame.top += offsetWithinFrame.y; 
     1131    frame.left += offsetWithinFrame.x; 
     1132 
     1133    delta.y = frame.top - fFrame.top; 
     1134    delta.x = frame.left - fFrame.left; 
     1135} 
     1136 
    10811137// #pragma mark - 
    10821138 
    10831139 
Attachment Flagspatch
obsolete