hrev45524 adds 1 changeset to branch 'master' old head: 1e77e4f85290ba74a1cdcc65f59e829cf71ef530 new head: 30e6af93e4ae245281e73a10e5ffcbd94ce38dc8 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=30e6af9+%5E1e77e4f ---------------------------------------------------------------------------- 30e6af9: Eliminate background app and Deskbar app checks This is a follow up on the fix for #9632. Now that the group list in Deskbar never deals with background apps or the Deskbar app itself we can simplify the code by eliminating the checks, especially in Switcher.cpp (Twitcher). Checking for background apps and Deskbar has also been eliminated from TExpandoMenuBar and TTeamMenu. The single point of entry for these checks is in TBarApp::AddTeam(). In Switcher.cpp remove OKToUse() since the list is assumed to contain only valid entries. TSwitchManager::CountVisibleGroups() also got removed because all groups are visible. TSwitchManager::_FindNextValidApp(), TSwitchManager::QuitApp(), TIconView::ItemAtPoint(), TIconView::ScrollTo(), and TIconView::FrameOf() all got simplified significantly. [ John Scipione <jscipione@xxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev45524 Commit: 30e6af93e4ae245281e73a10e5ffcbd94ce38dc8 URL: http://cgit.haiku-os.org/haiku/commit/?id=30e6af9 Author: John Scipione <jscipione@xxxxxxxxx> Date: Wed Apr 17 22:32:43 2013 UTC Ticket: https://dev.haiku-os.org/ticket/9632 ---------------------------------------------------------------------------- 4 files changed, 70 insertions(+), 195 deletions(-) src/apps/deskbar/ExpandoMenuBar.cpp | 40 +++---- src/apps/deskbar/Switcher.cpp | 180 +++++++------------------------- src/apps/deskbar/Switcher.h | 1 - src/apps/deskbar/TeamMenu.cpp | 44 ++++---- ---------------------------------------------------------------------------- diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index e03439d..6460544 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -167,21 +167,11 @@ TExpandoMenuBar::MessageReceived(BMessage* message) BBitmap* icon = NULL; message->FindPointer("icon", (void**)&icon); - const char* signature; - if (message->FindString("sig", &signature) == B_OK - &&strcasecmp(signature, kDeskbarSignature) == 0) { - delete teams; - delete icon; - break; - } + const char* signature = NULL; + message->FindString("sig", &signature); - uint32 flags; - if (message->FindInt32("flags", ((int32*) &flags)) == B_OK - && (flags & B_BACKGROUND_APP) != 0) { - delete teams; - delete icon; - break; - } + uint32 flags = 0; + message->FindInt32("flags", ((int32*) &flags)); const char* name = NULL; message->FindString("name", &name); @@ -564,19 +554,15 @@ TExpandoMenuBar::BuildItems() for (int32 i = 0; i < count; i++) { // add items back BarTeamInfo* barInfo = (BarTeamInfo*)fTeamList.ItemAt(i); - - if ((barInfo->flags & B_BACKGROUND_APP) == 0 - && strcasecmp(barInfo->sig, kDeskbarSignature) != 0) { - TTeamMenuItem* item = new TTeamMenuItem(barInfo->teams, - barInfo->icon, barInfo->name, barInfo->sig, itemWidth, - itemHeight, fDrawLabel, fVertical); - - if (settings->trackerAlwaysFirst - && strcmp(barInfo->sig, kTrackerSignature) == 0) { - AddItem(item, 0); - } else - AddItem(item); - } + TTeamMenuItem* item = new TTeamMenuItem(barInfo->teams, + barInfo->icon, barInfo->name, barInfo->sig, itemWidth, + itemHeight, fDrawLabel, fVertical); + + if (settings->trackerAlwaysFirst + && strcmp(barInfo->sig, kTrackerSignature) == 0) { + AddItem(item, 0); + } else + AddItem(item); } if (CountItems() == 0) { diff --git a/src/apps/deskbar/Switcher.cpp b/src/apps/deskbar/Switcher.cpp index a9e2572..d56b1a0 100644 --- a/src/apps/deskbar/Switcher.cpp +++ b/src/apps/deskbar/Switcher.cpp @@ -295,24 +295,6 @@ IsWindowOK(const window_info* windowInfo) } -bool -OKToUse(const TTeamGroup* teamGroup) -{ - if (teamGroup == NULL) - return false; - - // skip background applications - if ((teamGroup->Flags() & B_BACKGROUND_APP) != 0) - return false; - - // skip Deskbar itself - if (strcasecmp(teamGroup->Signature(), kDeskbarSignature) == 0) - return false; - - return true; -} - - int SmartStrcmp(const char* s1, const char* s2) { @@ -489,12 +471,10 @@ TSwitchManager::MessageReceived(BMessage* message) if (tinfo->TeamList()->HasItem((void*)(addr_t)teamID)) { fGroupList.RemoveItem(i); - if (OKToUse(tinfo)) { - fWindow->Redraw(i); - if (i <= fCurrentIndex) { - fCurrentIndex--; - CycleApp(true); - } + fWindow->Redraw(i); + if (i <= fCurrentIndex) { + fCurrentIndex--; + CycleApp(true); } delete tinfo; break; @@ -541,8 +521,7 @@ TSwitchManager::MessageReceived(BMessage* message) signature); fGroupList.AddItem(tinfo); - if (OKToUse(tinfo)) - fWindow->Redraw(fGroupList.CountItems() - 1); + fWindow->Redraw(fGroupList.CountItems() - 1); break; } @@ -811,23 +790,6 @@ TSwitchManager::QuickSwitch(BMessage* message) } -int32 -TSwitchManager::CountVisibleGroups() -{ - int32 result = 0; - int32 count = fGroupList.CountItems(); - - for (int32 i = 0; i < count; i++) { - if (!OKToUse((TTeamGroup*)fGroupList.ItemAt(i))) - continue; - - result++; - } - - return result; -} - - void TSwitchManager::CycleWindow(bool forward, bool wrap) { @@ -880,31 +842,18 @@ TSwitchManager::_FindNextValidApp(bool forward) if (fGroupList.IsEmpty()) return false; - int32 startIndex = fCurrentIndex; int32 max = fGroupList.CountItems(); - - for (;;) { - if (forward) { - fCurrentIndex++; - if (fCurrentIndex >= max) - fCurrentIndex = 0; - } else { - fCurrentIndex--; - if (fCurrentIndex < 0) - fCurrentIndex = max - 1; - } - - if (fCurrentIndex == startIndex) { - // we've gone completely through the list without finding - // a good app. Oh well. - break; - } - - if (OKToUse((TTeamGroup*)fGroupList.ItemAt(fCurrentIndex))) - return true; + if (forward) { + fCurrentIndex++; + if (fCurrentIndex >= max) + fCurrentIndex = 0; + } else { + fCurrentIndex--; + if (fCurrentIndex < 0) + fCurrentIndex = max - 1; } - return false; + return true; } @@ -914,9 +863,6 @@ TSwitchManager::SwitchToApp(int32 previousIndex, int32 newIndex, bool forward) int32 previousSlot = fCurrentSlot; fCurrentIndex = newIndex; - if (!OKToUse((TTeamGroup *)fGroupList.ItemAt(fCurrentIndex))) - _FindNextValidApp(forward); - fCurrentSlot = fWindow->SlotOf(fCurrentIndex); fCurrentWindow = 0; @@ -1045,27 +991,19 @@ TSwitchManager::ActivateApp(bool forceShow, bool allowWorkspaceSwitch) } +/*! + \brief quit all teams in this group +*/ void TSwitchManager::QuitApp() { - // check if we're in the last slot already (the last usable team group) - - TTeamGroup* teamGroup; - int32 count = 0; - - int32 groupCount = fGroupList.CountItems(); - for (int32 i = fCurrentIndex + 1; i < groupCount; i++) { - teamGroup = (TTeamGroup*)fGroupList.ItemAt(i); - - if (!OKToUse(teamGroup)) - continue; - - count++; - } - - teamGroup = (TTeamGroup*)fGroupList.ItemAt(fCurrentIndex); + // we should not be trying to quit an app if we have an empty list + if (fGroupList.IsEmpty()) + return; - if (count == 0) { + TTeamGroup* teamGroup = (TTeamGroup*)fGroupList.ItemAt(fCurrentIndex); + if (fCurrentIndex == fGroupList.CountItems() - 1) { + // if we're in the last slot already (the last usable team group) // switch to previous app in the list so that we don't jump to // the start of the list (try to keep the same position when // the apps at the current index go away) @@ -1073,12 +1011,11 @@ TSwitchManager::QuitApp() } // send the quit request to all teams in this group - for (int32 i = teamGroup->TeamList()->CountItems() - 1; i >= 0; i--) { team_id team = (addr_t)teamGroup->TeamList()->ItemAt(i); app_info info; if (be_roster->GetRunningAppInfo(team, &info) == B_OK) { - if (!strcasecmp(info.signature, kTrackerSignature)) { + if (strcasecmp(info.signature, kTrackerSignature) == 0) { // Tracker can't be quit this way continue; } @@ -1090,10 +1027,15 @@ TSwitchManager::QuitApp() } +/*! + \brief hide all teams in this group +*/ void TSwitchManager::HideApp() { - // hide all teams in this group + // we should not be trying to hide an app if we have an empty list + if (fGroupList.IsEmpty()) + return; TTeamGroup* teamGroup = (TTeamGroup*)fGroupList.ItemAt(fCurrentIndex); @@ -1316,8 +1258,8 @@ TBox::MouseDown(BPoint where) int32 newSlot = previousSlot - (kNumSlots - 1); if (newSlot < 0) newSlot = 0; - int32 newIndex = fIconView->IndexAt(newSlot); + int32 newIndex = fIconView->IndexAt(newSlot); fManager->SwitchToApp(previousIndex, newIndex, false); } } @@ -1333,8 +1275,7 @@ TBox::MouseDown(BPoint where) if (newIndex < 0) { // don't have a page full to scroll - int32 valid = fManager->CountVisibleGroups(); - newIndex = fIconView->IndexAt(valid - 1); + newIndex = fManager->GroupList()->CountItems() - 1; } fManager->SwitchToApp(previousIndex, newIndex, true); } @@ -2012,27 +1953,7 @@ TIconView::CenterOn(int32 index) int32 TIconView::ItemAtPoint(BPoint point) const { - float tmpPointVerticalIndex = (point.x / kSlotSize) - kCenterSlot; - if (tmpPointVerticalIndex < 0) - return -1; - - int32 pointVerticalIndex = (int32)tmpPointVerticalIndex; - - for (int32 i = 0, verticalIndex = 0; ; i++) { - - TTeamGroup* teamGroup = (TTeamGroup*)fManager->GroupList()->ItemAt(i); - if (teamGroup == NULL) - break; - - if (!OKToUse(teamGroup)) - continue; - - if (verticalIndex == pointVerticalIndex) - return i; - - verticalIndex++; - } - return -1; + return IndexAt((int32)(point.x / kSlotSize) - kCenterSlot); } @@ -2047,22 +1968,10 @@ TIconView::ScrollTo(BPoint where) int32 TIconView::IndexAt(int32 slot) const { - BList* list = fManager->GroupList(); - int32 count = list->CountItems(); - int32 slotIndex = 0; - - for (int32 i = 0; i < count; i++) { - TTeamGroup* teamGroup = (TTeamGroup*)list->ItemAt(i); - - if (!OKToUse(teamGroup)) - continue; + if (slot < 0 || slot >= fManager->GroupList()->CountItems()) + return -1; - if (slotIndex == slot) { - return i; - } - slotIndex++; - } - return -1; + return slot; } @@ -2078,20 +1987,9 @@ TIconView::SlotOf(int32 index) const BRect TIconView::FrameOf(int32 index) const { - BList* list = fManager->GroupList(); - int32 visible = kCenterSlot - 1; + int32 visible = index + kCenterSlot; // first few slots in view are empty - TTeamGroup* teamGroup; - for (int32 i = 0; i <= index; i++) { - teamGroup = (TTeamGroup*)list->ItemAt(i); - - if (!OKToUse(teamGroup)) - continue; - - visible++; - } - return BRect(visible * kSlotSize, 0, (visible + 1) * kSlotSize - 1, kSlotSize - 1); } @@ -2109,10 +2007,6 @@ TIconView::DrawTeams(BRect update) for (int32 i = 0; i < count; i++) { TTeamGroup* teamGroup = (TTeamGroup*)list->ItemAt(i); - - if (!OKToUse(teamGroup)) - continue; - if (rect.Intersects(update) && teamGroup) { SetDrawingMode(B_OP_ALPHA); SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); diff --git a/src/apps/deskbar/Switcher.h b/src/apps/deskbar/Switcher.h index 7e868f7..ad5a0a6 100644 --- a/src/apps/deskbar/Switcher.h +++ b/src/apps/deskbar/Switcher.h @@ -63,7 +63,6 @@ public: int32 CurrentWindow(); int32 CurrentSlot(); BList* GroupList(); - int32 CountVisibleGroups(); void QuitApp(); void HideApp(); diff --git a/src/apps/deskbar/TeamMenu.cpp b/src/apps/deskbar/TeamMenu.cpp index 2ff8f45..4fb8273 100644 --- a/src/apps/deskbar/TeamMenu.cpp +++ b/src/apps/deskbar/TeamMenu.cpp @@ -91,30 +91,26 @@ TTeamMenu::AttachedToWindow() for (int32 i = 0; i < count; i++) { // add items back BarTeamInfo* barInfo = (BarTeamInfo*)teamList.ItemAt(i); - - if (((barInfo->flags & B_BACKGROUND_APP) == 0) - && (strcasecmp(barInfo->sig, kDeskbarSignature) != 0)) { - TTeamMenuItem* item = new TTeamMenuItem(barInfo->teams, - barInfo->icon, barInfo->name, barInfo->sig, - width, -1, !settings->hideLabels, true); - - if (settings->trackerAlwaysFirst - && strcmp(barInfo->sig, kTrackerSignature) == 0) { - AddItem(item, 0); - } else - AddItem(item); - - if (dragging && item != NULL) { - bool canhandle = (dynamic_cast<TBarApp*>(be_app))->BarView()-> - AppCanHandleTypes(item->Signature()); - if (item->IsEnabled() != canhandle) - item->SetEnabled(canhandle); - - BMenu* menu = item->Submenu(); - if (menu) - menu->SetTrackingHook(barview->MenuTrackingHook, - barview->GetTrackingHookData()); - } + TTeamMenuItem* item = new TTeamMenuItem(barInfo->teams, + barInfo->icon, barInfo->name, barInfo->sig, + width, -1, !settings->hideLabels, true); + + if (settings->trackerAlwaysFirst + && strcmp(barInfo->sig, kTrackerSignature) == 0) { + AddItem(item, 0); + } else + AddItem(item); + + if (dragging && item != NULL) { + bool canhandle = (dynamic_cast<TBarApp*>(be_app))->BarView()-> + AppCanHandleTypes(item->Signature()); + if (item->IsEnabled() != canhandle) + item->SetEnabled(canhandle); + + BMenu* menu = item->Submenu(); + if (menu) + menu->SetTrackingHook(barview->MenuTrackingHook, + barview->GetTrackingHookData()); } }