Ticket #8194: Workspaces-Constants-Removed.diff
File Workspaces-Constants-Removed.diff, 8.2 KB (added by , 13 years ago) |
---|
-
src/apps/workspaces/Workspaces.cpp
diff --git a/src/apps/workspaces/Workspaces.cpp b/src/apps/workspaces/Workspaces.cpp index e7b99f9..c6eb7a9 100644
a b 27 27 #include <Screen.h> 28 28 #include <TextView.h> 29 29 #include <Window.h> 30 31 30 #include <ctype.h> 32 31 #include <stdio.h> 33 32 #include <stdlib.h> … … static const uint32 kMsgToggleAutoRaise = 'tgAR'; 55 54 static const uint32 kMsgToggleAlwaysOnTop = 'tgAT'; 56 55 static const uint32 kMsgToggleLiveInDeskbar = 'tgDb'; 57 56 58 static const float kScreenBorderOffset = 10.0;59 57 60 58 extern "C" _EXPORT BView* instantiate_deskbar_item(); 61 59 … … class WorkspacesSettings { 71 69 bool AlwaysOnTop() const { return fAlwaysOnTop; } 72 70 bool HasTitle() const { return fHasTitle; } 73 71 bool HasBorder() const { return fHasBorder; } 72 bool SettingsLoaded() const { return fLoaded; } 74 73 75 74 void UpdateFramesForScreen(BRect screenFrame); 76 75 void UpdateScreenFrame(); … … class WorkspacesSettings { 90 89 bool fAlwaysOnTop; 91 90 bool fHasTitle; 92 91 bool fHasBorder; 92 bool fLoaded; 93 93 }; 94 94 95 95 class WorkspacesView : public BView { … … class WorkspacesWindow : public BWindow { 136 136 137 137 void SetAutoRaise(bool enable); 138 138 bool IsAutoRaising() const { return fAutoRaising; } 139 float GetTabHeight() { return fTabHeight; } 140 float GetBorderWidth() { return fBorderWidth; } 141 float GetScreenBorderOffset() { return 2.0 * fBorderWidth; } 139 142 140 143 private: 141 144 WorkspacesSettings *fSettings; 142 145 bool fAutoRaising; 146 float fTabHeight; 147 float fBorderWidth; 143 148 }; 144 149 145 150 class WorkspacesApp : public BApplication { … … WorkspacesSettings::WorkspacesSettings() 166 171 fHasBorder(true) 167 172 { 168 173 UpdateScreenFrame(); 174 175 fLoaded = false; 169 176 170 bool loaded = false;171 177 BScreen screen; 172 178 173 179 BFile file; … … WorkspacesSettings::WorkspacesSettings() 176 182 if (settings.Unflatten(&file) == B_OK) { 177 183 if (settings.FindRect("window", &fWindowFrame) == B_OK 178 184 && settings.FindRect("screen", &fScreenFrame) == B_OK) 179 loaded = true;185 fLoaded = true; 180 186 181 187 settings.FindBool("auto-raise", &fAutoRaising); 182 188 settings.FindBool("always on top", &fAlwaysOnTop); … … WorkspacesSettings::WorkspacesSettings() 202 208 else 203 209 fScreenFrame = screen.Frame(); 204 210 205 loaded = true;211 fLoaded = true; 206 212 } 213 } else { 214 fprintf(stderr, "Opening settings file failed.\n"); 207 215 } 208 216 } 209 217 210 if ( loaded) {218 if (fLoaded) { 211 219 // if the current screen frame is different from the one 212 220 // just loaded, we need to alter the window frame accordingly 213 221 if (fScreenFrame != screen.Frame()) 214 222 UpdateFramesForScreen(screen.Frame()); 215 223 } 216 217 if (!loaded218 || !(screen.Frame().right + 5 >= fWindowFrame.right219 && screen.Frame().bottom + 5 >= fWindowFrame.bottom220 && screen.Frame().left - 5 <= fWindowFrame.left221 && screen.Frame().top - 5 <= fWindowFrame.top)) {222 // set to some usable defaults223 float screenWidth = screen.Frame().Width();224 float screenHeight = screen.Frame().Height();225 float aspectRatio = screenWidth / screenHeight;226 227 uint32 columns, rows;228 BPrivate::get_workspaces_layout(&columns, &rows);229 230 // default size of ~1/10 of screen width231 float workspaceWidth = screenWidth / 10;232 float workspaceHeight = workspaceWidth / aspectRatio;233 234 float width = floor(workspaceWidth * columns);235 float height = floor(workspaceHeight * rows);236 237 float tabHeight = 20;238 // TODO: find tabHeight without being a window239 240 // shrink to fit more241 while (width + 2 * kScreenBorderOffset > screenWidth242 || height + 2 * kScreenBorderOffset + tabHeight > screenHeight) {243 width = floor(0.95 * width);244 height = floor(0.95 * height);245 }246 247 fWindowFrame = fScreenFrame;248 fWindowFrame.OffsetBy(-kScreenBorderOffset, -kScreenBorderOffset);249 fWindowFrame.left = fWindowFrame.right - width;250 fWindowFrame.top = fWindowFrame.bottom - height;251 }252 224 } 253 225 254 226 … … WorkspacesSettings::~WorkspacesSettings() 260 232 return; 261 233 262 234 BMessage settings('wksp'); 263 235 264 236 if (settings.AddRect("window", fWindowFrame) == B_OK 265 237 && settings.AddRect("screen", fScreenFrame) == B_OK 266 238 && settings.AddBool("auto-raise", fAutoRaising) == B_OK … … WorkspacesSettings::~WorkspacesSettings() 268 240 && settings.AddBool("has title", fHasTitle) == B_OK 269 241 && settings.AddBool("has border", fHasBorder) == B_OK) 270 242 settings.Flatten(&file); 243 else 244 fprintf(stderr,"An error occured while saving settings.\n"); 271 245 } 272 246 273 247 … … WorkspacesSettings::UpdateFramesForScreen(BRect newScreenFrame) 313 287 fWindowFrame.OffsetTo(fWindowFrame.left, 314 288 newScreenFrame.bottom - (fScreenFrame.bottom - fWindowFrame.top)); 315 289 } 316 317 290 fScreenFrame = newScreenFrame; 318 291 } 319 292 … … WorkspacesSettings::SetWindowFrame(BRect frame) 339 312 WorkspacesView::WorkspacesView(BRect frame, bool showDragger=true) 340 313 : 341 314 BView(frame, kDeskbarItemName, B_FOLLOW_ALL, 342 kWorkspacesViewFlag | B_FRAME_EVENTS), 343 fParentWhichDrawsOnChildren(NULL), 315 kWorkspacesViewFlag | B_FRAME_EVENTS), // kWorkspacesViewFlag is picked up by the app_server. 316 fParentWhichDrawsOnChildren(NULL), // ...That's how the desktop frames are done! 344 317 fCurrentFrame(frame) 345 318 { 346 319 if(showDragger) { … … WorkspacesWindow::WorkspacesWindow(WorkspacesSettings *settings) 645 618 fSettings(settings), 646 619 fAutoRaising(false) 647 620 { 648 AddChild(new WorkspacesView(Bounds())); 621 622 // Turn window decor on to grab decor widths. 623 BMessage windowSettings; 624 SetLook(B_TITLED_WINDOW_LOOK); 625 if (GetDecoratorSettings(&windowSettings) == B_OK){ 626 BRect tabFrame = windowSettings.FindRect("tab frame"); 627 float borderWidth = windowSettings.FindFloat("border width"); 628 fTabHeight = tabFrame.Height(); 629 fBorderWidth = borderWidth; 630 631 /* Note: Below is based on old code from WorkspacesSettings::WorkspacesSettings(). 632 Decorator dimensions can be dynamically fetched instead of hardcoded here. */ 633 634 BScreen screen; 635 636 float screenWidth = screen.Frame().Width(); 637 float screenHeight = screen.Frame().Height(); 638 float aspectRatio = screenWidth / screenHeight; 639 640 uint32 columns, rows; 641 BPrivate::get_workspaces_layout(&columns, &rows); 642 643 // default size of ~1/10 of screen width 644 float workspaceWidth = screenWidth / 10; 645 float workspaceHeight = workspaceWidth / aspectRatio; 646 647 float width = floor(workspaceWidth * columns); 648 float height = floor(workspaceHeight * rows); 649 650 // If you have too many workspaces to fit on the screen, shrink until they fit. 651 while (width + 2 * borderWidth > screenWidth 652 || height + 2 * borderWidth + GetTabHeight() > screenHeight) { 653 width = floor(0.95 * width); 654 height = floor(0.95 * height); 655 } 656 657 BRect frame = fSettings->ScreenFrame(); 658 frame.OffsetBy(-2.0 * borderWidth, -2.0 * borderWidth); 659 frame.left = frame.right - width; 660 frame.top = frame.bottom - height; 661 ResizeTo(frame.Width(), frame.Height()); 662 if (!fSettings->SettingsLoaded()) { 663 // Put it in bottom corner by default. 664 MoveTo(screenWidth - frame.Width() - borderWidth, 665 screenHeight - frame.Height() - borderWidth); 666 } 667 fSettings->SetWindowFrame(frame); 668 } 649 669 650 670 if (!fSettings->HasBorder()) 651 671 SetLook(B_NO_BORDER_WINDOW_LOOK); … … WorkspacesWindow::WorkspacesWindow(WorkspacesSettings *settings) 656 676 SetFeel(B_FLOATING_ALL_WINDOW_FEEL); 657 677 else 658 678 SetAutoRaise(fSettings->AutoRaising()); 679 680 AddChild(new WorkspacesView(Bounds())); 659 681 } 660 682 661 683 … … WorkspacesWindow::Zoom(BPoint origin, float width, float height) 724 746 width = floor(workspaceWidth * columns); 725 747 height = floor(workspaceHeight * rows); 726 748 727 float tabHeight = Frame().top - DecoratorFrame().top;728 749 729 while (width + 2 * kScreenBorderOffset> screenWidth730 || height + 2 * kScreenBorderOffset + tabHeight> screenHeight) {750 while (width + 2 * GetScreenBorderOffset() > screenWidth 751 || height + 2 * GetScreenBorderOffset() + GetTabHeight() > screenHeight) { 731 752 width = floor(0.95 * width); 732 753 height = floor(0.95 * height); 733 754 } … … WorkspacesWindow::Zoom(BPoint origin, float width, float height) 735 756 ResizeTo(width, height); 736 757 737 758 origin = screen.Frame().RightBottom(); 738 origin.x -= kScreenBorderOffset+ width;739 origin.y -= kScreenBorderOffset+ height;759 origin.x -= GetScreenBorderOffset() + width; 760 origin.y -= GetScreenBorderOffset() + height; 740 761 741 762 MoveTo(origin); 742 763 }