Fixed two different bugs that could cause bug #896:

* the app's Activate() method was called unsafely; the ServerApp pointer could
  have become invalid in the mean time.
* when hiding a floating window (because its parent got hidden) that had focus
  or even was the mouse event window (was currently dragged over the screen)
  the focus was not moved to another window.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19075 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-10-17 20:44:13 +00:00
parent 7dfa04527c
commit 8c68eab694
1 changed files with 29 additions and 16 deletions

View File

@ -496,7 +496,7 @@ Desktop::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
for (int32 i = 0; i < count; i++) {
ServerApp *app = fApplications.ItemAt(i);
if (app != NULL && app->Thread() == thread) {
if (app->Thread() == thread) {
fApplications.RemoveItemAt(i);
removeApp = app;
break;
@ -631,7 +631,7 @@ Desktop::BroadcastToAllApps(int32 code)
{
BAutolock locker(fApplicationsLock);
for (int32 i = 0; i < fApplications.CountItems(); i++) {
for (int32 i = fApplications.CountItems(); i-- > 0;) {
fApplications.ItemAt(i)->PostMessage(code);
}
}
@ -1007,9 +1007,16 @@ Desktop::_UpdateFloating(int32 previousWorkspace, int32 nextWorkspace,
}
} else if (_Windows(previousWorkspace).HasWindow(floating)) {
// was visible, but is no longer
if (fMouseEventWindow == floating)
fMouseEventWindow = NULL;
_Windows(previousWorkspace).RemoveWindow(floating);
floating->SetCurrentWorkspace(-1);
_HideWindow(floating);
if (FocusWindow() == floating)
SetFocusWindow(_CurrentWindows().LastWindow());
}
}
}
@ -1191,35 +1198,41 @@ Desktop::SetFocusWindow(WindowLayer* focus)
return;
}
ServerApp* oldActiveApp = NULL;
ServerApp* newActiveApp = NULL;
team_id oldActiveApp = -1;
team_id newActiveApp = -1;
if (fFocus != NULL) {
fFocus->SetFocus(false);
oldActiveApp = fFocus->ServerWindow()->App();
oldActiveApp = fFocus->ServerWindow()->App()->ClientTeam();
}
fFocus = focus;
if (fFocus != NULL) {
fFocus->SetFocus(true);
newActiveApp = fFocus->ServerWindow()->App();
newActiveApp = fFocus->ServerWindow()->App()->ClientTeam();
}
if (newActiveApp == -1) {
// make sure the cursor is visible
HWInterface()->SetCursorVisible(true);
}
UnlockAllWindows();
// change the "active" app if appropriate
if (oldActiveApp != newActiveApp) {
if (oldActiveApp) {
oldActiveApp->Activate(false);
}
if (oldActiveApp == newActiveApp)
return;
if (newActiveApp) {
newActiveApp->Activate(true);
} else {
// make sure the cursor is visible
HWInterface()->SetCursorVisible(true);
}
BAutolock locker(fApplicationsLock);
for (int32 i = 0; i < fApplications.CountItems(); i++) {
ServerApp *app = fApplications.ItemAt(i);
if (oldActiveApp != -1 && app->ClientTeam() == oldActiveApp)
app->Activate(false);
else if (newActiveApp != -1 && app->ClientTeam() == newActiveApp)
app->Activate(true);
}
}