xref: /haiku/src/servers/app/Desktop.h (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 /*
2  * Copyright 2001-2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Adrian Oanca <adioanca@cotty.iren.ro>
7  *		Stephan Aßmus <superstippi@gmx.de>
8  *		Axel Dörfler, axeld@pinc-software.de
9  */
10 #ifndef DESKTOP_H
11 #define DESKTOP_H
12 
13 
14 #include "CursorManager.h"
15 #include "EventDispatcher.h"
16 #include "ScreenManager.h"
17 #include "ServerScreen.h"
18 #include "VirtualScreen.h"
19 #include "DesktopSettings.h"
20 #include "MessageLooper.h"
21 #include "WindowList.h"
22 #include "Workspace.h"
23 #include "WorkspacePrivate.h"
24 
25 #include <ObjectList.h>
26 
27 #include <Autolock.h>
28 #include <InterfaceDefs.h>
29 #include <List.h>
30 #include <Menu.h>
31 #include <Region.h>
32 #include <Window.h>
33 
34 #define USE_MULTI_LOCKER 1
35 
36 #if USE_MULTI_LOCKER
37 #  include "MultiLocker.h"
38 #else
39 #  include <Locker.h>
40 #endif
41 
42 class BMessage;
43 
44 class DrawingEngine;
45 class HWInterface;
46 class ServerApp;
47 class WorkspacesLayer;
48 struct server_read_only_memory;
49 
50 namespace BPrivate {
51 	class LinkSender;
52 };
53 
54 class Desktop : public MessageLooper, public ScreenOwner {
55 	public:
56 								Desktop(uid_t userID);
57 		virtual					~Desktop();
58 
59 		status_t				Init();
60 
61 		uid_t					UserID() const { return fUserID; }
62 		virtual port_id			MessagePort() const { return fMessagePort; }
63 		area_id					SharedReadOnlyArea() const { return fSharedReadOnlyArea; }
64 
65 		::EventDispatcher&		EventDispatcher() { return fEventDispatcher; }
66 
67 		void					BroadcastToAllApps(int32 code);
68 
69 		// Screen and drawing related methods
70 
71 		Screen*					ScreenAt(int32 index) const
72 									{ return fActiveScreen; }
73 		Screen*					ActiveScreen() const
74 									{ return fActiveScreen; }
75 
76 		CursorManager&			GetCursorManager() { return fCursorManager; }
77 
78 		void					SetCursor(ServerCursor* cursor);
79 		ServerCursor*			Cursor() const;
80 		void					SetLastMouseState(const BPoint& position,
81 									int32 buttons);
82 									// for use by the mouse filter only
83 									// both mouse position calls require
84 									// the Desktop object to be locked
85 									// already
86 		void					GetLastMouseState(BPoint* position,
87 									int32* buttons) const;
88 									// for use by ServerWindow
89 
90 		void					ScreenChanged(Screen* screen, bool makeDefault);
91 
92 		void					ScreenRemoved(Screen* screen) {}
93 		void					ScreenAdded(Screen* screen) {}
94 		bool					ReleaseScreen(Screen* screen) { return false; }
95 
96 		const ::VirtualScreen&	VirtualScreen() const { return fVirtualScreen; }
97 		DrawingEngine*			GetDrawingEngine() const
98 									{ return fVirtualScreen.DrawingEngine(); }
99 		::HWInterface*			HWInterface() const
100 									{ return fVirtualScreen.HWInterface(); }
101 
102 		// Workspace methods
103 
104 		void					SetWorkspaceAsync(int32 index);
105 		void					SetWorkspace(int32 index);
106 		int32					CurrentWorkspace()
107 									{ return fCurrentWorkspace; }
108 		Workspace::Private&		WorkspaceAt(int32 index)
109 									{ return fWorkspaces[index]; }
110 		status_t				SetWorkspacesCount(int32 newCount);
111 
112 		// WindowLayer methods
113 
114 		void					ActivateWindow(WindowLayer* window);
115 		void					SendWindowBehind(WindowLayer* window,
116 									WindowLayer* behindOf = NULL);
117 
118 		void					ShowWindow(WindowLayer* window);
119 		void					HideWindow(WindowLayer* window);
120 
121 		void					MoveWindowBy(WindowLayer* window, float x, float y,
122 									int32 workspace = -1);
123 		void					ResizeWindowBy(WindowLayer* window, float x, float y);
124 		bool					SetWindowTabLocation(WindowLayer* window, float location);
125 		bool					SetWindowDecoratorSettings(WindowLayer* window,
126 														   const BMessage& settings);
127 
128 		void					SetWindowWorkspaces(WindowLayer* window,
129 									uint32 workspaces);
130 
131 		void					AddWindow(WindowLayer* window);
132 		void					RemoveWindow(WindowLayer* window);
133 
134 		bool					AddWindowToSubset(WindowLayer* subset,
135 									WindowLayer* window);
136 		void					RemoveWindowFromSubset(WindowLayer* subset,
137 									WindowLayer* window);
138 
139 		void					SetWindowLook(WindowLayer* window, window_look look);
140 		void					SetWindowFeel(WindowLayer* window, window_feel feel);
141 		void					SetWindowFlags(WindowLayer* window, uint32 flags);
142 		void					SetWindowTitle(WindowLayer* window, const char* title);
143 
144 		WindowLayer*			FocusWindow() const { return fFocus; }
145 		WindowLayer*			FrontWindow() const { return fFront; }
146 		WindowLayer*			BackWindow() const { return fBack; }
147 
148 		WindowLayer*			WindowAt(BPoint where);
149 
150 		WindowLayer*			MouseEventWindow() const { return fMouseEventWindow; }
151 		void					SetMouseEventWindow(WindowLayer* window);
152 
153 		void					SetViewUnderMouse(const WindowLayer* window, int32 viewToken);
154 		int32					ViewUnderMouse(const WindowLayer* window);
155 
156 		void					SetFocusWindow(WindowLayer* window);
157 		EventTarget*			KeyboardEventTarget();
158 
159 		WindowLayer*			FindWindowLayerByClientToken(int32 token, team_id teamID);
160 		//WindowLayer*			FindWindowLayerByServerToken(int32 token);
161 
162 #if USE_MULTI_LOCKER
163 		bool					LockSingleWindow() { return fWindowLock.ReadLock(); }
164 		void					UnlockSingleWindow() { fWindowLock.ReadUnlock(); }
165 
166 		bool					LockAllWindows() { return fWindowLock.WriteLock(); }
167 		void					UnlockAllWindows() { fWindowLock.WriteUnlock(); }
168 #else // USE_MULTI_LOCKER
169 		bool					LockSingleWindow() { return fWindowLock.Lock(); }
170 		void					UnlockSingleWindow() { fWindowLock.Unlock(); }
171 
172 		bool					LockAllWindows() { return fWindowLock.Lock(); }
173 		void					UnlockAllWindows() { fWindowLock.Unlock(); }
174 #endif // USE_MULTI_LOCKER
175 
176 		void					MarkDirty(BRegion& region);
177 
178 		BRegion&				BackgroundRegion()
179 									{ return fBackgroundRegion; }
180 
181 		void					RedrawBackground();
182 		void					StoreWorkspaceConfiguration(int32 index);
183 
184 		void					MinimizeApplication(team_id team);
185 		void					BringApplicationToFront(team_id team);
186 		void					WindowAction(int32 windowToken, int32 action);
187 
188 		void					WriteWindowList(team_id team,
189 									BPrivate::LinkSender& sender);
190 		void					WriteWindowInfo(int32 serverToken,
191 									BPrivate::LinkSender& sender);
192 
193 	private:
194 		void					_LaunchInputServer();
195 		void					_SetWorkspace(int32 index);
196 		void					_ShowWindow(WindowLayer* window,
197 									bool affectsOtherWindows = true);
198 		void					_HideWindow(WindowLayer* window);
199 
200 		void					_UpdateSubsetWorkspaces(WindowLayer* window,
201 									int32 previousIndex = -1,
202 									int32 newIndex = -1);
203 		void					_ChangeWindowWorkspaces(WindowLayer* window,
204 									uint32 oldWorkspaces, uint32 newWorkspaces);
205 		void					_BringWindowsToFront(WindowList& windows,
206 									int32 list, bool wereVisible);
207  		status_t				_ActivateApp(team_id team);
208  		void					_SendFakeMouseMoved(WindowLayer* window = NULL);
209 
210 		void					_RebuildClippingForAllWindows(BRegion& stillAvailableOnScreen);
211 		void					_TriggerWindowRedrawing(BRegion& newDirtyRegion);
212 		void					_SetBackground(BRegion& background);
213 
214 		void					_UpdateFloating(int32 previousWorkspace = -1,
215 									int32 nextWorkspace = -1,
216 									WindowLayer* mouseEventWindow = NULL);
217 		void					_UpdateBack();
218 		void					_UpdateFront(bool updateFloating = true);
219 		void					_UpdateFronts(bool updateFloating = true);
220 		bool					_WindowHasModal(WindowLayer* window);
221 
222 		void					_WindowChanged(WindowLayer* window);
223 
224 		void					_GetLooperName(char* name, size_t size);
225 		void					_PrepareQuit();
226 		void					_DispatchMessage(int32 code,
227 									BPrivate::LinkReceiver &link);
228 
229 		WindowList&				_CurrentWindows();
230 		WindowList&				_Windows(int32 index);
231 
232 	private:
233 		friend class DesktopSettings;
234 		friend class LockedDesktopSettings;
235 
236 		uid_t					fUserID;
237 		::VirtualScreen			fVirtualScreen;
238 		DesktopSettingsPrivate*	fSettings;
239 		port_id					fMessagePort;
240 		::EventDispatcher		fEventDispatcher;
241 		port_id					fInputPort;
242 		area_id					fSharedReadOnlyArea;
243 		server_read_only_memory* fServerReadOnlyMemory;
244 
245 		BLocker					fApplicationsLock;
246 		BObjectList<ServerApp>	fApplications;
247 
248 		sem_id					fShutdownSemaphore;
249 		int32					fShutdownCount;
250 
251 		::Workspace::Private	fWorkspaces[kMaxWorkspaces];
252 		int32					fCurrentWorkspace;
253 
254 		WindowList				fAllWindows;
255 		WindowList				fSubsetWindows;
256 		WorkspacesLayer*		fWorkspacesLayer;
257 
258 		Screen*					fActiveScreen;
259 
260 		CursorManager			fCursorManager;
261 
262 #if USE_MULTI_LOCKER
263 		MultiLocker				fWindowLock;
264 #else
265 		BLocker					fWindowLock;
266 #endif
267 
268 		BRegion					fBackgroundRegion;
269 		BRegion					fScreenRegion;
270 
271 		bool					fFocusFollowsMouse;
272 
273 		WindowLayer*			fMouseEventWindow;
274 		const WindowLayer*		fWindowUnderMouse;
275 		int32					fViewUnderMouse;
276 		BPoint					fLastMousePosition;
277 		int32					fLastMouseButtons;
278 
279 		WindowLayer*			fFocus;
280 		WindowLayer*			fFront;
281 		WindowLayer*			fBack;
282 };
283 
284 #endif	// DESKTOP_H
285