diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index 16d3cd00d3..65e4bfa21e 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -2754,17 +2754,17 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) link.Read(&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(workspace.Color()); - fDesktop->Unlock(); + fDesktop->UnlockSingleWindow(); fLink.Flush(); break; } @@ -2782,7 +2782,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) if (link.Read(&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; } diff --git a/src/servers/app/Workspace.cpp b/src/servers/app/Workspace.cpp index b2aa0ff25b..1b890dd3ed 100644 --- a/src/servers/app/Workspace.cpp +++ b/src/servers/app/Workspace.cpp @@ -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(); } diff --git a/src/servers/app/Workspace.h b/src/servers/app/Workspace.h index 4921133092..7e0bfe96a9 100644 --- a/src/servers/app/Workspace.h +++ b/src/servers/app/Workspace.h @@ -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; diff --git a/src/servers/app/WorkspacesView.cpp b/src/servers/app/WorkspacesView.cpp index c20e12c609..a475aad31a 100644 --- a/src/servers/app/WorkspacesView.cpp +++ b/src/servers/app/WorkspacesView.cpp @@ -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