1 /* 2 * Copyright 2005-2008, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 10 #include "Desktop.h" 11 #include "Workspace.h" 12 #include "WorkspacePrivate.h" 13 #include "Window.h" 14 15 #include <math.h> 16 #include <stdio.h> 17 #include <stdlib.h> 18 19 20 static rgb_color kDefaultColor = (rgb_color){ 51, 102, 152, 255 }; 21 22 23 Workspace::Private::Private() 24 { 25 _SetDefaults(); 26 } 27 28 29 Workspace::Private::~Private() 30 { 31 } 32 33 34 void 35 Workspace::Private::SetDisplaysFromDesktop(Desktop* desktop) 36 { 37 } 38 39 40 void 41 Workspace::Private::SetColor(const rgb_color& color) 42 { 43 fColor = color; 44 } 45 46 47 void 48 Workspace::Private::RestoreConfiguration(const BMessage& settings) 49 { 50 rgb_color color; 51 if (settings.FindInt32("color", (int32 *)&color) == B_OK) 52 fColor = color; 53 } 54 55 56 /*! 57 \brief Store the workspace configuration in a message 58 */ 59 void 60 Workspace::Private::StoreConfiguration(BMessage& settings) 61 { 62 settings.RemoveName("color"); 63 settings.AddInt32("color", *(int32 *)&fColor); 64 } 65 66 67 void 68 Workspace::Private::_SetDefaults() 69 { 70 fColor = kDefaultColor; 71 } 72 73 74 // #pragma mark - 75 76 77 Workspace::Workspace(Desktop& desktop, int32 index) 78 : 79 fWorkspace(desktop.WorkspaceAt(index)), 80 fDesktop(desktop), 81 fCurrentWorkspace(index == desktop.CurrentWorkspace()) 82 { 83 // fDesktop.LockSingleWindow(); 84 // TODO: in which threads is this being used? 85 // from my investigations, it is used in the 86 // WorkspacesView::Draw(), which would have 87 // to hold the read lock already 88 RewindWindows(); 89 } 90 91 92 Workspace::~Workspace() 93 { 94 // fDesktop.UnlockSingleWindow(); 95 } 96 97 98 const rgb_color& 99 Workspace::Color() const 100 { 101 return fWorkspace.Color(); 102 } 103 104 105 void 106 Workspace::SetColor(const rgb_color& color, bool makeDefault) 107 { 108 if (color == Color()) 109 return; 110 111 fWorkspace.SetColor(color); 112 fDesktop.RedrawBackground(); 113 if (makeDefault) 114 fDesktop.StoreWorkspaceConfiguration(fWorkspace.Index()); 115 } 116 117 118 status_t 119 Workspace::GetNextWindow(Window*& _window, BPoint& _leftTop) 120 { 121 if (fCurrent == NULL) 122 fCurrent = fWorkspace.Windows().FirstWindow(); 123 else 124 fCurrent = fCurrent->NextWindow(fWorkspace.Index()); 125 126 if (fCurrent == NULL) 127 return B_ENTRY_NOT_FOUND; 128 129 _window = fCurrent; 130 131 if (fCurrentWorkspace) 132 _leftTop = fCurrent->Frame().LeftTop(); 133 else 134 _leftTop = fCurrent->Anchor(fWorkspace.Index()).position; 135 136 return B_OK; 137 } 138 139 140 status_t 141 Workspace::GetPreviousWindow(Window*& _window, BPoint& _leftTop) 142 { 143 if (fCurrent == NULL) 144 fCurrent = fWorkspace.Windows().LastWindow(); 145 else 146 fCurrent = fCurrent->PreviousWindow(fWorkspace.Index()); 147 148 if (fCurrent == NULL) 149 return B_ENTRY_NOT_FOUND; 150 151 _window = fCurrent; 152 153 if (fCurrentWorkspace) 154 _leftTop = fCurrent->Frame().LeftTop(); 155 else 156 _leftTop = fCurrent->Anchor(fWorkspace.Index()).position; 157 158 return B_OK; 159 } 160 161 162 void 163 Workspace::RewindWindows() 164 { 165 fCurrent = NULL; 166 } 167 168