diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index 48da259d5f..e3642e0202 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -478,6 +478,7 @@ BWindow::Minimize(bool minimize) fLink->StartMessage(AS_MINIMIZE_WINDOW); fLink->Attach(minimize); + fLink->Attach(fShowLevel); fLink->Flush(); Unlock(); @@ -2038,25 +2039,21 @@ BWindow::ResizeTo(float width, float height) void BWindow::Show() { - bool isLocked = this->IsLocked(); - - fShowLevel--; - - if (fShowLevel == 0) { - STRACE(("BWindow(%s): sending AS_SHOW_WINDOW message...\n", Name())); - if (Lock()) { - fLink->StartMessage(AS_SHOW_WINDOW); - fLink->Flush(); - Unlock(); - } + if (!fRunCalled) { + // this is the fist time Show() is called, which implicetly runs the looper + Run(); } - // if it's the fist time Show() is called... start the Looper thread. - if (Thread() == B_ERROR) { - // normally this won't happen, but I want to be sure! - if (!isLocked) - Lock(); - Run(); + if (Lock()) { + fShowLevel++; + + if (fShowLevel == 1) { + STRACE(("BWindow(%s): sending AS_SHOW_WINDOW message...\n", Name())); + fLink->StartMessage(AS_SHOW_WINDOW); + fLink->Flush(); + } + + Unlock(); } } @@ -2064,19 +2061,22 @@ BWindow::Show() void BWindow::Hide() { - if (fShowLevel == 0 && Lock()) { + if (!Lock()) + return; + + if (--fShowLevel == 0) { fLink->StartMessage(AS_HIDE_WINDOW); fLink->Flush(); - Unlock(); } - fShowLevel++; + + Unlock(); } bool BWindow::IsHidden() const { - return fShowLevel > 0; + return fShowLevel <= 0; } @@ -2177,7 +2177,7 @@ BWindow::_InitData(BRect frame, const char* title, window_look look, fInTransaction = false; fActive = false; - fShowLevel = 1; + fShowLevel = 0; fTopView = NULL; fFocus = NULL; diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index ff9a94e654..724f504a2d 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -544,9 +544,16 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) case AS_MINIMIZE_WINDOW: { DTRACE(("ServerWindow %s: Message AS_MINIMIZE_WINDOW\n", Title())); + int32 showLevel; bool minimize; - if (link.Read(&minimize) == B_OK) { - // TODO: this actually needs to take the window's show/hide counter into account + + link.Read(&minimize); + if (link.Read(&showLevel) == B_OK) { + if (showLevel <= 0) { + // window is currently hidden - ignore the minimize request + break; + } + if (minimize && !fWindowLayer->IsHidden()) _Hide(); else if (!minimize && fWindowLayer->IsHidden())