Fixed wrong assert and locking when using Workspace objects.
* The assert in the Workspace constructor was definitely for the wrong lock. One should be holding the all window lock either in read or write mode. The Desktop message loop lock should be unrelated. * Added boolean to the constructor which controls the assert. * Added documentation to Workspace class, since it's not at all obvious how this is intended to be used. * Fixed ServerApp to lock the Desktop correctly when using Workspace desktop colors.
This commit is contained in:
@@ -2754,17 +2754,17 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
|
||||
link.Read<uint32>(&index);
|
||||
|
||||
fLink.StartMessage(B_OK);
|
||||
fDesktop->Lock();
|
||||
fDesktop->LockSingleWindow();
|
||||
|
||||
// we're nice to our children (and also take the default case
|
||||
// into account which asks for the current workspace)
|
||||
if (index >= (uint32)kMaxWorkspaces)
|
||||
index = fDesktop->CurrentWorkspace();
|
||||
|
||||
Workspace workspace(*fDesktop, index);
|
||||
Workspace workspace(*fDesktop, index, true);
|
||||
fLink.Attach<rgb_color>(workspace.Color());
|
||||
|
||||
fDesktop->Unlock();
|
||||
fDesktop->UnlockSingleWindow();
|
||||
fLink.Flush();
|
||||
break;
|
||||
}
|
||||
@@ -2782,7 +2782,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
|
||||
if (link.Read<bool>(&makeDefault) != B_OK)
|
||||
break;
|
||||
|
||||
fDesktop->Lock();
|
||||
fDesktop->LockAllWindows();
|
||||
|
||||
// we're nice to our children (and also take the default case
|
||||
// into account which asks for the current workspace)
|
||||
@@ -2792,7 +2792,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
|
||||
Workspace workspace(*fDesktop, index);
|
||||
workspace.SetColor(color, makeDefault);
|
||||
|
||||
fDesktop->Unlock();
|
||||
fDesktop->UnlockAllWindows();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,13 +79,14 @@ Workspace::Private::_SetDefaults()
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
Workspace::Workspace(Desktop& desktop, int32 index)
|
||||
Workspace::Workspace(Desktop& desktop, int32 index, bool readOnly)
|
||||
:
|
||||
fWorkspace(desktop.WorkspaceAt(index)),
|
||||
fDesktop(desktop),
|
||||
fCurrentWorkspace(index == desktop.CurrentWorkspace())
|
||||
{
|
||||
ASSERT(desktop.IsLocked());
|
||||
ASSERT(desktop.WindowLocker().IsWriteLocked()
|
||||
|| ( readOnly && desktop.WindowLocker().IsReadLocked()));
|
||||
RewindWindows();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,16 @@
|
||||
class Desktop;
|
||||
class Window;
|
||||
|
||||
|
||||
/*!
|
||||
Workspace objects are intended to be short-lived. You create them while
|
||||
already holding a lock to the Desktop read-write lock and then you can use them
|
||||
to query information, and then you destroy them again, for example by letting
|
||||
them go out of scope.
|
||||
*/
|
||||
class Workspace {
|
||||
public:
|
||||
Workspace(Desktop& desktop, int32 index);
|
||||
Workspace(Desktop& desktop, int32 index,
|
||||
bool readOnly = false);
|
||||
~Workspace();
|
||||
|
||||
const rgb_color& Color() const;
|
||||
|
||||
@@ -277,7 +277,7 @@ WorkspacesView::_DrawWorkspace(DrawingEngine* drawingEngine,
|
||||
{
|
||||
BRect rect = _WorkspaceAt(index);
|
||||
|
||||
Workspace workspace(*Window()->Desktop(), index);
|
||||
Workspace workspace(*Window()->Desktop(), index, true);
|
||||
bool workspaceActive = workspace.IsCurrent();
|
||||
if (workspaceActive) {
|
||||
// draw active frame
|
||||
|
||||
Reference in New Issue
Block a user