Author: czeidler Date: 2010-05-31 07:11:33 +0200 (Mon, 31 May 2010) New Revision: 36973 Changeset: http://dev.haiku-os.org/changeset/36973/haiku Modified: haiku/branches/features/stack-and-tile/src/servers/app/StackAndTile.cpp Log: - Variable and Constrains have to been initialized every time. Fix this for now but this should be done in a more clever way. - Cleanup. Modified: haiku/branches/features/stack-and-tile/src/servers/app/StackAndTile.cpp =================================================================== --- haiku/branches/features/stack-and-tile/src/servers/app/StackAndTile.cpp 2010-05-31 05:09:11 UTC (rev 36972) +++ haiku/branches/features/stack-and-tile/src/servers/app/StackAndTile.cpp 2010-05-31 05:11:33 UTC (rev 36973) @@ -9,7 +9,7 @@ using namespace std; -//#define DEBUG_STACK_AND_TILE +#define DEBUG_STACK_AND_TILE #ifdef DEBUG_STACK_AND_TILE @@ -463,6 +463,71 @@ fEnabled = true; + if (fLeftVar) + return; + + fLeftVar = fStackAndTile->GetLinearSpec()->AddVariable(); + fTopVar = fStackAndTile->GetLinearSpec()->AddVariable(); + fRightVar = fStackAndTile->GetLinearSpec()->AddVariable(); + fBottomVar = fStackAndTile->GetLinearSpec()->AddVariable(); + BString label(fWindow->Title()); + label << ".fLeftVar"; + fLeftVar->SetLabel(label.String()); + label = fWindow->Title(); + label << ".fTopVar"; + fTopVar->SetLabel(label.String()); + label = fWindow->Title(); + label << ".fRightVar"; + fRightVar->SetLabel(label.String()); + label = fWindow->Title(); + label << ".fBottomVar"; + fBottomVar->SetLabel(label.String()); + + fLeftVar->SetRange(-DBL_MAX, DBL_MAX); + fTopVar->SetRange(-DBL_MAX, DBL_MAX); + fRightVar->SetRange(-DBL_MAX, DBL_MAX); + fBottomVar->SetRange(-DBL_MAX, DBL_MAX); + + fLeftConstraint = fStackAndTile->GetLinearSpec()->AddConstraint(1.0, + fLeftVar, OperatorType(EQ), fWindow->Frame().left, 1, 1); + fTopConstraint = fStackAndTile->GetLinearSpec()->AddConstraint(1.0, + fTopVar, OperatorType(EQ), fWindow->Frame().top, 1, 1); + label = fWindow->Title(); + label << ".fLeftConstraint"; + fLeftConstraint->SetLabel(label.String()); + label = fWindow->Title(); + label << ".fTopConstraint"; + fTopConstraint->SetLabel(label.String()); + + int32 minWidth, maxWidth, minHeight, maxHeight; + fWindow->GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); + fMinWidthConstraint = fStackAndTile->GetLinearSpec()->AddConstraint(1.0, + fLeftVar, -1.0, fRightVar, OperatorType(LE), -minWidth); + fMinHeightConstraint = fStackAndTile->GetLinearSpec()->AddConstraint(1.0, + fTopVar, -1.0, fBottomVar, OperatorType(LE), -minHeight); + label = fWindow->Title(); + label << ".fMinWidthConstraint"; + fMinWidthConstraint->SetLabel(label.String()); + label = fWindow->Title(); + label << ".fMinHeightConstraint"; + fMinHeightConstraint->SetLabel(label.String()); + + // The width and height constraints have higher penalties than the + // position constraints (left, top), so a window will keep its size + // unless explicitly resized. + fWidthConstraint = fStackAndTile->GetLinearSpec()->AddConstraint(-1.0, + fLeftVar, 1.0, fRightVar, OperatorType(EQ), fWindow->Frame().Width(), + 10, 10); + fHeightConstraint = fStackAndTile->GetLinearSpec()->AddConstraint(-1.0, + fTopVar, 1.0, fBottomVar, OperatorType(EQ), fWindow->Frame().Height(), + 10, 10); + label = fWindow->Title(); + label << ".fWidthConstraint"; + fWidthConstraint->SetLabel(label.String()); + label = fWindow->Title(); + label << ".fHeightConstraint"; + fHeightConstraint->SetLabel(label.String()); + STRACE_SAT(("Finished Window::InitStackingAndSnapping() on %s\n", fWindow->Title())); } @@ -480,6 +545,30 @@ fEnabled = false; + delete fLeftConstraint; + delete fTopConstraint; + delete fMinWidthConstraint; + delete fMinHeightConstraint; + delete fWidthConstraint; + delete fHeightConstraint; + fLeftConstraint = NULL; + fTopConstraint = NULL; + fMinWidthConstraint = NULL; + fMinHeightConstraint = NULL; + fWidthConstraint = NULL; + fHeightConstraint = NULL; + + // deleting variables also invalidates their constraints + // therefore we can delete them afterwards without harm + delete fLeftVar; + delete fTopVar; + delete fRightVar; + delete fBottomVar; + fLeftVar = NULL; + fTopVar = NULL; + fRightVar = NULL; + fBottomVar = NULL; + STRACE_SAT(("Finished Window::_RemoveSAT() on %s\n", fWindow->Title())); } @@ -503,8 +592,8 @@ void SATWindow::StackAndTile() { - STRACE_SAT(("Window::StackAndTile() on %s, fWindow->Desktop()->fStackAndTileSpec=%x\n", - fWindow->Title(), fStackAndTile->GetLinearSpec())); + STRACE_SAT(("Window::StackAndTile() on %s, fEnabled=%i\n", fWindow->Title(), + fEnabled)); // works only if stack and tile is active for this window if (!fEnabled) @@ -536,16 +625,15 @@ } // set window locations and sizes - for (Window* window = fWindow->Desktop()->CurrentWindows().LastWindow(); - window; + for (Window* window = Desktop()->CurrentWindows().LastWindow(); window; window = window->PreviousWindow(fWindow->CurrentWorkspace())) { SATWindow* windowSAT = fStackAndTile->GetSATWindow(window); if (windowSAT && windowSAT != this && windowSAT->fEnabled) { - fWindow->Desktop()->MoveWindowBy(window, + Desktop()->MoveWindowBy(window, windowSAT->fLeftVar->Value() - window->Frame().left, windowSAT->fTopVar->Value() - window->Frame().top); - fWindow->Desktop()->ResizeWindowBy(window, + Desktop()->ResizeWindowBy(window, windowSAT->fRightVar->Value() - window->Frame().right, windowSAT->fBottomVar->Value() - window->Frame().bottom); }