usb_ecm: Use the current configuration instead of a fixed one.
[haiku.git] / src / servers / app / Workspace.cpp
blob1b890dd3ed8aec24c7c364e35f8423972855dc56
1 /*
2 * Copyright 2005-2009, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de
7 */
10 #include "Workspace.h"
12 #include <math.h>
13 #include <stdio.h>
14 #include <stdlib.h>
16 #include <Debug.h>
18 #include "Desktop.h"
19 #include "WorkspacePrivate.h"
20 #include "Window.h"
23 static rgb_color kDefaultColor = (rgb_color){ 51, 102, 152, 255 };
26 Workspace::Private::Private()
28 _SetDefaults();
32 Workspace::Private::~Private()
37 void
38 Workspace::Private::SetDisplaysFromDesktop(Desktop* desktop)
43 void
44 Workspace::Private::SetColor(const rgb_color& color)
46 fColor = color;
50 void
51 Workspace::Private::RestoreConfiguration(const BMessage& settings)
53 rgb_color color;
54 if (settings.FindInt32("color", (int32 *)&color) == B_OK)
55 fColor = color;
57 fStoredScreenConfiguration.Restore(settings);
58 fCurrentScreenConfiguration.Restore(settings);
62 /*! \brief Store the workspace configuration in a message
64 void
65 Workspace::Private::StoreConfiguration(BMessage& settings)
67 fStoredScreenConfiguration.Store(settings);
68 settings.AddInt32("color", *(int32 *)&fColor);
72 void
73 Workspace::Private::_SetDefaults()
75 fColor = kDefaultColor;
79 // #pragma mark -
82 Workspace::Workspace(Desktop& desktop, int32 index, bool readOnly)
84 fWorkspace(desktop.WorkspaceAt(index)),
85 fDesktop(desktop),
86 fCurrentWorkspace(index == desktop.CurrentWorkspace())
88 ASSERT(desktop.WindowLocker().IsWriteLocked()
89 || ( readOnly && desktop.WindowLocker().IsReadLocked()));
90 RewindWindows();
94 Workspace::~Workspace()
99 const rgb_color&
100 Workspace::Color() const
102 return fWorkspace.Color();
106 void
107 Workspace::SetColor(const rgb_color& color, bool makeDefault)
109 if (color == Color())
110 return;
112 fWorkspace.SetColor(color);
113 fDesktop.RedrawBackground();
114 if (makeDefault)
115 fDesktop.StoreWorkspaceConfiguration(fWorkspace.Index());
119 status_t
120 Workspace::GetNextWindow(Window*& _window, BPoint& _leftTop)
122 if (fCurrent == NULL)
123 fCurrent = fWorkspace.Windows().FirstWindow();
124 else
125 fCurrent = fCurrent->NextWindow(fWorkspace.Index());
127 if (fCurrent == NULL)
128 return B_ENTRY_NOT_FOUND;
130 _window = fCurrent;
132 if (fCurrentWorkspace)
133 _leftTop = fCurrent->Frame().LeftTop();
134 else
135 _leftTop = fCurrent->Anchor(fWorkspace.Index()).position;
137 return B_OK;
141 status_t
142 Workspace::GetPreviousWindow(Window*& _window, BPoint& _leftTop)
144 if (fCurrent == NULL)
145 fCurrent = fWorkspace.Windows().LastWindow();
146 else
147 fCurrent = fCurrent->PreviousWindow(fWorkspace.Index());
149 if (fCurrent == NULL)
150 return B_ENTRY_NOT_FOUND;
152 _window = fCurrent;
154 if (fCurrentWorkspace)
155 _leftTop = fCurrent->Frame().LeftTop();
156 else
157 _leftTop = fCurrent->Anchor(fWorkspace.Index()).position;
159 return B_OK;
163 void
164 Workspace::RewindWindows()
166 fCurrent = NULL;