From c0dc265c3b3917a3eca1c7f2f952f7e8b2e8b4dc Mon Sep 17 00:00:00 2001 From: John Scipione Date: Thu, 19 Oct 2017 16:48:32 -0700 Subject: [PATCH] Deskbar & PowerStatus: Realign Replicants Added a new message constant to Deskbar kRealignReplicants which is called to realign replicant icons. Add routing so that if you knock on Deskbar's front door (Application) it will get routed to the right view, in this case the repliant tray that knows how to realign replicants. Send a message with this newly created constant in PowerStatus when the width changes because you turned the label on or off. This makes it so that when you show or hide the battery percentage it will not overrun the clock. Realign Replicants is a common case. Fixes the rest of #8641 --- src/apps/deskbar/BarApp.cpp | 1 + src/apps/deskbar/BarApp.h | 3 +++ src/apps/deskbar/BarView.cpp | 1 + src/apps/deskbar/DeskbarMenu.cpp | 1 + src/apps/deskbar/StatusView.cpp | 23 ++++++++++------------- src/apps/powerstatus/PowerStatusView.cpp | 14 +++++++++++++- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index c6949f90a2..03ff77069d 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -660,6 +660,7 @@ TBarApp::MessageReceived(BMessage* message) } // fall-through + case kRealignReplicants: case kShowHideTime: case kShowSeconds: case kShowDayOfWeek: diff --git a/src/apps/deskbar/BarApp.h b/src/apps/deskbar/BarApp.h index 362b62db0b..d85763848d 100644 --- a/src/apps/deskbar/BarApp.h +++ b/src/apps/deskbar/BarApp.h @@ -76,6 +76,9 @@ const int32 kIconCacheCount = (kMaximumIconSize - kMinimumIconSize) // update preferences message constant const uint32 kUpdatePreferences = 'Pref'; +// realign replicants message constant +const uint32 kRealignReplicants = 'Algn'; + /* --------------------------------------------- */ class BBitmap; diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 64f478d6e7..22b0aaa7c6 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -251,6 +251,7 @@ TBarView::MessageReceived(BMessage* message) { switch (message->what) { case B_LOCALE_CHANGED: + case kRealignReplicants: case kShowHideTime: case kShowSeconds: case kShowDayOfWeek: diff --git a/src/apps/deskbar/DeskbarMenu.cpp b/src/apps/deskbar/DeskbarMenu.cpp index 144b1bc5a7..ac4a288085 100644 --- a/src/apps/deskbar/DeskbarMenu.cpp +++ b/src/apps/deskbar/DeskbarMenu.cpp @@ -379,6 +379,7 @@ TDeskbarMenu::ResetTargets() case kRebootSystem: case kSuspendSystem: case kShutdownSystem: + case kRealignReplicants: case kShowHideTime: case kShowSeconds: case kShowDayOfWeek: diff --git a/src/apps/deskbar/StatusView.cpp b/src/apps/deskbar/StatusView.cpp index 6d720fa7e2..7321ac6475 100644 --- a/src/apps/deskbar/StatusView.cpp +++ b/src/apps/deskbar/StatusView.cpp @@ -276,11 +276,8 @@ TReplicantTray::MessageReceived(BMessage* message) return; fTime->Update(); - // time string reformat -> realign - RealignReplicants(); - AdjustPlacement(); - break; + goto realignReplicants; case kShowHideTime: // from context menu in clock and in this view @@ -294,9 +291,7 @@ TReplicantTray::MessageReceived(BMessage* message) fTime->SetShowSeconds(!fTime->ShowSeconds()); // time string reformat -> realign - RealignReplicants(); - AdjustPlacement(); - break; + goto realignReplicants; case kShowDayOfWeek: if (fTime == NULL) @@ -305,9 +300,7 @@ TReplicantTray::MessageReceived(BMessage* message) fTime->SetShowDayOfWeek(!fTime->ShowDayOfWeek()); // time string reformat -> realign - RealignReplicants(); - AdjustPlacement(); - break; + goto realignReplicants; case kShowTimeZone: if (fTime == NULL) @@ -316,9 +309,7 @@ TReplicantTray::MessageReceived(BMessage* message) fTime->SetShowTimeZone(!fTime->ShowTimeZone()); // time string reformat -> realign - RealignReplicants(); - AdjustPlacement(); - break; + goto realignReplicants; case kGetClockSettings: { @@ -345,6 +336,12 @@ TReplicantTray::MessageReceived(BMessage* message) break; #endif + case kRealignReplicants: +realignReplicants: + RealignReplicants(); + AdjustPlacement(); + break; + default: BView::MessageReceived(message); break; diff --git a/src/apps/powerstatus/PowerStatusView.cpp b/src/apps/powerstatus/PowerStatusView.cpp index 8539a24554..a13edc3375 100644 --- a/src/apps/powerstatus/PowerStatusView.cpp +++ b/src/apps/powerstatus/PowerStatusView.cpp @@ -440,8 +440,20 @@ PowerStatusView::Update(bool force) width = 8; } - if (width != Bounds().Width()) + if (width != Bounds().Width()) { ResizeTo(width, Bounds().Height()); + + // inform Deskbar that it needs to realign its replicants + BWindow* window = Window(); + if (window != NULL) { + BView* view = window->FindView("Status"); + if (view != NULL) { + BMessenger target((BHandler*)view); + BMessage realignReplicants('Algn'); + target.SendMessage(&realignReplicants); + } + } + } } if (force || wasOnline != fOnline