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
This commit is contained in:
John Scipione 2017-10-19 16:48:32 -07:00
parent c3c3360f40
commit c0dc265c3b
6 changed files with 29 additions and 14 deletions

View File

@ -660,6 +660,7 @@ TBarApp::MessageReceived(BMessage* message)
} }
// fall-through // fall-through
case kRealignReplicants:
case kShowHideTime: case kShowHideTime:
case kShowSeconds: case kShowSeconds:
case kShowDayOfWeek: case kShowDayOfWeek:

View File

@ -76,6 +76,9 @@ const int32 kIconCacheCount = (kMaximumIconSize - kMinimumIconSize)
// update preferences message constant // update preferences message constant
const uint32 kUpdatePreferences = 'Pref'; const uint32 kUpdatePreferences = 'Pref';
// realign replicants message constant
const uint32 kRealignReplicants = 'Algn';
/* --------------------------------------------- */ /* --------------------------------------------- */
class BBitmap; class BBitmap;

View File

@ -251,6 +251,7 @@ TBarView::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case B_LOCALE_CHANGED: case B_LOCALE_CHANGED:
case kRealignReplicants:
case kShowHideTime: case kShowHideTime:
case kShowSeconds: case kShowSeconds:
case kShowDayOfWeek: case kShowDayOfWeek:

View File

@ -379,6 +379,7 @@ TDeskbarMenu::ResetTargets()
case kRebootSystem: case kRebootSystem:
case kSuspendSystem: case kSuspendSystem:
case kShutdownSystem: case kShutdownSystem:
case kRealignReplicants:
case kShowHideTime: case kShowHideTime:
case kShowSeconds: case kShowSeconds:
case kShowDayOfWeek: case kShowDayOfWeek:

View File

@ -276,11 +276,8 @@ TReplicantTray::MessageReceived(BMessage* message)
return; return;
fTime->Update(); fTime->Update();
// time string reformat -> realign // time string reformat -> realign
RealignReplicants(); goto realignReplicants;
AdjustPlacement();
break;
case kShowHideTime: case kShowHideTime:
// from context menu in clock and in this view // from context menu in clock and in this view
@ -294,9 +291,7 @@ TReplicantTray::MessageReceived(BMessage* message)
fTime->SetShowSeconds(!fTime->ShowSeconds()); fTime->SetShowSeconds(!fTime->ShowSeconds());
// time string reformat -> realign // time string reformat -> realign
RealignReplicants(); goto realignReplicants;
AdjustPlacement();
break;
case kShowDayOfWeek: case kShowDayOfWeek:
if (fTime == NULL) if (fTime == NULL)
@ -305,9 +300,7 @@ TReplicantTray::MessageReceived(BMessage* message)
fTime->SetShowDayOfWeek(!fTime->ShowDayOfWeek()); fTime->SetShowDayOfWeek(!fTime->ShowDayOfWeek());
// time string reformat -> realign // time string reformat -> realign
RealignReplicants(); goto realignReplicants;
AdjustPlacement();
break;
case kShowTimeZone: case kShowTimeZone:
if (fTime == NULL) if (fTime == NULL)
@ -316,9 +309,7 @@ TReplicantTray::MessageReceived(BMessage* message)
fTime->SetShowTimeZone(!fTime->ShowTimeZone()); fTime->SetShowTimeZone(!fTime->ShowTimeZone());
// time string reformat -> realign // time string reformat -> realign
RealignReplicants(); goto realignReplicants;
AdjustPlacement();
break;
case kGetClockSettings: case kGetClockSettings:
{ {
@ -345,6 +336,12 @@ TReplicantTray::MessageReceived(BMessage* message)
break; break;
#endif #endif
case kRealignReplicants:
realignReplicants:
RealignReplicants();
AdjustPlacement();
break;
default: default:
BView::MessageReceived(message); BView::MessageReceived(message);
break; break;

View File

@ -440,8 +440,20 @@ PowerStatusView::Update(bool force)
width = 8; width = 8;
} }
if (width != Bounds().Width()) if (width != Bounds().Width()) {
ResizeTo(width, Bounds().Height()); 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 if (force || wasOnline != fOnline