Ticket #9749: 0001-Notification_Server-Added-ability-to-choose-position.patch
File 0001-Notification_Server-Added-ability-to-choose-position.patch, 14.2 KB (added by , 7 years ago) |
---|
-
headers/private/notification/Notifications.h
From 69071c4b0afb005458b0ddd1f08eebde8bd0c8d1 Mon Sep 17 00:00:00 2001 From: Hrishi Hiraskar <hrishihiraskar@gmail.com> Date: Mon, 11 Dec 2017 16:24:02 +0530 Subject: [PATCH] Notification_Server: Added ability to choose position of notifications The feature gives user ability to choose the position of notifications out of Follow Deskbar, Lower Right, Lower Left, Upper Right and Upper Left. Fixes #9749 - Notification_Server: add the ability to choose the position of notifications (easy). --- headers/private/notification/Notifications.h | 5 + src/preferences/notifications/GeneralView.cpp | 84 +++++++++++++++ src/preferences/notifications/GeneralView.h | 5 + src/servers/notification/NotificationWindow.cpp | 136 ++++++++++++++++++------ src/servers/notification/NotificationWindow.h | 1 + src/servers/notification/Notifications.cpp | 1 + 6 files changed, 197 insertions(+), 35 deletions(-) diff --git a/headers/private/notification/Notifications.h b/headers/private/notification/Notifications.h index 18298a4270..2f3ac9ec4f 100644
a b 6 6 #define _NOTIFICATIONS_H 7 7 8 8 #include <Mime.h> 9 #include <View.h> 9 10 #include <String.h> 10 11 11 12 #define kNotificationServerSignature "application/x-vnd.Haiku-notification_server" 12 13 14 #define B_FOLLOW_DESKBAR B_FOLLOW_NONE 15 13 16 // Messages 14 17 const uint32 kNotificationMessage = 'nssm'; 15 18 … … extern const char* kAutoStartName; 21 24 extern const char* kTimeoutName; 22 25 extern const char* kWidthName; 23 26 extern const char* kIconSizeName; 27 extern const char* kNotificationPositionName; 24 28 25 29 // General default settings 26 30 const bool kDefaultAutoStart = true; … … const float kMinimumWidth = 300.0f; 32 36 const float kMaximumWidth = 1000.0f; 33 37 const int32 kWidthStep = 50; 34 38 const icon_size kDefaultIconSize = B_LARGE_ICON; 39 const uint32 kDefaultNotificationPosition = B_FOLLOW_DESKBAR; 35 40 36 41 #endif // _NOTIFICATIONS_H -
src/preferences/notifications/GeneralView.cpp
diff --git a/src/preferences/notifications/GeneralView.cpp b/src/preferences/notifications/GeneralView.cpp index bbd831f138..bde36889d6 100644
a b 43 43 const uint32 kToggleNotifications = '_TSR'; 44 44 const uint32 kWidthChanged = '_WIC'; 45 45 const uint32 kTimeoutChanged = '_TIC'; 46 const uint32 kPositionChanged = '_NPC'; 46 47 const uint32 kServerChangeTriggered = '_SCT'; 47 48 const BString kSampleMessageID("NotificationsSample"); 48 49 49 50 51 static int32 52 notification_position_to_index(uint32 notification_position) { 53 if (notification_position == B_FOLLOW_NONE) 54 return 0; 55 else if (notification_position == (B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM)) 56 return 1; 57 else if (notification_position == (B_FOLLOW_LEFT | B_FOLLOW_BOTTOM)) 58 return 2; 59 else if (notification_position == (B_FOLLOW_RIGHT | B_FOLLOW_TOP)) 60 return 3; 61 else if (notification_position == (B_FOLLOW_LEFT | B_FOLLOW_TOP)) 62 return 4; 63 return 0; 64 } 65 66 50 67 GeneralView::GeneralView(SettingsHost* host) 51 68 : 52 69 SettingsPane("general", host) … … GeneralView::GeneralView(SettingsHost* host) 87 104 B_TRANSLATE_COMMENT(minLabel.String(), "Slider low text"), 88 105 B_TRANSLATE_COMMENT(maxLabel.String(), "Slider high text")); 89 106 107 // Notification Position 108 fPositionMenu = new BPopUpMenu(B_TRANSLATE("Follow Deskbar")); 109 const char* positionLabels[] = { 110 B_TRANSLATE_MARK("Follow Deskbar"), 111 B_TRANSLATE_MARK("Lower right"), 112 B_TRANSLATE_MARK("Lower left"), 113 B_TRANSLATE_MARK("Upper right"), 114 B_TRANSLATE_MARK("Upper left") 115 }; 116 const uint32 positions[] = { 117 B_FOLLOW_DESKBAR, // Follow Deskbar 118 B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT, // Lower right 119 B_FOLLOW_BOTTOM | B_FOLLOW_LEFT, // Lower left 120 B_FOLLOW_TOP | B_FOLLOW_RIGHT, // Upper right 121 B_FOLLOW_TOP | B_FOLLOW_LEFT // Upper left 122 }; 123 for (int i=0; i < 5; i++) { 124 BMessage* message = new BMessage(kPositionChanged); 125 message->AddInt32(kNotificationPositionName, positions[i]); 126 127 fPositionMenu->AddItem(new BMenuItem(B_TRANSLATE_NOCOLLECT( 128 positionLabels[i]), message)); 129 } 130 BMenuField* positionField = new BMenuField(B_TRANSLATE("Position:"), 131 fPositionMenu); 132 90 133 box->AddChild(BLayoutBuilder::Group<>(B_VERTICAL) 91 134 .SetInsets(B_USE_DEFAULT_SPACING) 92 135 .Add(fWidthSlider) 93 136 .Add(fDurationSlider) 137 .Add(positionField) 94 138 .AddGlue() 95 139 .View()); 96 140 … … GeneralView::AttachedToWindow() 108 152 fNotificationBox->SetTarget(this); 109 153 fWidthSlider->SetTarget(this); 110 154 fDurationSlider->SetTarget(this); 155 fPositionMenu->SetTargetForItems(this); 111 156 } 112 157 113 158 … … GeneralView::MessageReceived(BMessage* msg) 134 179 SettingsPane::SettingsChanged(true); 135 180 break; 136 181 } 182 case kPositionChanged: 183 { 184 int32 position; 185 if (msg->FindInt32(kNotificationPositionName, &position) == B_OK) { 186 fNewPosition = position; 187 SettingsPane::SettingsChanged(true); 188 } 189 break; 190 } 137 191 default: 138 192 BView::MessageReceived(msg); 139 193 break; … … GeneralView::Load(BMessage& settings) 163 217 else 164 218 fOriginalIconSize = (icon_size)setting; 165 219 220 int32 position; 221 if (settings.FindInt32(kNotificationPositionName, &position) != B_OK) 222 fOriginalPosition = kDefaultNotificationPosition; 223 else 224 fOriginalPosition = position; 225 166 226 _EnableControls(); 167 227 168 228 return Revert(); … … GeneralView::Save(BMessage& settings) 184 244 icon_size iconSize = B_LARGE_ICON; 185 245 settings.AddInt32(kIconSizeName, (int32)iconSize); 186 246 247 settings.AddInt32(kNotificationPositionName, (int32)fNewPosition); 248 187 249 return B_OK; 188 250 } 189 251 … … GeneralView::Revert() 196 258 197 259 fWidthSlider->SetValue(fOriginalWidth / 50); 198 260 _SetWidthLabel(fOriginalWidth); 261 262 fNewPosition = fOriginalPosition; 263 BMenuItem* item = fPositionMenu->ItemAt( 264 notification_position_to_index(fNewPosition)); 265 if (item != NULL) 266 item->SetMarked(true); 199 267 200 268 return B_OK; 201 269 } … … GeneralView::RevertPossible() 212 280 if (fOriginalWidth != width) 213 281 return true; 214 282 283 if (fOriginalPosition != fNewPosition) 284 return true; 285 215 286 return false; 216 287 } 217 288 … … GeneralView::Defaults() 225 296 fWidthSlider->SetValue(kDefaultWidth / 50); 226 297 _SetWidthLabel(kDefaultWidth); 227 298 299 fNewPosition = kDefaultNotificationPosition; 300 BMenuItem* item = fPositionMenu->ItemAt( 301 notification_position_to_index(fNewPosition)); 302 if (item != NULL) 303 item->SetMarked(true); 304 228 305 return B_OK; 229 306 } 230 307 … … GeneralView::DefaultsPossible() 239 316 int32 width = fWidthSlider->Value() * 50; 240 317 if (kDefaultWidth != width) 241 318 return true; 319 320 if (kDefaultNotificationPosition != fNewPosition) 321 return true; 242 322 243 323 return false; 244 324 } … … GeneralView::_EnableControls() 257 337 bool enabled = fNotificationBox->Value() == B_CONTROL_ON; 258 338 fWidthSlider->SetEnabled(enabled); 259 339 fDurationSlider->SetEnabled(enabled); 340 BMenuItem* item = fPositionMenu->ItemAt( 341 notification_position_to_index(fOriginalPosition)); 342 if (item != NULL) 343 item->SetMarked(true); 260 344 } 261 345 262 346 -
src/preferences/notifications/GeneralView.h
diff --git a/src/preferences/notifications/GeneralView.h b/src/preferences/notifications/GeneralView.h index 0bd5a084b1..9106cee1b3 100644
a b 12 12 #include <Menu.h> 13 13 #include <MenuField.h> 14 14 #include <Mime.h> 15 #include <PopUpMenu.h> 15 16 #include <RadioButton.h> 16 17 #include <Slider.h> 17 18 #include <StringView.h> … … private: 40 41 BCheckBox* fNotificationBox; 41 42 BSlider* fDurationSlider; 42 43 BSlider* fWidthSlider; 44 BPopUpMenu* fPositionMenu; 45 43 46 44 47 int32 fOriginalTimeout; 45 48 float fOriginalWidth; 46 49 icon_size fOriginalIconSize; 50 uint32 fOriginalPosition; 51 uint32 fNewPosition; 47 52 48 53 void _EnableControls(); 49 54 void _SetWidthLabel(int32 value); -
src/servers/notification/NotificationWindow.cpp
diff --git a/src/servers/notification/NotificationWindow.cpp b/src/servers/notification/NotificationWindow.cpp index bad3683f98..2f18c05b81 100644
a b 26 26 #include <NodeMonitor.h> 27 27 #include <Notifications.h> 28 28 #include <Path.h> 29 #include <Point.h> 29 30 #include <PropertyInfo.h> 31 #include <Screen.h> 30 32 31 33 #include "AppGroupView.h" 32 34 #include "AppUsage.h" … … property_info main_prop_list[] = { 50 52 }; 51 53 52 54 55 /** 56 * Checks if notification position overlaps with 57 * deskbar position 58 */ 59 static bool 60 is_overlapping(deskbar_location deskbar, 61 uint32 notification) { 62 if (deskbar == B_DESKBAR_RIGHT_TOP 63 && notification == (B_FOLLOW_RIGHT | B_FOLLOW_TOP)) 64 return true; 65 if (deskbar == B_DESKBAR_RIGHT_BOTTOM 66 && notification == (B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM)) 67 return true; 68 if (deskbar == B_DESKBAR_LEFT_TOP 69 && notification == (B_FOLLOW_LEFT | B_FOLLOW_TOP)) 70 return true; 71 if (deskbar == B_DESKBAR_LEFT_BOTTOM 72 && notification == (B_FOLLOW_LEFT | B_FOLLOW_BOTTOM)) 73 return true; 74 if (deskbar == B_DESKBAR_TOP 75 && (notification == (B_FOLLOW_LEFT | B_FOLLOW_TOP) 76 || notification == (B_FOLLOW_RIGHT | B_FOLLOW_TOP))) 77 return true; 78 if (deskbar == B_DESKBAR_BOTTOM 79 && (notification == (B_FOLLOW_LEFT | B_FOLLOW_BOTTOM) 80 || notification == (B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM))) 81 return true; 82 return false; 83 } 84 85 53 86 NotificationWindow::NotificationWindow() 54 87 : 55 88 BWindow(BRect(0, 0, -1, -1), B_TRANSLATE_MARK("Notification"), … … NotificationWindow::NotificationWindow() 63 96 fCachePath.Append("Notifications"); 64 97 BDirectory cacheDir; 65 98 result = cacheDir.SetTo(fCachePath.Path()); 66 if (result == B_ENTRY_NOT_FOUND)99 if (result == B_ENTRY_NOT_FOUND) 67 100 cacheDir.CreateDirectory(fCachePath.Path(), NULL); 68 101 69 102 SetLayout(new BGroupLayout(B_VERTICAL, 0)); … … NotificationWindow::MessageReceived(BMessage* message) 146 179 BString sourceName(notification->SourceName()); 147 180 148 181 bool allow = false; 149 appfilter_t::iterator it = 150 fAppFilters.find(sourceSignature.String());182 appfilter_t::iterator it = fAppFilters 183 .find(sourceSignature.String()); 151 184 152 185 AppUsage* appUsage = NULL; 153 186 if (it == fAppFilters.end()) { … … NotificationWindow::SetPosition() 275 308 276 309 float x = Frame().left; 277 310 float y = Frame().top; 278 // If we can't guess, don't move... 311 // If we cant guess, don't move... 312 BPoint location(x, y); 279 313 280 314 BDeskbar deskbar; 281 BRect frame = deskbar.Frame();282 315 283 switch (deskbar.Location()) { 284 case B_DESKBAR_TOP: 285 // Put it just under, top right corner 286 y = frame.bottom + topOffset; 287 x = frame.right - width + rightOffset; 288 break; 289 case B_DESKBAR_BOTTOM: 290 // Put it just above, lower left corner 291 y = frame.top - height - bottomOffset; 292 x = frame.right - width + rightOffset; 293 break; 294 case B_DESKBAR_RIGHT_TOP: 295 x = frame.left - width - rightOffset; 296 y = frame.top - topOffset + 1; 297 break; 298 case B_DESKBAR_LEFT_TOP: 299 x = frame.right + leftOffset; 300 y = frame.top - topOffset + 1; 301 break; 302 case B_DESKBAR_RIGHT_BOTTOM: 303 y = frame.bottom - height + bottomOffset; 304 x = frame.left - width - rightOffset; 305 break; 306 case B_DESKBAR_LEFT_BOTTOM: 307 y = frame.bottom - height + bottomOffset; 308 x = frame.right + leftOffset; 309 break; 310 default: 311 break; 316 // If notification and deskbar position are same 317 // then follow deskbar position 318 uint32 position = (is_overlapping(deskbar.Location(), fPosition)) 319 ? B_FOLLOW_DESKBAR 320 : fPosition; 321 322 323 if (position == B_FOLLOW_DESKBAR) 324 { 325 BRect frame = deskbar.Frame(); 326 switch (deskbar.Location()) { 327 case B_DESKBAR_TOP: 328 // In case of overlapping here or for bottom 329 // use user's notification position 330 y = frame.bottom + topOffset; 331 x = (fPosition == (B_FOLLOW_LEFT | B_FOLLOW_TOP)) 332 ? frame.left + rightOffset 333 : frame.right - width + rightOffset; 334 break; 335 case B_DESKBAR_BOTTOM: 336 y = frame.top - height - bottomOffset; 337 x = (fPosition == (B_FOLLOW_LEFT | B_FOLLOW_BOTTOM)) 338 ? frame.left + rightOffset 339 : frame.right - width + rightOffset; 340 break; 341 case B_DESKBAR_RIGHT_TOP: 342 y = frame.top - topOffset + 1; 343 x = frame.left - width - rightOffset; 344 break; 345 case B_DESKBAR_LEFT_TOP: 346 y = frame.top - topOffset + 1; 347 x = frame.right + leftOffset; 348 break; 349 case B_DESKBAR_RIGHT_BOTTOM: 350 y = frame.bottom - height + bottomOffset; 351 x = frame.left - width - rightOffset; 352 break; 353 case B_DESKBAR_LEFT_BOTTOM: 354 y = frame.bottom - height + bottomOffset; 355 x = frame.right + leftOffset; 356 break; 357 default: 358 break; 359 } 360 location = BPoint(x, y); 361 } else if (position == (B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM)) { 362 location = BScreen().Frame().RightBottom(); 363 location -= BPoint(width, height); 364 } else if (position == (B_FOLLOW_LEFT | B_FOLLOW_BOTTOM)) { 365 location = BScreen().Frame().LeftBottom(); 366 location -= BPoint(0, height); 367 } else if (position == (B_FOLLOW_RIGHT | B_FOLLOW_TOP)) { 368 location = BScreen().Frame().RightTop(); 369 location -= BPoint(width, 0); 370 } else if (position == (B_FOLLOW_LEFT | B_FOLLOW_TOP)) { 371 location = BScreen().Frame().LeftTop(); 312 372 } 313 373 314 MoveTo( x, y);374 MoveTo(location); 315 375 } 316 376 317 377 … … NotificationWindow::_LoadDisplaySettings(BMessage& settings) 402 462 else 403 463 fIconSize = (icon_size)setting; 404 464 465 int32 position; 466 if (settings.FindInt32(kNotificationPositionName, &position) != B_OK) 467 fPosition = kDefaultNotificationPosition; 468 else 469 fPosition = position; 470 405 471 // Notify the views about the change 406 472 appview_t::iterator aIt; 407 473 for (aIt = fAppViews.begin(); aIt != fAppViews.end(); ++aIt) { -
src/servers/notification/NotificationWindow.h
diff --git a/src/servers/notification/NotificationWindow.h b/src/servers/notification/NotificationWindow.h index f4325a9ae2..8861453c60 100644
a b private: 63 63 float fWidth; 64 64 icon_size fIconSize; 65 65 int32 fTimeout; 66 uint32 fPosition; 66 67 bool fShouldRun; 67 68 BPath fCachePath; 68 69 }; -
src/servers/notification/Notifications.cpp
diff --git a/src/servers/notification/Notifications.cpp b/src/servers/notification/Notifications.cpp index 3dfcb1e713..d49f0c3e15 100644
a b const char* kTimeoutName = "timeout"; 17 17 // Display settings 18 18 const char* kWidthName = "width"; 19 19 const char* kIconSizeName = "icon size"; 20 const char* kNotificationPositionName = "notification position";