Removed locking from Workspace class. Rootlayer should be the only one who uses this class. Also changed Workspace::AddLayerPtr() into AddWinBorder.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8374 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adi Oanca
2004-07-11 10:01:01 +00:00
parent 72bb797ea9
commit 038d30aae7
5 changed files with 29 additions and 53 deletions
+1 -1
View File
@@ -846,7 +846,7 @@ void Desktop::RemoveSubsetWindow(WinBorder* wb)
int32 countWKs = rl->WorkspaceCount(); int32 countWKs = rl->WorkspaceCount();
for (int32 i=0; i < countWKs; i++) for (int32 i=0; i < countWKs; i++)
rl->WorkspaceAt(i+1)->RemoveLayerPtr(wb); rl->WorkspaceAt(i+1)->RemoveWinBorder(wb);
} }
+7 -7
View File
@@ -219,7 +219,7 @@ void RootLayer::AddWinBorderToWorkspaces(WinBorder* winBorder, uint32 wks)
for( int32 i=0; i < 32; i++) for( int32 i=0; i < 32; i++)
{ {
if( wks & (0x00000001 << i) && i < WorkspaceCount()) if( wks & (0x00000001 << i) && i < WorkspaceCount())
WorkspaceAt(i+1)->AddLayerPtr(winBorder); WorkspaceAt(i+1)->AddWinBorder(winBorder);
} }
} }
@@ -349,7 +349,7 @@ void RootLayer::RemoveWinBorder(WinBorder* winBorder)
int32 count = WorkspaceCount(); int32 count = WorkspaceCount();
for(int32 i=0; i < count; i++) for(int32 i=0; i < count; i++)
WorkspaceAt(i+1)->RemoveLayerPtr(winBorder); WorkspaceAt(i+1)->RemoveWinBorder(winBorder);
} }
else else
{ // for B_NORMAL_WINDOW_FEEL { // for B_NORMAL_WINDOW_FEEL
@@ -358,7 +358,7 @@ void RootLayer::RemoveWinBorder(WinBorder* winBorder)
for( int32 i=0; i < 32 && i < count; i++) for( int32 i=0; i < 32 && i < count; i++)
{ {
if( workspaces & (0x00000001UL << i)) if( workspaces & (0x00000001UL << i))
WorkspaceAt(i+1)->RemoveLayerPtr(winBorder); WorkspaceAt(i+1)->RemoveWinBorder(winBorder);
} }
} }
@@ -399,12 +399,12 @@ void RootLayer::ChangeWorkspacesFor(WinBorder* winBorder, uint32 newWorkspaces)
else else
if(oldWorkspaces & (0x00000001 << i)) if(oldWorkspaces & (0x00000001 << i))
{ {
WorkspaceAt(i+1)->RemoveLayerPtr(winBorder); WorkspaceAt(i+1)->RemoveWinBorder(winBorder);
} }
else else
if (newWorkspaces & (0x00000001 << i)) if (newWorkspaces & (0x00000001 << i))
{ {
WorkspaceAt(i+1)->AddLayerPtr(winBorder); WorkspaceAt(i+1)->AddWinBorder(winBorder);
} }
} }
} }
@@ -560,7 +560,7 @@ void RootLayer::SetWorkspaceCount(const int32 count)
else else
{ {
Workspace *ws; Workspace *ws;
ws = new Workspace(fColorSpace, i+1, BGColor(), this); ws = new Workspace(fColorSpace, i+1, BGColor());
newWSPtrList.AddItem(ws); newWSPtrList.AddItem(ws);
} }
} }
@@ -653,7 +653,7 @@ void RootLayer::RemoveAppWindow(WinBorder *wb)
int32 count = WorkspaceCount(); int32 count = WorkspaceCount();
for(int32 i=0; i < count; i++) for(int32 i=0; i < count; i++)
WorkspaceAt(i+1)->RemoveLayerPtr(wb); WorkspaceAt(i+1)->RemoveWinBorder(wb);
} }
void RootLayer::PrintToStream() void RootLayer::PrintToStream()
+2 -2
View File
@@ -515,7 +515,7 @@ void WinBorder::AddToSubsetOf(WinBorder* main)
{ {
Workspace *ws = rl->WorkspaceAt(i+1); Workspace *ws = rl->WorkspaceAt(i+1);
if(ws->FrontLayer() == main) if(ws->FrontLayer() == main)
ws->AddLayerPtr(this); ws->AddWinBorder(this);
} }
rl->fMainLock.Unlock(); rl->fMainLock.Unlock();
@@ -549,7 +549,7 @@ void WinBorder::RemoveFromSubsetOf(WinBorder* main)
// if its main window is in 'i' workspaces, remove it from // if its main window is in 'i' workspaces, remove it from
// workspace 'i' if it's in there... // workspace 'i' if it's in there...
ws->RemoveLayerPtr(this); ws->RemoveWinBorder(this);
} }
} }
} }
+8 -28
View File
@@ -23,6 +23,10 @@
// Author: Adi Oanca <[email protected]> // Author: Adi Oanca <[email protected]>
// Description: Tracks workspaces // Description: Tracks workspaces
// //
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Notes: IMPORTANT WARNING
// This object does not use any locking mechanism. It is designed
// to be used only by RootLayer class. DO NOT USE from another class!
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#include <stdio.h> #include <stdio.h>
#include <Window.h> #include <Window.h>
@@ -35,8 +39,6 @@
#include "RGBColor.h" #include "RGBColor.h"
#include "Globals.h" #include "Globals.h"
#include "FMWList.h" #include "FMWList.h"
#include "RootLayer.h"
#include "Desktop.h"
//#define DEBUG_WORKSPACE //#define DEBUG_WORKSPACE
@@ -56,14 +58,12 @@
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
Workspace::Workspace(const uint32 colorspace, int32 ID, const RGBColor& BGColor, RootLayer *owner) Workspace::Workspace(const uint32 colorspace, int32 ID, const RGBColor& BGColor)
{ {
fID = ID; fID = ID;
fSpace = colorspace; fSpace = colorspace;
fBGColor = BGColor; fBGColor = BGColor;
fOwner = owner;
fBottomItem = NULL; fBottomItem = NULL;
fTopItem = NULL; fTopItem = NULL;
fCurrentItem= NULL; fCurrentItem= NULL;
@@ -115,7 +115,7 @@ Workspace::~Workspace(void)
to give focus to, having as preferred 'layer'. to give focus to, having as preferred 'layer'.
Remember, some windows having B_AVOID_FOCUS can't have the focus state. Remember, some windows having B_AVOID_FOCUS can't have the focus state.
*/ */
bool Workspace::AddLayerPtr(WinBorder *layer) bool Workspace::AddWinBorder(WinBorder *layer)
{ {
if (layer == NULL) if (layer == NULL)
debugger("NULL pointer in Workspace::AddLayerPtr\n"); debugger("NULL pointer in Workspace::AddLayerPtr\n");
@@ -128,12 +128,9 @@ bool Workspace::AddLayerPtr(WinBorder *layer)
item->upperItem = NULL; item->upperItem = NULL;
item->lowerItem = NULL; item->lowerItem = NULL;
fOpLock.Lock();
// insert 'item' at the end. It doesn't matter where we add it, // insert 'item' at the end. It doesn't matter where we add it,
// it will be placed correctly by SearchAndSetNewFront(item->layerPtr); // it will be placed correctly by SearchAndSetNewFront(item->layerPtr);
InsertItem(item, NULL); InsertItem(item, NULL);
fOpLock.Unlock();
STRACE(("\n*AddLayerPtr(%s) -", layer->GetName())); STRACE(("\n*AddLayerPtr(%s) -", layer->GetName()));
@@ -154,9 +151,9 @@ bool Workspace::AddLayerPtr(WinBorder *layer)
If this window was the front/focus one it calls SearchAndSetNew(Front/Focus) If this window was the front/focus one it calls SearchAndSetNew(Front/Focus)
to give the respective state to the window below her. to give the respective state to the window below her.
*/ */
bool Workspace::RemoveLayerPtr(WinBorder *layer) bool Workspace::RemoveWinBorder(WinBorder *layer)
{ {
if(!layer) if (layer == NULL)
return false; return false;
STRACE(("\n*Workspace(%ld)::RemoveLayerPtr(%s)\n", ID(), layer->GetName())); STRACE(("\n*Workspace(%ld)::RemoveLayerPtr(%s)\n", ID(), layer->GetName()));
@@ -166,7 +163,6 @@ bool Workspace::RemoveLayerPtr(WinBorder *layer)
// search to see if this workspace has WinBorder's pointer in its list // search to see if this workspace has WinBorder's pointer in its list
ListData *item = NULL; ListData *item = NULL;
fOpLock.Lock();
if((item = HasItem(layer))) if((item = HasItem(layer)))
{ {
ListData *nextItem = NULL; ListData *nextItem = NULL;
@@ -201,7 +197,6 @@ bool Workspace::RemoveLayerPtr(WinBorder *layer)
RemoveItem(item); RemoveItem(item);
delete item; delete item;
STRACESTREAM(); STRACESTREAM();
fOpLock.Unlock();
// reset some internal variables // reset some internal variables
layer->SetMainWinBorder(NULL); layer->SetMainWinBorder(NULL);
@@ -215,7 +210,6 @@ bool Workspace::RemoveLayerPtr(WinBorder *layer)
else else
{ {
STRACE(("Layer %s NOT found in Workspace No %ld\n", layer->GetName(), ID())); STRACE(("Layer %s NOT found in Workspace No %ld\n", layer->GetName(), ID()));
fOpLock.Unlock();
return false; return false;
} }
} }
@@ -230,7 +224,6 @@ bool Workspace::HideSubsetWindows(WinBorder *layer)
// search to see if this workspace has WinBorder's pointer in its list // search to see if this workspace has WinBorder's pointer in its list
ListData *item = NULL; ListData *item = NULL;
fOpLock.Lock();
if((item = HasItem(layer))) if((item = HasItem(layer)))
{ {
ListData *nextItem = NULL; ListData *nextItem = NULL;
@@ -259,13 +252,10 @@ bool Workspace::HideSubsetWindows(WinBorder *layer)
} }
} }
fOpLock.Unlock();
return true; return true;
} }
else else
{ {
fOpLock.Unlock();
return false; return false;
} }
} }
@@ -552,7 +542,6 @@ ListData *Workspace::FindPlace(ListData *pref)
void Workspace::SearchAndSetNewFront(WinBorder *preferred) void Workspace::SearchAndSetNewFront(WinBorder *preferred)
{ {
STRACE(("*WS(%ld)::SASNF(%s)\n", ID(), preferred? preferred->GetName(): "NULL")); STRACE(("*WS(%ld)::SASNF(%s)\n", ID(), preferred? preferred->GetName(): "NULL"));
fOpLock.Lock();
// the new front must not be the same as the previous one. // the new front must not be the same as the previous one.
if(fFrontItem && fFrontItem->layerPtr == preferred && !(preferred->IsHidden())) if(fFrontItem && fFrontItem->layerPtr == preferred && !(preferred->IsHidden()))
@@ -562,7 +551,6 @@ void Workspace::SearchAndSetNewFront(WinBorder *preferred)
STRACESTREAM(); STRACESTREAM();
STRACE(("#WS(%ld)::SASNF(%s) ENDED 1\n", ID(), preferred? preferred->GetName(): "NULL")); STRACE(("#WS(%ld)::SASNF(%s) ENDED 1\n", ID(), preferred? preferred->GetName(): "NULL"));
fOpLock.Unlock();
return; return;
} }
@@ -581,7 +569,6 @@ void Workspace::SearchAndSetNewFront(WinBorder *preferred)
STRACESTREAM(); STRACESTREAM();
STRACE(("#WS(%ld)::SASNF(%s) ENDED 2\n", ID(), preferred? preferred->GetName(): "NULL")); STRACE(("#WS(%ld)::SASNF(%s) ENDED 2\n", ID(), preferred? preferred->GetName(): "NULL"));
fOpLock.Unlock();
return; return;
} }
@@ -1086,7 +1073,6 @@ void Workspace::SearchAndSetNewFront(WinBorder *preferred)
fFrontItem = newFrontItem; fFrontItem = newFrontItem;
// TODO: call a method like... WinBorder::MakeFront(true); // TODO: call a method like... WinBorder::MakeFront(true);
} }
fOpLock.Unlock();
STRACE(("#WS(%ld)::SASNF(%s) ENDED! Workspace data...", ID(), preferred? preferred->GetName(): "NULL")); STRACE(("#WS(%ld)::SASNF(%s) ENDED! Workspace data...", ID(), preferred? preferred->GetName(): "NULL"));
STRACESTREAM(); STRACESTREAM();
@@ -1102,8 +1088,6 @@ void Workspace::SearchAndSetNewFocus(WinBorder *preferred)
{ {
STRACE(("*WS(%ld)::SASNFocus(%s)\n", ID(), preferred? preferred->GetName(): "NULL")); STRACE(("*WS(%ld)::SASNFocus(%s)\n", ID(), preferred? preferred->GetName(): "NULL"));
fOpLock.Lock();
if(!preferred) if(!preferred)
preferred = fBottomItem? fBottomItem->layerPtr : NULL; preferred = fBottomItem? fBottomItem->layerPtr : NULL;
@@ -1175,8 +1159,6 @@ void Workspace::SearchAndSetNewFocus(WinBorder *preferred)
// TODO: Rebuild & Redraw. // TODO: Rebuild & Redraw.
fFocusItem = item; fFocusItem = item;
} }
fOpLock.Unlock();
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@@ -1194,7 +1176,6 @@ void Workspace::BringToFrontANormalWindow(WinBorder *layer)
case B_FLOATING_APP_WINDOW_FEEL: case B_FLOATING_APP_WINDOW_FEEL:
case B_MODAL_APP_WINDOW_FEEL: case B_MODAL_APP_WINDOW_FEEL:
{ {
fOpLock.Lock();
ListData *item = fBottomItem; ListData *item = fBottomItem;
team_id tid = layer->Window()->ClientTeamID(); team_id tid = layer->Window()->ClientTeamID();
while(item) while(item)
@@ -1210,7 +1191,6 @@ void Workspace::BringToFrontANormalWindow(WinBorder *layer)
if(item) if(item)
SearchAndSetNewFront(item->layerPtr); SearchAndSetNewFront(item->layerPtr);
fOpLock.Unlock();
break; break;
} }
default: default:
+11 -15
View File
@@ -23,6 +23,10 @@
// Author: Adi Oanca <[email protected]> // Author: Adi Oanca <[email protected]>
// Description: Tracks workspaces // Description: Tracks workspaces
// //
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Notes: IMPORTANT WARNING
// This object does not use any locking mechanism. It is designed
// to be used only by RootLayer class. DO NOT USE from another class!
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifndef _WORKSPACE_H_ #ifndef _WORKSPACE_H_
#define _WORKSPACE_H_ #define _WORKSPACE_H_
@@ -34,8 +38,6 @@
#include "RGBColor.h" #include "RGBColor.h"
class WinBorder; class WinBorder;
class RBGColor;
class RootLayer;
struct ListData struct ListData
{ {
@@ -47,12 +49,11 @@ struct ListData
class Workspace class Workspace
{ {
public: public:
Workspace(const uint32 colorspace, int32 ID, const RGBColor& BGColor, Workspace(const uint32 colorspace, int32 ID, const RGBColor& BGColor);
RootLayer *owner);
~Workspace(void); ~Workspace(void);
bool AddLayerPtr(WinBorder *layer); bool AddWinBorder(WinBorder *layer);
bool RemoveLayerPtr(WinBorder *layer); bool RemoveWinBorder(WinBorder *layer);
bool HideSubsetWindows(WinBorder *layer); bool HideSubsetWindows(WinBorder *layer);
WinBorder *FocusLayer(void) const; WinBorder *FocusLayer(void) const;
WinBorder *FrontLayer(void) const; WinBorder *FrontLayer(void) const;
@@ -65,7 +66,7 @@ public:
WinBorder *GoToTopItem(void); WinBorder *GoToTopItem(void);
WinBorder *GoToLowerItem(void); WinBorder *GoToLowerItem(void);
bool GoToItem(WinBorder *layer); bool GoToItem(WinBorder *layer);
void SetLocalSpace(const uint32 colorspace); void SetLocalSpace(const uint32 colorspace);
uint32 LocalSpace(void) const; uint32 LocalSpace(void) const;
@@ -89,13 +90,12 @@ public:
void SearchAndSetNewFocus(WinBorder *preferred); void SearchAndSetNewFocus(WinBorder *preferred);
void BringToFrontANormalWindow(WinBorder *layer); void BringToFrontANormalWindow(WinBorder *layer);
ListData *HasItem(WinBorder *layer);
private: private:
void InsertItem(ListData *item, ListData *before); void InsertItem(ListData *item, ListData *before);
void RemoveItem(ListData *item); void RemoveItem(ListData *item);
ListData *HasItem(ListData *item); ListData *HasItem(ListData *item);
ListData *HasItem(WinBorder *layer);
ListData *FindPlace(ListData *pref); ListData *FindPlace(ListData *pref);
@@ -103,23 +103,19 @@ private:
uint32 fSpace; uint32 fSpace;
RGBColor fBGColor; RGBColor fBGColor;
BLocker fOpLock;
RootLayer *fOwner;
// first visible onscreen // first visible onscreen
ListData *fBottomItem; ListData *fBottomItem;
// the last visible(or covered by other Layers) // the last visible(or covered by other Layers)
ListData *fTopItem; ListData *fTopItem;
// pointer to the currect element in the list // pointer to the current element in the list
ListData *fCurrentItem; ListData *fCurrentItem;
// the focus WinBorder - for keyboard events // the focus WinBorder - for keyboard events
ListData *fFocusItem; ListData *fFocusItem;
// the one the mouse can bring in front as possible(in its set) // the item that is the target of mouse operations
ListData *fFrontItem; ListData *fFrontItem;
// settings for each workspace -- example taken from R5's app_server_settings file // settings for each workspace -- example taken from R5's app_server_settings file