diff --git a/src/servers/app/server/RootLayer.cpp b/src/servers/app/server/RootLayer.cpp index 47525a98e6..132b4fe71b 100644 --- a/src/servers/app/server/RootLayer.cpp +++ b/src/servers/app/server/RootLayer.cpp @@ -66,7 +66,9 @@ RootLayer::RootLayer(const char *name, int32 workspaceCount, { fDesktop = desktop; - fWinBorderList = NULL; + fWinBorderListLength = 64; + fWinBorderList2 = (WinBorder**)malloc(fWinBorderListLength * sizeof(WinBorder*)); + fWinBorderList = (WinBorder**)malloc(fWinBorderListLength * sizeof(WinBorder*)); fWinBorderCount = 0; fWinBorderIndex = 0; fWsCount = 0; @@ -321,15 +323,6 @@ void RootLayer::ResizeBy(float x, float y) Layer* RootLayer::VirtualTopChild() const { - if (fWinBorderList) - { - free(fWinBorderList); - fWinBorderList = NULL; - } - - void **list; - ActiveWorkspace()->GetWinBorderList(list, &fWinBorderCount); - fWinBorderList = (WinBorder**)list; fWinBorderIndex = fWinBorderCount-1; if (fWinBorderIndex < fWinBorderCount && fWinBorderIndex >= 0) @@ -356,15 +349,6 @@ Layer* RootLayer::VirtualUpperSibling() const Layer* RootLayer::VirtualBottomChild() const { - if (fWinBorderList) - { - free(fWinBorderList); - fWinBorderList = NULL; - } - - void **list; - ActiveWorkspace()->GetWinBorderList(list, &fWinBorderCount); - fWinBorderList = (WinBorder**)list; fWinBorderIndex = 0; if (fWinBorderIndex < fWinBorderCount && fWinBorderIndex >= 0) @@ -906,6 +890,8 @@ void RootLayer::MouseEventHandler(int32 code, BPortLink& msg) exFocus->fDecorator->SetFocus(false); if (focus && exFocus != focus && focus->fDecorator) focus->fDecorator->SetFocus(true); + + get_workspace_windows(); BRegion reg(target->fFull); reg.Include(&target->fTopLayer->fFull); @@ -1554,6 +1540,8 @@ void RootLayer::show_winBorder(WinBorder *winBorder) invalidate = invalid; } + get_workspace_windows(); + if (invalidate) { BRegion reg(winBorder->fFull); @@ -1581,9 +1569,29 @@ void RootLayer::hide_winBorder(WinBorder *winBorder) invalidate = invalid; } + get_workspace_windows(); + if (invalidate) { invalidate_layer(this, winBorder->fFullVisible); } } +void RootLayer::get_workspace_windows() +{ + int32 bufferSize = fWinBorderListLength; + + memcpy(fWinBorderList2, fWinBorderList, fWinBorderCount); + + if (!(ActiveWorkspace()->GetWinBorderList((void**)fWinBorderList, &bufferSize))) + { + fWinBorderList2 = (WinBorder**)realloc(fWinBorderList2, bufferSize); + fWinBorderList = (WinBorder**)realloc(fWinBorderList, bufferSize); + fWinBorderListLength = bufferSize; + ActiveWorkspace()->GetWinBorderList((void**)fWinBorderList, &bufferSize); + } + + fWinBorderCount = bufferSize; + + fWinBorderIndex = 0; +} \ No newline at end of file diff --git a/src/servers/app/server/RootLayer.h b/src/servers/app/server/RootLayer.h index fe012bc514..f7275e440b 100644 --- a/src/servers/app/server/RootLayer.h +++ b/src/servers/app/server/RootLayer.h @@ -136,6 +136,8 @@ friend class Desktop; void show_winBorder(WinBorder* winBorder); void hide_winBorder(WinBorder* winBorder); + void get_workspace_windows(); + void invalidate_layer(Layer *layer, const BRegion ®ion); void redraw_layer(Layer *layer, const BRegion ®ion); @@ -162,9 +164,11 @@ friend class Desktop; int32 fActiveWksIndex; int32 fWsCount; Workspace* fWorkspace[32]; + mutable WinBorder** fWinBorderList2; mutable WinBorder** fWinBorderList; mutable int32 fWinBorderCount; mutable int32 fWinBorderIndex; + int32 fWinBorderListLength; int32 fScreenShotIndex; bool fQuiting; diff --git a/src/servers/app/server/Workspace.cpp b/src/servers/app/server/Workspace.cpp index 64ab589789..ee55a1e233 100644 --- a/src/servers/app/server/Workspace.cpp +++ b/src/servers/app/server/Workspace.cpp @@ -215,7 +215,7 @@ WinBorder *Workspace::Front() const \param list The list of visible WinBorders found in this workspace. \param itemCount Number of WinBorder pointers found in the list. */ -void Workspace::GetWinBorderList(void **&list, int32 *itemCount ) const +bool Workspace::GetWinBorderList(void **list, int32 *itemCount ) const { int32 count = 0; ListData *cursor; @@ -228,18 +228,15 @@ void Workspace::GetWinBorderList(void **&list, int32 *itemCount ) const cursor = cursor->upperItem; } - if (count == 0) + if (*itemCount < count) { - *itemCount = 0; - list = NULL; - return; + // buffer not big enough. buffer must be count high + *itemCount = count; + return false; } - void **mylist; - mylist = (void**)malloc(sizeof(void*) * count); - if (mylist) + if (list) { - list = mylist; *itemCount = count; cursor = fBottomItem; @@ -247,17 +244,14 @@ void Workspace::GetWinBorderList(void **&list, int32 *itemCount ) const { if (!cursor->layerPtr->IsHidden()) { - *mylist = cursor->layerPtr; - mylist++; + *list = cursor->layerPtr; + list++; } cursor = cursor->upperItem; } } - else - { - list = NULL; - itemCount = 0; - } + + return false; } //---------------------------------------------------------------------------------- diff --git a/src/servers/app/server/Workspace.h b/src/servers/app/server/Workspace.h index 365ef46acc..d40298bb25 100644 --- a/src/servers/app/server/Workspace.h +++ b/src/servers/app/server/Workspace.h @@ -63,7 +63,7 @@ public: WinBorder* Focus(void) const; WinBorder* Front(void) const; - void GetWinBorderList(void **&list, int32 *itemCount ) const; + bool GetWinBorderList(void **list, int32 *itemCount ) const; bool MoveToBack(WinBorder *newLast); bool MoveToFront(WinBorder *newFront, bool doNotDisturb = false);