1 /* 2 * Copyright 2005-2006, 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 "WindowLayer.h" 14 15 #include <math.h> 16 #include <stdio.h> 17 #include <stdlib.h> 18 19 20 static RGBColor kDefaultColor = RGBColor(51, 102, 152); 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 RGBColor& 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.SetColor(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 rgb_color color = fColor.GetColor32(); 63 settings.RemoveName("color"); 64 settings.AddInt32("color", *(int32 *)&color); 65 } 66 67 68 void 69 Workspace::Private::_SetDefaults() 70 { 71 fColor.SetColor(kDefaultColor); 72 } 73 74 75 // #pragma mark - 76 77 78 Workspace::Workspace(Desktop& desktop, int32 index) 79 : 80 fWorkspace(desktop.WorkspaceAt(index)), 81 fDesktop(desktop), 82 fCurrentWorkspace(index == desktop.CurrentWorkspace()) 83 { 84 // fDesktop.LockSingleWindow(); 85 // TODO: in which threads is this being used? 86 // from my investigations, it is used in the 87 // WorkspacesLayer::Draw(), which would have 88 // to hold the read lock already 89 RewindWindows(); 90 } 91 92 93 Workspace::~Workspace() 94 { 95 // fDesktop.UnlockSingleWindow(); 96 } 97 98 99 const RGBColor& 100 Workspace::Color() const 101 { 102 return fWorkspace.Color(); 103 } 104 105 106 void 107 Workspace::SetColor(const RGBColor& color, bool makeDefault) 108 { 109 if (color == Color()) 110 return; 111 112 fWorkspace.SetColor(color); 113 fDesktop.RedrawBackground(); 114 if (makeDefault) 115 fDesktop.StoreWorkspaceConfiguration(fWorkspace.Index()); 116 } 117 118 119 status_t 120 Workspace::GetNextWindow(WindowLayer*& _window, BPoint& _leftTop) 121 { 122 if (fCurrent == NULL) 123 fCurrent = fWorkspace.Windows().FirstWindow(); 124 else 125 fCurrent = fCurrent->NextWindow(fWorkspace.Index()); 126 127 if (fCurrent == NULL) 128 return B_ENTRY_NOT_FOUND; 129 130 _window = fCurrent; 131 132 if (fCurrentWorkspace) 133 _leftTop = fCurrent->Frame().LeftTop(); 134 else 135 _leftTop = fCurrent->Anchor(fWorkspace.Index()).position; 136 137 return B_OK; 138 } 139 140 141 void 142 Workspace::RewindWindows() 143 { 144 fCurrent = NULL; 145 } 146 147