* AS_CURRENT_WORKSPACE now holds a single window lock before retrieving

the current workspace.
* This should fix bug #1765 as far as the app_server is concerned.
* Cleanup, removed extraneous white space.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24632 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-03-28 18:59:08 +00:00
parent b4bacb2a8a
commit 9dbce7a4e7
2 changed files with 81 additions and 60 deletions
+36 -20
View File
@@ -61,7 +61,8 @@ class Desktop : public MessageLooper, public ScreenOwner {
uid_t UserID() const { return fUserID; } uid_t UserID() const { return fUserID; }
virtual port_id MessagePort() const { return fMessagePort; } virtual port_id MessagePort() const { return fMessagePort; }
area_id SharedReadOnlyArea() const { return fSharedReadOnlyArea; } area_id SharedReadOnlyArea() const
{ return fSharedReadOnlyArea; }
::EventDispatcher& EventDispatcher() { return fEventDispatcher; } ::EventDispatcher& EventDispatcher() { return fEventDispatcher; }
@@ -121,10 +122,12 @@ class Desktop : public MessageLooper, public ScreenOwner {
void MoveWindowBy(Window* window, float x, float y, void MoveWindowBy(Window* window, float x, float y,
int32 workspace = -1); int32 workspace = -1);
void ResizeWindowBy(Window* window, float x, float y); void ResizeWindowBy(Window* window, float x,
bool SetWindowTabLocation(Window* window, float location); float y);
bool SetWindowTabLocation(Window* window,
float location);
bool SetWindowDecoratorSettings(Window* window, bool SetWindowDecoratorSettings(Window* window,
const BMessage& settings); const BMessage& settings);
void SetWindowWorkspaces(Window* window, void SetWindowWorkspaces(Window* window,
uint32 workspaces); uint32 workspaces);
@@ -140,7 +143,8 @@ class Desktop : public MessageLooper, public ScreenOwner {
void SetWindowLook(Window* window, window_look look); void SetWindowLook(Window* window, window_look look);
void SetWindowFeel(Window* window, window_feel feel); void SetWindowFeel(Window* window, window_feel feel);
void SetWindowFlags(Window* window, uint32 flags); void SetWindowFlags(Window* window, uint32 flags);
void SetWindowTitle(Window* window, const char* title); void SetWindowTitle(Window* window,
const char* title);
Window* FocusWindow() const { return fFocus; } Window* FocusWindow() const { return fFocus; }
Window* FrontWindow() const { return fFront; } Window* FrontWindow() const { return fFront; }
@@ -148,10 +152,12 @@ class Desktop : public MessageLooper, public ScreenOwner {
Window* WindowAt(BPoint where); Window* WindowAt(BPoint where);
Window* MouseEventWindow() const { return fMouseEventWindow; } Window* MouseEventWindow() const
{ return fMouseEventWindow; }
void SetMouseEventWindow(Window* window); void SetMouseEventWindow(Window* window);
void SetViewUnderMouse(const Window* window, int32 viewToken); void SetViewUnderMouse(const Window* window,
int32 viewToken);
int32 ViewUnderMouse(const Window* window); int32 ViewUnderMouse(const Window* window);
void SetFocusWindow(Window* window = NULL); void SetFocusWindow(Window* window = NULL);
@@ -161,17 +167,25 @@ class Desktop : public MessageLooper, public ScreenOwner {
team_id teamID); team_id teamID);
#if USE_MULTI_LOCKER #if USE_MULTI_LOCKER
bool LockSingleWindow() { return fWindowLock.ReadLock(); } bool LockSingleWindow()
void UnlockSingleWindow() { fWindowLock.ReadUnlock(); } { return fWindowLock.ReadLock(); }
void UnlockSingleWindow()
{ fWindowLock.ReadUnlock(); }
bool LockAllWindows() { return fWindowLock.WriteLock(); } bool LockAllWindows()
void UnlockAllWindows() { fWindowLock.WriteUnlock(); } { return fWindowLock.WriteLock(); }
void UnlockAllWindows()
{ fWindowLock.WriteUnlock(); }
#else // USE_MULTI_LOCKER #else // USE_MULTI_LOCKER
bool LockSingleWindow() { return fWindowLock.Lock(); } bool LockSingleWindow()
void UnlockSingleWindow() { fWindowLock.Unlock(); } { return fWindowLock.Lock(); }
void UnlockSingleWindow()
{ fWindowLock.Unlock(); }
bool LockAllWindows() { return fWindowLock.Lock(); } bool LockAllWindows()
void UnlockAllWindows() { fWindowLock.Unlock(); } { return fWindowLock.Lock(); }
void UnlockAllWindows()
{ fWindowLock.Unlock(); }
#endif // USE_MULTI_LOCKER #endif // USE_MULTI_LOCKER
void MarkDirty(BRegion& region); void MarkDirty(BRegion& region);
@@ -211,8 +225,10 @@ class Desktop : public MessageLooper, public ScreenOwner {
status_t _ActivateApp(team_id team); status_t _ActivateApp(team_id team);
void _SendFakeMouseMoved(Window* window = NULL); void _SendFakeMouseMoved(Window* window = NULL);
void _RebuildClippingForAllWindows(BRegion& stillAvailableOnScreen); void _RebuildClippingForAllWindows(
void _TriggerWindowRedrawing(BRegion& newDirtyRegion); BRegion& stillAvailableOnScreen);
void _TriggerWindowRedrawing(
BRegion& newDirtyRegion);
void _SetBackground(BRegion& background); void _SetBackground(BRegion& background);
void _UpdateFloating(int32 previousWorkspace = -1, void _UpdateFloating(int32 previousWorkspace = -1,
@@ -282,9 +298,9 @@ class Desktop : public MessageLooper, public ScreenOwner {
BPoint fLastMousePosition; BPoint fLastMousePosition;
int32 fLastMouseButtons; int32 fLastMouseButtons;
Window* fFocus; Window* fFocus;
Window* fFront; Window* fFront;
Window* fBack; Window* fBack;
}; };
#endif // DESKTOP_H #endif // DESKTOP_H
+45 -40
View File
@@ -266,7 +266,7 @@ bool
ServerApp::_HasWindowUnderMouse() ServerApp::_HasWindowUnderMouse()
{ {
BAutolock locker(fWindowListLock); BAutolock locker(fWindowListLock);
for (int32 i = fWindowList.CountItems(); i-- > 0;) { for (int32 i = fWindowList.CountItems(); i-- > 0;) {
ServerWindow* serverWindow = fWindowList.ItemAt(i); ServerWindow* serverWindow = fWindowList.ItemAt(i);
@@ -281,7 +281,7 @@ ServerApp::_HasWindowUnderMouse()
/*! /*!
\brief Sets the ServerApp's active status \brief Sets the ServerApp's active status
\param value The new status of the ServerApp. \param value The new status of the ServerApp.
This changes an internal flag and also sets the current cursor to the one specified by This changes an internal flag and also sets the current cursor to the one specified by
the application the application
*/ */
@@ -410,8 +410,8 @@ ServerApp::_MessageLooper()
\param code Identifier code for the message. Equivalent to BMessage::what \param code Identifier code for the message. Equivalent to BMessage::what
\param buffer Any attachments \param buffer Any attachments
Note that the buffer's exact format is determined by the particular message. Note that the buffer's exact format is determined by the particular message.
All attachments are placed in the buffer via a PortLink, so it will be a All attachments are placed in the buffer via a PortLink, so it will be a
matter of casting and incrementing an index variable to access them. matter of casting and incrementing an index variable to access them.
*/ */
void void
@@ -561,7 +561,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
} }
case AS_R5_SET_DECORATOR: case AS_R5_SET_DECORATOR:
{ {
// Sort of supports Tracker's nifty Easter Egg. It was easy to do and // Sort of supports Tracker's nifty Easter Egg. It was easy to do and
// it's kind of neat, so why not? // it's kind of neat, so why not?
// Attached Data: // Attached Data:
@@ -576,7 +576,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
if (gDecorManager.SetR5Decorator(decindex)) if (gDecorManager.SetR5Decorator(decindex))
fDesktop->BroadcastToAllApps(AS_UPDATE_DECORATOR); fDesktop->BroadcastToAllApps(AS_UPDATE_DECORATOR);
break; break;
} }
case AS_CREATE_BITMAP: case AS_CREATE_BITMAP:
@@ -590,12 +590,12 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// 3) int32 bitmap_flags // 3) int32 bitmap_flags
// 4) int32 bytes_per_row // 4) int32 bytes_per_row
// 5) int32 screen_id::id // 5) int32 screen_id::id
// Reply Data: // Reply Data:
// 1) int32 server token // 1) int32 server token
// 2) area_id id of the area in which the bitmap data resides // 2) area_id id of the area in which the bitmap data resides
// 3) int32 area pointer offset used to calculate fBasePtr // 3) int32 area pointer offset used to calculate fBasePtr
// First, let's attempt to allocate the bitmap // First, let's attempt to allocate the bitmap
ServerBitmap *bitmap = NULL; ServerBitmap *bitmap = NULL;
uint8 allocationFlags = kAllocator; uint8 allocationFlags = kAllocator;
@@ -689,7 +689,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
{ {
// TODO: Maybe rename this to AS_UPLOAD_PICTURE ? // TODO: Maybe rename this to AS_UPLOAD_PICTURE ?
STRACE(("ServerApp %s: Create Picture\n", Signature())); STRACE(("ServerApp %s: Create Picture\n", Signature()));
status_t status = B_ERROR; status_t status = B_ERROR;
ServerPicture *picture = CreatePicture(); ServerPicture *picture = CreatePicture();
if (picture != NULL) { if (picture != NULL) {
int32 subPicturesCount = 0; int32 subPicturesCount = 0;
@@ -729,18 +729,18 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
ServerPicture *original = NULL; ServerPicture *original = NULL;
if (link.Read<int32>(&token) == B_OK) if (link.Read<int32>(&token) == B_OK)
original = FindPicture(token); original = FindPicture(token);
ServerPicture *cloned = NULL; ServerPicture *cloned = NULL;
if (original != NULL) if (original != NULL)
cloned = CreatePicture(original); cloned = CreatePicture(original);
if (cloned != NULL) { if (cloned != NULL) {
fLink.StartMessage(B_OK); fLink.StartMessage(B_OK);
fLink.Attach<int32>(cloned->Token()); fLink.Attach<int32>(cloned->Token());
} else } else
fLink.StartMessage(B_ERROR); fLink.StartMessage(B_ERROR);
fLink.Flush(); fLink.Flush();
break; break;
} }
@@ -755,9 +755,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// ExportData() calls StartMessage() already // ExportData() calls StartMessage() already
} else } else
fLink.StartMessage(B_ERROR); fLink.StartMessage(B_ERROR);
fLink.Flush(); fLink.Flush();
break; break;
} }
@@ -787,8 +787,13 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
case AS_CURRENT_WORKSPACE: case AS_CURRENT_WORKSPACE:
STRACE(("ServerApp %s: get current workspace\n", Signature())); STRACE(("ServerApp %s: get current workspace\n", Signature()));
fLink.StartMessage(B_OK); if (fDesktop->LockSingleWindow()) {
fLink.Attach<int32>(fDesktop->CurrentWorkspace()); fLink.StartMessage(B_OK);
fLink.Attach<int32>(fDesktop->CurrentWorkspace());
fDesktop->UnlockSingleWindow();
} else
fLink.StartMessage(B_ERROR);
fLink.Flush(); fLink.Flush();
break; break;
@@ -952,7 +957,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
case AS_GET_SCROLLBAR_INFO: case AS_GET_SCROLLBAR_INFO:
{ {
STRACE(("ServerApp %s: Get ScrollBar info\n", Signature())); STRACE(("ServerApp %s: Get ScrollBar info\n", Signature()));
if (fDesktop->LockSingleWindow()) { if (fDesktop->LockSingleWindow()) {
scroll_bar_info info; scroll_bar_info info;
DesktopSettings settings(fDesktop); DesktopSettings settings(fDesktop);
@@ -1258,7 +1263,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
fLink.StartMessage(B_OK); fLink.StartMessage(B_OK);
fLink.AttachString(family->Name()); fLink.AttachString(family->Name());
fLink.Attach<uint32>(family->Flags()); fLink.Attach<uint32>(family->Flags());
int32 count = family->CountStyles(); int32 count = family->CountStyles();
fLink.Attach<int32>(count); fLink.Attach<int32>(count);
@@ -1388,7 +1393,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// 2) uint16 ID of style // 2) uint16 ID of style
// 3) float point size of font // 3) float point size of font
// 4) uint8 spacing to use // 4) uint8 spacing to use
// 5) int32 numStrings // 5) int32 numStrings
// 6) int32 string length to measure (numStrings times) // 6) int32 string length to measure (numStrings times)
// 7) string String to measure (numStrings times) // 7) string String to measure (numStrings times)
@@ -1676,7 +1681,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// 3) int32 - numChars // 3) int32 - numChars
// 4) int32 - numBytes // 4) int32 - numBytes
// 5) char - the char buffer with size numBytes // 5) char - the char buffer with size numBytes
uint16 familyID, styleID; uint16 familyID, styleID;
link.Read<uint16>(&familyID); link.Read<uint16>(&familyID);
link.Read<uint16>(&styleID); link.Read<uint16>(&styleID);
@@ -1821,7 +1826,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// Returns: // Returns:
// 1) float - escapement buffer with numChar entries // 1) float - escapement buffer with numChar entries
uint16 familyID, styleID; uint16 familyID, styleID;
uint32 flags; uint32 flags;
float size, rotation; float size, rotation;
@@ -1837,7 +1842,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
escapement_delta delta; escapement_delta delta;
link.Read<float>(&delta.nonspace); link.Read<float>(&delta.nonspace);
link.Read<float>(&delta.space); link.Read<float>(&delta.space);
int32 numChars; int32 numChars;
link.Read<int32>(&numChars); link.Read<int32>(&numChars);
@@ -1897,7 +1902,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// 6) float - false bold width // 6) float - false bold width
// 7) uint8 - spacing // 7) uint8 - spacing
// 8) uint32 - flags // 8) uint32 - flags
// 9) font_metric_mode - mode // 9) font_metric_mode - mode
// 10) bool - string escapement // 10) bool - string escapement
@@ -1909,14 +1914,14 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// Returns: // Returns:
// 1) BRect - rects with numChar entries // 1) BRect - rects with numChar entries
uint16 famid, styid; uint16 famid, styid;
uint32 flags; uint32 flags;
float ptsize, rotation, shear, falseBoldWidth; float ptsize, rotation, shear, falseBoldWidth;
uint8 spacing; uint8 spacing;
font_metric_mode mode; font_metric_mode mode;
bool string_escapement; bool string_escapement;
link.Read<uint16>(&famid); link.Read<uint16>(&famid);
link.Read<uint16>(&styid); link.Read<uint16>(&styid);
link.Read<float>(&ptsize); link.Read<float>(&ptsize);
@@ -1930,7 +1935,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
escapement_delta delta; escapement_delta delta;
link.Read<escapement_delta>(&delta); link.Read<escapement_delta>(&delta);
int32 numChars; int32 numChars;
link.Read<int32>(&numChars); link.Read<int32>(&numChars);
@@ -1983,7 +1988,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// 6) float - false bold width // 6) float - false bold width
// 7) uint8 - spacing // 7) uint8 - spacing
// 8) uint32 - flags // 8) uint32 - flags
// 9) font_metric_mode - mode // 9) font_metric_mode - mode
// 10) int32 numStrings // 10) int32 numStrings
@@ -1993,13 +1998,13 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// Returns: // Returns:
// 1) BRect - rects with numStrings entries // 1) BRect - rects with numStrings entries
uint16 famid, styid; uint16 famid, styid;
uint32 flags; uint32 flags;
float ptsize, rotation, shear, falseBoldWidth; float ptsize, rotation, shear, falseBoldWidth;
uint8 spacing; uint8 spacing;
font_metric_mode mode; font_metric_mode mode;
link.Read<uint16>(&famid); link.Read<uint16>(&famid);
link.Read<uint16>(&styid); link.Read<uint16>(&styid);
link.Read<float>(&ptsize); link.Read<float>(&ptsize);
@@ -2012,7 +2017,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
int32 numStrings; int32 numStrings;
link.Read<int32>(&numStrings); link.Read<int32>(&numStrings);
escapement_delta deltaArray[numStrings]; escapement_delta deltaArray[numStrings];
char *stringArray[numStrings]; char *stringArray[numStrings];
int32 lengthArray[numStrings]; int32 lengthArray[numStrings];
@@ -2238,7 +2243,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
if (colorMap != NULL) { if (colorMap != NULL) {
fLink.StartMessage(B_OK); fLink.StartMessage(B_OK);
fLink.Attach<color_map>(*colorMap); fLink.Attach<color_map>(*colorMap);
} else } else
fLink.StartMessage(B_ERROR); fLink.StartMessage(B_ERROR);
fLink.Flush(); fLink.Flush();
@@ -2503,22 +2508,22 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
fLink.Flush(); fLink.Flush();
break; break;
} }
case AS_GET_ACCELERANT_PATH: case AS_GET_ACCELERANT_PATH:
{ {
int32 index; int32 index;
fLink.Read<int32>(&index); fLink.Read<int32>(&index);
BString path; BString path;
status_t status = fDesktop->HWInterface()->GetAccelerantPath(path); status_t status = fDesktop->HWInterface()->GetAccelerantPath(path);
fLink.StartMessage(status); fLink.StartMessage(status);
if (status == B_OK) if (status == B_OK)
fLink.AttachString(path.String()); fLink.AttachString(path.String());
fLink.Flush(); fLink.Flush();
break; break;
} }
case AS_GET_DRIVER_PATH: case AS_GET_DRIVER_PATH:
{ {
int32 index; int32 index;
@@ -2747,7 +2752,7 @@ ServerApp::CreatePicture(const ServerPicture *original)
if (picture != NULL) if (picture != NULL)
fPictureList.AddItem(picture); fPictureList.AddItem(picture);
return picture; return picture;
} }
@@ -2755,7 +2760,7 @@ ServerApp::CreatePicture(const ServerPicture *original)
ServerPicture * ServerPicture *
ServerApp::FindPicture(const int32 &token) const ServerApp::FindPicture(const int32 &token) const
{ {
// TODO: we need to make sure the picture is ours?! // TODO: we need to make sure the picture is ours?!
ServerPicture* picture; ServerPicture* picture;
if (gTokenSpace.GetToken(token, kPictureToken, (void**)&picture) == B_OK) if (gTokenSpace.GetToken(token, kPictureToken, (void**)&picture) == B_OK)
return picture; return picture;
@@ -2770,10 +2775,10 @@ ServerApp::DeletePicture(const int32 &token)
ServerPicture *picture = FindPicture(token); ServerPicture *picture = FindPicture(token);
if (picture == NULL) if (picture == NULL)
return false; return false;
if (!fPictureList.RemoveItem(picture)) if (!fPictureList.RemoveItem(picture))
return false; return false;
delete picture; delete picture;
return true; return true;