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