xref: /haiku/src/servers/app/Desktop.h (revision a17c3a48b84013d5c1ab684fd5bf9961eee3d7d9)
16a0a0a80SAxel Dörfler /*
2195e980eSAxel Dörfler  * Copyright 2001-2006, Haiku.
36a0a0a80SAxel Dörfler  * Distributed under the terms of the MIT License.
46a0a0a80SAxel Dörfler  *
56a0a0a80SAxel Dörfler  * Authors:
66a0a0a80SAxel Dörfler  *		Adrian Oanca <adioanca@cotty.iren.ro>
76a0a0a80SAxel Dörfler  *		Stephan Aßmus <superstippi@gmx.de>
86a0a0a80SAxel Dörfler  *		Axel Dörfler, axeld@pinc-software.de
96a0a0a80SAxel Dörfler  */
1027adb969SAxel Dörfler #ifndef DESKTOP_H
1127adb969SAxel Dörfler #define DESKTOP_H
1233bbe223SAxel Dörfler 
1308f35604SAxel Dörfler 
143ddebe7eSMichael Lotz #include "CursorManager.h"
1508f35604SAxel Dörfler #include "EventDispatcher.h"
16fd5bec1eSAxel Dörfler #include "ScreenManager.h"
17fd5bec1eSAxel Dörfler #include "ServerScreen.h"
18fd5bec1eSAxel Dörfler #include "VirtualScreen.h"
19ef8810f2SAxel Dörfler #include "DesktopSettings.h"
205f2edc0fSAxel Dörfler #include "MessageLooper.h"
21e83820edSAxel Dörfler #include "WindowList.h"
2227adb969SAxel Dörfler #include "Workspace.h"
235ca8477eSAxel Dörfler #include "WorkspacePrivate.h"
24fd5bec1eSAxel Dörfler 
25e83820edSAxel Dörfler #include <ObjectList.h>
26e83820edSAxel Dörfler 
27e83820edSAxel Dörfler #include <Autolock.h>
2833bbe223SAxel Dörfler #include <InterfaceDefs.h>
293dcb3b07SStephan Aßmus #include <List.h>
303dcb3b07SStephan Aßmus #include <Menu.h>
31e83820edSAxel Dörfler #include <Region.h>
3257be2866SAxel Dörfler #include <Window.h>
336a0a0a80SAxel Dörfler 
3439c9925fSStephan Aßmus #define USE_MULTI_LOCKER 1
35e83820edSAxel Dörfler 
36e83820edSAxel Dörfler #if USE_MULTI_LOCKER
37e83820edSAxel Dörfler #  include "MultiLocker.h"
38e83820edSAxel Dörfler #else
39e83820edSAxel Dörfler #  include <Locker.h>
40e83820edSAxel Dörfler #endif
4133bbe223SAxel Dörfler 
423dcb3b07SStephan Aßmus class BMessage;
436a0a0a80SAxel Dörfler 
4458468dfeSStephan Aßmus class DrawingEngine;
453dcb3b07SStephan Aßmus class HWInterface;
46e83820edSAxel Dörfler class ServerApp;
47ce8c4d79SAxel Dörfler class WorkspacesLayer;
486d5488e1SAxel Dörfler struct server_read_only_memory;
4933bbe223SAxel Dörfler 
506a0a0a80SAxel Dörfler namespace BPrivate {
516a0a0a80SAxel Dörfler 	class LinkSender;
526a0a0a80SAxel Dörfler };
536a0a0a80SAxel Dörfler 
545f2edc0fSAxel Dörfler class Desktop : public MessageLooper, public ScreenOwner {
5533bbe223SAxel Dörfler 	public:
5636deda69SAxel Dörfler 								Desktop(uid_t userID);
573dcb3b07SStephan Aßmus 		virtual					~Desktop();
583dcb3b07SStephan Aßmus 
596d5488e1SAxel Dörfler 		status_t				Init();
6036deda69SAxel Dörfler 
6136deda69SAxel Dörfler 		uid_t					UserID() const { return fUserID; }
62770c05d6SAxel Dörfler 		virtual port_id			MessagePort() const { return fMessagePort; }
636d5488e1SAxel Dörfler 		area_id					SharedReadOnlyArea() const { return fSharedReadOnlyArea; }
64770c05d6SAxel Dörfler 
65f7598223SAxel Dörfler 		::EventDispatcher&		EventDispatcher() { return fEventDispatcher; }
666c17d025SAxel Dörfler 
67770c05d6SAxel Dörfler 		void					BroadcastToAllApps(int32 code);
6833bbe223SAxel Dörfler 
6927adb969SAxel Dörfler 		// Screen and drawing related methods
7027adb969SAxel Dörfler 
7127adb969SAxel Dörfler 		Screen*					ScreenAt(int32 index) const
72fd5bec1eSAxel Dörfler 									{ return fActiveScreen; }
7327adb969SAxel Dörfler 		Screen*					ActiveScreen() const
7494fa2bd2SAdi Oanca 									{ return fActiveScreen; }
75e83820edSAxel Dörfler 
7627adb969SAxel Dörfler 		CursorManager&			GetCursorManager() { return fCursorManager; }
7733bbe223SAxel Dörfler 
78195e980eSAxel Dörfler 		void					SetCursor(ServerCursor* cursor);
79195e980eSAxel Dörfler 		ServerCursor*			Cursor() const;
80195e980eSAxel Dörfler 
818527f8ffSAxel Dörfler 		void					ScreenChanged(Screen* screen, bool makeDefault);
82df362433SAxel Dörfler 
8327adb969SAxel Dörfler 		void					ScreenRemoved(Screen* screen) {}
8427adb969SAxel Dörfler 		void					ScreenAdded(Screen* screen) {}
8527adb969SAxel Dörfler 		bool					ReleaseScreen(Screen* screen) { return false; }
863dcb3b07SStephan Aßmus 
87fd5bec1eSAxel Dörfler 		const ::VirtualScreen&	VirtualScreen() const { return fVirtualScreen; }
8827adb969SAxel Dörfler 		DrawingEngine*			GetDrawingEngine() const
8958468dfeSStephan Aßmus 									{ return fVirtualScreen.DrawingEngine(); }
9027adb969SAxel Dörfler 		::HWInterface*			HWInterface() const
91fd5bec1eSAxel Dörfler 									{ return fVirtualScreen.HWInterface(); }
9294fa2bd2SAdi Oanca 
9327adb969SAxel Dörfler 		// Workspace methods
9427adb969SAxel Dörfler 
9527adb969SAxel Dörfler 		void					SetWorkspace(int32 index);
9627adb969SAxel Dörfler 		int32					CurrentWorkspace()
9727adb969SAxel Dörfler 									{ return fCurrentWorkspace; }
985ca8477eSAxel Dörfler 		Workspace::Private&		WorkspaceAt(int32 index)
9927adb969SAxel Dörfler 									{ return fWorkspaces[index]; }
100*a17c3a48SAxel Dörfler 		status_t				SetWorkspacesCount(int32 newCount);
10127adb969SAxel Dörfler 
10227adb969SAxel Dörfler 		// WindowLayer methods
10327adb969SAxel Dörfler 
10427adb969SAxel Dörfler 		void					ActivateWindow(WindowLayer* window);
105e83820edSAxel Dörfler 		void					SendWindowBehind(WindowLayer* window,
106e83820edSAxel Dörfler 									WindowLayer* behindOf = NULL);
10727adb969SAxel Dörfler 
10815918e4fSAxel Dörfler 		void					ShowWindow(WindowLayer* window);
10915918e4fSAxel Dörfler 		void					HideWindow(WindowLayer* window);
11015918e4fSAxel Dörfler 
11114fe11cfSAxel Dörfler 		void					MoveWindowBy(WindowLayer* window, float x, float y,
11214fe11cfSAxel Dörfler 									int32 workspace = -1);
11319d801a6SAxel Dörfler 		void					ResizeWindowBy(WindowLayer* window, float x, float y);
11446fb2d73SStephan Aßmus 		bool					SetWindowTabLocation(WindowLayer* window, float location);
115b30e9021SStephan Aßmus 		bool					SetWindowDecoratorSettings(WindowLayer* window,
116b30e9021SStephan Aßmus 														   const BMessage& settings);
11719d801a6SAxel Dörfler 
118a631158aSAxel Dörfler 		void					SetWindowWorkspaces(WindowLayer* window,
119a631158aSAxel Dörfler 									uint32 workspaces);
12027adb969SAxel Dörfler 
121a631158aSAxel Dörfler 		void					AddWindow(WindowLayer* window);
122a631158aSAxel Dörfler 		void					RemoveWindow(WindowLayer* window);
12357be2866SAxel Dörfler 
12434227d2cSAxel Dörfler 		bool					AddWindowToSubset(WindowLayer* subset,
12534227d2cSAxel Dörfler 									WindowLayer* window);
12634227d2cSAxel Dörfler 		void					RemoveWindowFromSubset(WindowLayer* subset,
12734227d2cSAxel Dörfler 									WindowLayer* window);
12834227d2cSAxel Dörfler 
12957be2866SAxel Dörfler 		void					SetWindowLook(WindowLayer* window, window_look look);
13057be2866SAxel Dörfler 		void					SetWindowFeel(WindowLayer* window, window_feel feel);
13157be2866SAxel Dörfler 		void					SetWindowFlags(WindowLayer* window, uint32 flags);
132939fb407SStephan Aßmus 		void					SetWindowTitle(WindowLayer* window, const char* title);
13333bbe223SAxel Dörfler 
134e83820edSAxel Dörfler 		WindowLayer*			FocusWindow() const { return fFocus; }
135e83820edSAxel Dörfler 		WindowLayer*			FrontWindow() const { return fFront; }
136e83820edSAxel Dörfler 		WindowLayer*			BackWindow() const { return fBack; }
137e83820edSAxel Dörfler 
138e83820edSAxel Dörfler 		WindowLayer*			WindowAt(BPoint where);
139e83820edSAxel Dörfler 
140e83820edSAxel Dörfler 		WindowLayer*			MouseEventWindow() const { return fMouseEventWindow; }
141e83820edSAxel Dörfler 		void					SetMouseEventWindow(WindowLayer* window);
142e83820edSAxel Dörfler 
1431e766d46SAxel Dörfler 		void					SetViewUnderMouse(const WindowLayer* window, int32 viewToken);
1441e766d46SAxel Dörfler 		int32					ViewUnderMouse(const WindowLayer* window);
1451e766d46SAxel Dörfler 
146e83820edSAxel Dörfler 		void					SetFocusWindow(WindowLayer* window);
147e83820edSAxel Dörfler 
1484b813bf2SAxel Dörfler 		WindowLayer*			FindWindowLayerByClientToken(int32 token, team_id teamID);
1494b813bf2SAxel Dörfler 		//WindowLayer*			FindWindowLayerByServerToken(int32 token);
1506a0a0a80SAxel Dörfler 
151e83820edSAxel Dörfler #if USE_MULTI_LOCKER
15261fed21bSAxel Dörfler 		bool					LockSingleWindow() { return fWindowLock.ReadLock(); }
15361fed21bSAxel Dörfler 		void					UnlockSingleWindow() { fWindowLock.ReadUnlock(); }
154e83820edSAxel Dörfler 
15561fed21bSAxel Dörfler 		bool					LockAllWindows() { return fWindowLock.WriteLock(); }
15661fed21bSAxel Dörfler 		void					UnlockAllWindows() { fWindowLock.WriteUnlock(); }
157e83820edSAxel Dörfler #else // USE_MULTI_LOCKER
15861fed21bSAxel Dörfler 		bool					LockSingleWindow() { return fWindowLock.Lock(); }
15961fed21bSAxel Dörfler 		void					UnlockSingleWindow() { fWindowLock.Unlock(); }
160e83820edSAxel Dörfler 
16161fed21bSAxel Dörfler 		bool					LockAllWindows() { return fWindowLock.Lock(); }
16261fed21bSAxel Dörfler 		void					UnlockAllWindows() { fWindowLock.Unlock(); }
163e83820edSAxel Dörfler #endif // USE_MULTI_LOCKER
164e83820edSAxel Dörfler 
165e83820edSAxel Dörfler 		void					MarkDirty(BRegion& region);
166e83820edSAxel Dörfler 
167e83820edSAxel Dörfler 		BRegion&				BackgroundRegion()
168e83820edSAxel Dörfler 									{ return fBackgroundRegion; }
16933bbe223SAxel Dörfler 
1703dcbe9fcSAxel Dörfler 		void					RedrawBackground();
17182081c70SJérôme Duval 		void					StoreWorkspaceConfiguration(int32 index);
1723dcbe9fcSAxel Dörfler 
173f877af82SAxel Dörfler 		void					MinimizeApplication(team_id team);
174f877af82SAxel Dörfler 		void					BringApplicationToFront(team_id team);
175bfe69873SAxel Dörfler 		void					WindowAction(int32 windowToken, int32 action);
176f877af82SAxel Dörfler 
17727adb969SAxel Dörfler 		void					WriteWindowList(team_id team,
17827adb969SAxel Dörfler 									BPrivate::LinkSender& sender);
17927adb969SAxel Dörfler 		void					WriteWindowInfo(int32 serverToken,
18027adb969SAxel Dörfler 									BPrivate::LinkSender& sender);
18133bbe223SAxel Dörfler 
18233bbe223SAxel Dörfler 	private:
183*a17c3a48SAxel Dörfler 		void					_SetWorkspace(int32 index);
184e83820edSAxel Dörfler 		void					_ShowWindow(WindowLayer* window,
185e83820edSAxel Dörfler 									bool affectsOtherWindows = true);
186e83820edSAxel Dörfler 		void					_HideWindow(WindowLayer* window);
187e83820edSAxel Dörfler 
18864747950SAxel Dörfler 		void					_UpdateSubsetWorkspaces(WindowLayer* window,
18964747950SAxel Dörfler 									int32 previousIndex = -1,
19064747950SAxel Dörfler 									int32 newIndex = -1);
191a631158aSAxel Dörfler 		void					_ChangeWindowWorkspaces(WindowLayer* window,
192a631158aSAxel Dörfler 									uint32 oldWorkspaces, uint32 newWorkspaces);
193e83820edSAxel Dörfler 		void					_BringWindowsToFront(WindowList& windows,
194e83820edSAxel Dörfler 									int32 list, bool wereVisible);
19536deda69SAxel Dörfler  		status_t				_ActivateApp(team_id team);
196a1a04a47SAxel Dörfler  		void					_SendFakeMouseMoved(WindowLayer* window = NULL);
197e83820edSAxel Dörfler 
198e83820edSAxel Dörfler 		void					_RebuildClippingForAllWindows(BRegion& stillAvailableOnScreen);
199e83820edSAxel Dörfler 		void					_TriggerWindowRedrawing(BRegion& newDirtyRegion);
200e83820edSAxel Dörfler 		void					_SetBackground(BRegion& background);
201e83820edSAxel Dörfler 
20234227d2cSAxel Dörfler 		void					_UpdateFloating(int32 previousWorkspace = -1,
203d479fa7aSAxel Dörfler 									int32 nextWorkspace = -1,
204d479fa7aSAxel Dörfler 									WindowLayer* mouseEventWindow = NULL);
205e83820edSAxel Dörfler 		void					_UpdateBack();
20634227d2cSAxel Dörfler 		void					_UpdateFront(bool updateFloating = true);
20734227d2cSAxel Dörfler 		void					_UpdateFronts(bool updateFloating = true);
20834227d2cSAxel Dörfler 		bool					_WindowHasModal(WindowLayer* window);
209e83820edSAxel Dörfler 
210ce8c4d79SAxel Dörfler 		void					_WindowChanged(WindowLayer* window);
211ce8c4d79SAxel Dörfler 
21227adb969SAxel Dörfler 		void					_GetLooperName(char* name, size_t size);
21327adb969SAxel Dörfler 		void					_PrepareQuit();
21427adb969SAxel Dörfler 		void					_DispatchMessage(int32 code,
21527adb969SAxel Dörfler 									BPrivate::LinkReceiver &link);
2165f2edc0fSAxel Dörfler 
217e83820edSAxel Dörfler 		WindowList&				_CurrentWindows();
21834227d2cSAxel Dörfler 		WindowList&				_Windows(int32 index);
219e83820edSAxel Dörfler 
2205f2edc0fSAxel Dörfler 	private:
221ef8810f2SAxel Dörfler 		friend class DesktopSettings;
222*a17c3a48SAxel Dörfler 		friend class LockedDesktopSettings;
223ef8810f2SAxel Dörfler 
22436deda69SAxel Dörfler 		uid_t					fUserID;
225fd5bec1eSAxel Dörfler 		::VirtualScreen			fVirtualScreen;
226*a17c3a48SAxel Dörfler 		DesktopSettingsPrivate*	fSettings;
2275f2edc0fSAxel Dörfler 		port_id					fMessagePort;
228f7598223SAxel Dörfler 		::EventDispatcher		fEventDispatcher;
2296c17d025SAxel Dörfler 		port_id					fInputPort;
2306d5488e1SAxel Dörfler 		area_id					fSharedReadOnlyArea;
2316d5488e1SAxel Dörfler 		server_read_only_memory* fServerReadOnlyMemory;
232770c05d6SAxel Dörfler 
233e83820edSAxel Dörfler 		BLocker					fApplicationsLock;
234e83820edSAxel Dörfler 		BObjectList<ServerApp>	fApplications;
235770c05d6SAxel Dörfler 
236770c05d6SAxel Dörfler 		sem_id					fShutdownSemaphore;
237770c05d6SAxel Dörfler 		int32					fShutdownCount;
238770c05d6SAxel Dörfler 
23982081c70SJérôme Duval 		::Workspace::Private	fWorkspaces[kMaxWorkspaces];
24027adb969SAxel Dörfler 		int32					fCurrentWorkspace;
24127adb969SAxel Dörfler 
242e83820edSAxel Dörfler 		WindowList				fAllWindows;
24334227d2cSAxel Dörfler 		WindowList				fSubsetWindows;
244ce8c4d79SAxel Dörfler 		WorkspacesLayer*		fWorkspacesLayer;
24533bbe223SAxel Dörfler 
24633bbe223SAxel Dörfler 		Screen*					fActiveScreen;
2473ddebe7eSMichael Lotz 
2483ddebe7eSMichael Lotz 		CursorManager			fCursorManager;
249e83820edSAxel Dörfler 
250e83820edSAxel Dörfler #if USE_MULTI_LOCKER
251e83820edSAxel Dörfler 		MultiLocker				fWindowLock;
252e83820edSAxel Dörfler #else
253e83820edSAxel Dörfler 		BLocker					fWindowLock;
254e83820edSAxel Dörfler #endif
255e83820edSAxel Dörfler 
256e83820edSAxel Dörfler 		BRegion					fBackgroundRegion;
257e83820edSAxel Dörfler 		BRegion					fScreenRegion;
258e83820edSAxel Dörfler 
259e83820edSAxel Dörfler 		bool					fFocusFollowsMouse;
260e83820edSAxel Dörfler 
261e83820edSAxel Dörfler 		WindowLayer*			fMouseEventWindow;
2621e766d46SAxel Dörfler 		const WindowLayer*		fWindowUnderMouse;
2631e766d46SAxel Dörfler 		int32					fViewUnderMouse;
2641e766d46SAxel Dörfler 
265e83820edSAxel Dörfler 		WindowLayer*			fFocus;
266e83820edSAxel Dörfler 		WindowLayer*			fFront;
267e83820edSAxel Dörfler 		WindowLayer*			fBack;
26833bbe223SAxel Dörfler };
26933bbe223SAxel Dörfler 
27027adb969SAxel Dörfler #endif	// DESKTOP_H
271