diff --git a/src/servers/app/server/Desktop.cpp b/src/servers/app/server/Desktop.cpp index 86741b8ef4..0f763099f4 100644 --- a/src/servers/app/server/Desktop.cpp +++ b/src/servers/app/server/Desktop.cpp @@ -327,17 +327,17 @@ void Desktop::MouseEventHandler(int32 code, BPortLink& msg) { fGeneralLock.Lock(); rl->fMainLock.Lock(); -#if 0 -printf("Target: %s\n", target->GetName()); -printf("Front: %s\n", ws->FrontLayer()->GetName()); -printf("Focus: %s\n", ws->FocusLayer()->GetName()); -#endif - if (target != ws->FrontLayer()) + + STRACE(("Target: %s\n", target->GetName())); + STRACE(("Front: %s\n", ws->FrontLayer()->GetName())); + STRACE(("Focus: %s\n", ws->FocusLayer()->GetName())); + + WinBorder *previousFocus=NULL; + WinBorder *activeFocus=NULL; + BRegion invalidRegion; + + if (target!=ws->FrontLayer()) { - WinBorder *previousFocus=NULL; - WinBorder *activeFocus=NULL; - BRegion invalidRegion; - ws->BringToFrontANormalWindow(target); ws->SearchAndSetNewFront(target); previousFocus = ws->FocusLayer(); @@ -351,7 +351,7 @@ printf("Focus: %s\n", ws->FocusLayer()->GetName()); else target->MouseDown(evt, false); - // may be or may be empty. + // may or may not be empty. // TODO: B_MOUSE_DOWN: what if modal of floating windows are in front of us? invalidRegion.Include(&(activeFocus->fFull)); @@ -369,11 +369,10 @@ printf("Focus: %s\n", ws->FocusLayer()->GetName()); } fMouseTarget = target; -#if 0 -printf("2Target: %s\n", target->GetName()); -printf("2Front: %s\n", ws->FrontLayer()->GetName()); -printf("2Focus: %s\n", ws->FocusLayer()->GetName()); -#endif + + STRACE(("2Target: %s\n", target->GetName())); + STRACE(("2Front: %s\n", ws->FrontLayer()->GetName())); + STRACE(("2Focus: %s\n", ws->FocusLayer()->GetName())); activeFocus->Window()->Unlock(); } @@ -386,6 +385,39 @@ printf("2Focus: %s\n", ws->FocusLayer()->GetName()); target->MouseDown(evt, true); target->Window()->Unlock(); } + else + { + previousFocus = ws->FocusLayer(); + ws->SearchAndSetNewFocus(target); + activeFocus = ws->FocusLayer(); + + activeFocus->Window()->Lock(); + + if (target == activeFocus && target->Window()->Flags() & B_WILL_ACCEPT_FIRST_CLICK) + target->MouseDown(evt, true); + else + target->MouseDown(evt, false); + + // may or may not be empty. + + // TODO: B_MOUSE_DOWN: what if modal of floating windows are in front of us? + invalidRegion.Include(&(activeFocus->fFull)); + invalidRegion.Include(&(activeFocus->fTopLayer->fFull)); + activeFocus->fParent->RebuildAndForceRedraw(invalidRegion, activeFocus); + + if (previousFocus != activeFocus && previousFocus) + { + if (previousFocus->fVisible.CountRects() > 0) + { + invalidRegion.MakeEmpty(); + invalidRegion.Include(&(previousFocus->fVisible)); + activeFocus->fParent->Invalidate(invalidRegion); + } + } + fMouseTarget = target; + + activeFocus->Window()->Unlock(); + } } rl->fMainLock.Unlock(); diff --git a/src/servers/app/server/Workspace.cpp b/src/servers/app/server/Workspace.cpp index 0c1621e7be..d03f38f3ae 100644 --- a/src/servers/app/server/Workspace.cpp +++ b/src/servers/app/server/Workspace.cpp @@ -28,6 +28,8 @@ // 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 +#include #include #include @@ -1093,7 +1095,7 @@ void Workspace::SearchAndSetNewFocus(WinBorder *preferred) preferred = fBottomItem? fBottomItem->layerPtr : NULL; bool selectOthers = false; - ListData *item = NULL; + ListData *item=NULL; for(item = fBottomItem; item != NULL; item = item->upperItem) { @@ -1155,10 +1157,34 @@ void Workspace::SearchAndSetNewFocus(WinBorder *preferred) if(item != fFocusItem) { - // TODO: redraw old item in inactive colors & send message to client - // TODO: redraw new item in active colors & send message to client - // TODO: Rebuild & Redraw. - fFocusItem = item; + if(fFocusItem) + { + ListData *oldItem=fFocusItem; + + oldItem->layerPtr->HighlightDecorator(false); + + BMessage inactive(B_WINDOW_ACTIVATED); + inactive.AddInt64("when",system_time()); + inactive.AddBool("active",false); + oldItem->layerPtr->Window()->Lock(); + oldItem->layerPtr->Window()->SendMessageToClient(&inactive); + oldItem->layerPtr->Window()->Unlock(); + } + + fFocusItem=item; + + if(fFocusItem) + { + fFocusItem->layerPtr->HighlightDecorator(true); + + BMessage active(B_WINDOW_ACTIVATED); + active.AddInt64("when",system_time()); + active.AddBool("active",true); + + fFocusItem->layerPtr->Window()->Lock(); + fFocusItem->layerPtr->Window()->SendMessageToClient(&active); + fFocusItem->layerPtr->Window()->Unlock(); + } } }