From 9b5a183539f2b7eb48da0e25a9470ebd4e7cc08c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 27 Feb 2006 16:45:58 +0000 Subject: [PATCH] * Fixed BWindow::Show()/Hide(): fShowLevel was changed and checked without holding the window lock. * Run() is now called before creating the window in the app_server when Show() is called for the first time (which is now checked with fRunCalled instead of some thread arithmetics). * Minimize() now sends the show level of a window to the app_server, so that it can actually determine if minimizing or maximizing the window should have any effect. This fixes bug #225. * fShowLevel's meaning is now reversed; when it's above zero, it now means the window is shown (before, a level less than 1 meant shown). This definitely better fits its name :) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16536 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Window.cpp | 44 ++++++++++++++++---------------- src/servers/app/ServerWindow.cpp | 11 ++++++-- 2 files changed, 31 insertions(+), 24 deletions(-) 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())