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 34e83820edSAxel Dörfler #define USE_MULTI_LOCKER 0 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; 4833bbe223SAxel Dörfler 496a0a0a80SAxel Dörfler namespace BPrivate { 506a0a0a80SAxel Dörfler class LinkSender; 516a0a0a80SAxel Dörfler }; 526a0a0a80SAxel Dörfler 535f2edc0fSAxel Dörfler class Desktop : public MessageLooper, public ScreenOwner { 5433bbe223SAxel Dörfler public: 5536deda69SAxel Dörfler Desktop(uid_t userID); 563dcb3b07SStephan Aßmus virtual ~Desktop(); 573dcb3b07SStephan Aßmus 583dcb3b07SStephan Aßmus void Init(); 5936deda69SAxel Dörfler 6036deda69SAxel Dörfler uid_t UserID() const { return fUserID; } 61770c05d6SAxel Dörfler virtual port_id MessagePort() const { return fMessagePort; } 62770c05d6SAxel Dörfler 63f7598223SAxel Dörfler ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 646c17d025SAxel Dörfler 65770c05d6SAxel Dörfler void BroadcastToAllApps(int32 code); 6633bbe223SAxel Dörfler 6727adb969SAxel Dörfler // Screen and drawing related methods 6827adb969SAxel Dörfler 6927adb969SAxel Dörfler Screen* ScreenAt(int32 index) const 70fd5bec1eSAxel Dörfler { return fActiveScreen; } 7127adb969SAxel Dörfler Screen* ActiveScreen() const 7294fa2bd2SAdi Oanca { return fActiveScreen; } 73e83820edSAxel Dörfler 7427adb969SAxel Dörfler CursorManager& GetCursorManager() { return fCursorManager; } 7533bbe223SAxel Dörfler 76195e980eSAxel Dörfler void SetCursor(ServerCursor* cursor); 77195e980eSAxel Dörfler ServerCursor* Cursor() const; 78195e980eSAxel Dörfler 798527f8ffSAxel Dörfler void ScreenChanged(Screen* screen, bool makeDefault); 80df362433SAxel Dörfler 8127adb969SAxel Dörfler void ScreenRemoved(Screen* screen) {} 8227adb969SAxel Dörfler void ScreenAdded(Screen* screen) {} 8327adb969SAxel Dörfler bool ReleaseScreen(Screen* screen) { return false; } 843dcb3b07SStephan Aßmus 85fd5bec1eSAxel Dörfler const ::VirtualScreen& VirtualScreen() const { return fVirtualScreen; } 8627adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 8758468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 8827adb969SAxel Dörfler ::HWInterface* HWInterface() const 89fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 9094fa2bd2SAdi Oanca 9127adb969SAxel Dörfler // Workspace methods 9227adb969SAxel Dörfler 9327adb969SAxel Dörfler void SetWorkspace(int32 index); 9427adb969SAxel Dörfler int32 CurrentWorkspace() 9527adb969SAxel Dörfler { return fCurrentWorkspace; } 965ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 9727adb969SAxel Dörfler { return fWorkspaces[index]; } 98e83820edSAxel Dörfler void UpdateWorkspaces(); 9927adb969SAxel Dörfler 10027adb969SAxel Dörfler // WindowLayer methods 10127adb969SAxel Dörfler 10227adb969SAxel Dörfler void ActivateWindow(WindowLayer* window); 103e83820edSAxel Dörfler void SendWindowBehind(WindowLayer* window, 104e83820edSAxel Dörfler WindowLayer* behindOf = NULL); 10527adb969SAxel Dörfler 10615918e4fSAxel Dörfler void ShowWindow(WindowLayer* window); 10715918e4fSAxel Dörfler void HideWindow(WindowLayer* window); 10815918e4fSAxel Dörfler 10919d801a6SAxel Dörfler void MoveWindowBy(WindowLayer* window, float x, float y); 11019d801a6SAxel Dörfler void ResizeWindowBy(WindowLayer* window, float x, float y); 11119d801a6SAxel Dörfler 112a631158aSAxel Dörfler void SetWindowWorkspaces(WindowLayer* window, 113a631158aSAxel Dörfler uint32 workspaces); 11427adb969SAxel Dörfler 115a631158aSAxel Dörfler void AddWindow(WindowLayer* window); 116a631158aSAxel Dörfler void RemoveWindow(WindowLayer* window); 11757be2866SAxel Dörfler 11834227d2cSAxel Dörfler bool AddWindowToSubset(WindowLayer* subset, 11934227d2cSAxel Dörfler WindowLayer* window); 12034227d2cSAxel Dörfler void RemoveWindowFromSubset(WindowLayer* subset, 12134227d2cSAxel Dörfler WindowLayer* window); 12234227d2cSAxel Dörfler 12357be2866SAxel Dörfler void SetWindowLook(WindowLayer* window, window_look look); 12457be2866SAxel Dörfler void SetWindowFeel(WindowLayer* window, window_feel feel); 12557be2866SAxel Dörfler void SetWindowFlags(WindowLayer* window, uint32 flags); 126939fb407SStephan Aßmus void SetWindowTitle(WindowLayer* window, const char* title); 12733bbe223SAxel Dörfler 128e83820edSAxel Dörfler WindowLayer* FocusWindow() const { return fFocus; } 129e83820edSAxel Dörfler WindowLayer* FrontWindow() const { return fFront; } 130e83820edSAxel Dörfler WindowLayer* BackWindow() const { return fBack; } 131e83820edSAxel Dörfler 132e83820edSAxel Dörfler WindowLayer* WindowAt(BPoint where); 133e83820edSAxel Dörfler 134e83820edSAxel Dörfler WindowLayer* MouseEventWindow() const { return fMouseEventWindow; } 135e83820edSAxel Dörfler void SetMouseEventWindow(WindowLayer* window); 136e83820edSAxel Dörfler 137*1e766d46SAxel Dörfler void SetViewUnderMouse(const WindowLayer* window, int32 viewToken); 138*1e766d46SAxel Dörfler int32 ViewUnderMouse(const WindowLayer* window); 139*1e766d46SAxel Dörfler 140e83820edSAxel Dörfler void SetFocusWindow(WindowLayer* window); 141e83820edSAxel Dörfler 1424b813bf2SAxel Dörfler WindowLayer* FindWindowLayerByClientToken(int32 token, team_id teamID); 1434b813bf2SAxel Dörfler //WindowLayer* FindWindowLayerByServerToken(int32 token); 1446a0a0a80SAxel Dörfler 145e83820edSAxel Dörfler #if USE_MULTI_LOCKER 14661fed21bSAxel Dörfler bool LockSingleWindow() { return fWindowLock.ReadLock(); } 14761fed21bSAxel Dörfler void UnlockSingleWindow() { fWindowLock.ReadUnlock(); } 148e83820edSAxel Dörfler 14961fed21bSAxel Dörfler bool LockAllWindows() { return fWindowLock.WriteLock(); } 15061fed21bSAxel Dörfler void UnlockAllWindows() { fWindowLock.WriteUnlock(); } 151e83820edSAxel Dörfler #else // USE_MULTI_LOCKER 15261fed21bSAxel Dörfler bool LockSingleWindow() { return fWindowLock.Lock(); } 15361fed21bSAxel Dörfler void UnlockSingleWindow() { fWindowLock.Unlock(); } 154e83820edSAxel Dörfler 15561fed21bSAxel Dörfler bool LockAllWindows() { return fWindowLock.Lock(); } 15661fed21bSAxel Dörfler void UnlockAllWindows() { fWindowLock.Unlock(); } 157e83820edSAxel Dörfler #endif // USE_MULTI_LOCKER 158e83820edSAxel Dörfler 159e83820edSAxel Dörfler void MarkDirty(BRegion& region); 160e83820edSAxel Dörfler 161e83820edSAxel Dörfler BRegion& BackgroundRegion() 162e83820edSAxel Dörfler { return fBackgroundRegion; } 16333bbe223SAxel Dörfler 1643dcbe9fcSAxel Dörfler void RedrawBackground(); 1653dcbe9fcSAxel Dörfler 166f877af82SAxel Dörfler void MinimizeApplication(team_id team); 167f877af82SAxel Dörfler void BringApplicationToFront(team_id team); 168bfe69873SAxel Dörfler void WindowAction(int32 windowToken, int32 action); 169f877af82SAxel Dörfler 17027adb969SAxel Dörfler void WriteWindowList(team_id team, 17127adb969SAxel Dörfler BPrivate::LinkSender& sender); 17227adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 17327adb969SAxel Dörfler BPrivate::LinkSender& sender); 17433bbe223SAxel Dörfler 17533bbe223SAxel Dörfler private: 176e83820edSAxel Dörfler void _ShowWindow(WindowLayer* window, 177e83820edSAxel Dörfler bool affectsOtherWindows = true); 178e83820edSAxel Dörfler void _HideWindow(WindowLayer* window); 179e83820edSAxel Dörfler 18034227d2cSAxel Dörfler void _UpdateSubsetWorkspaces(WindowLayer* window); 181a631158aSAxel Dörfler void _ChangeWindowWorkspaces(WindowLayer* window, 182a631158aSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 183e83820edSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 184e83820edSAxel Dörfler int32 list, bool wereVisible); 18536deda69SAxel Dörfler status_t _ActivateApp(team_id team); 186e83820edSAxel Dörfler 187e83820edSAxel Dörfler void _RebuildClippingForAllWindows(BRegion& stillAvailableOnScreen); 188e83820edSAxel Dörfler void _TriggerWindowRedrawing(BRegion& newDirtyRegion); 189e83820edSAxel Dörfler void _SetBackground(BRegion& background); 190e83820edSAxel Dörfler 19134227d2cSAxel Dörfler void _UpdateFloating(int32 previousWorkspace = -1, 19234227d2cSAxel Dörfler int32 nextWorkspace = -1); 193e83820edSAxel Dörfler void _UpdateBack(); 19434227d2cSAxel Dörfler void _UpdateFront(bool updateFloating = true); 19534227d2cSAxel Dörfler void _UpdateFronts(bool updateFloating = true); 19634227d2cSAxel Dörfler bool _WindowHasModal(WindowLayer* window); 197e83820edSAxel Dörfler 198ce8c4d79SAxel Dörfler void _WindowChanged(WindowLayer* window); 199ce8c4d79SAxel Dörfler 20027adb969SAxel Dörfler void _GetLooperName(char* name, size_t size); 20127adb969SAxel Dörfler void _PrepareQuit(); 20227adb969SAxel Dörfler void _DispatchMessage(int32 code, 20327adb969SAxel Dörfler BPrivate::LinkReceiver &link); 2045f2edc0fSAxel Dörfler 205e83820edSAxel Dörfler WindowList& _CurrentWindows(); 20634227d2cSAxel Dörfler WindowList& _Windows(int32 index); 207e83820edSAxel Dörfler 2085f2edc0fSAxel Dörfler private: 209ef8810f2SAxel Dörfler friend class DesktopSettings; 210ef8810f2SAxel Dörfler 21136deda69SAxel Dörfler uid_t fUserID; 212fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 213ef8810f2SAxel Dörfler DesktopSettings::Private* fSettings; 2145f2edc0fSAxel Dörfler port_id fMessagePort; 215f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 2166c17d025SAxel Dörfler port_id fInputPort; 217770c05d6SAxel Dörfler 218e83820edSAxel Dörfler BLocker fApplicationsLock; 219e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 220770c05d6SAxel Dörfler 221770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 222770c05d6SAxel Dörfler int32 fShutdownCount; 223770c05d6SAxel Dörfler 2245ca8477eSAxel Dörfler ::Workspace::Private fWorkspaces[32]; 22527adb969SAxel Dörfler int32 fCurrentWorkspace; 22627adb969SAxel Dörfler 227e83820edSAxel Dörfler WindowList fAllWindows; 22834227d2cSAxel Dörfler WindowList fSubsetWindows; 229ce8c4d79SAxel Dörfler WorkspacesLayer* fWorkspacesLayer; 23033bbe223SAxel Dörfler 23133bbe223SAxel Dörfler Screen* fActiveScreen; 2323ddebe7eSMichael Lotz 2333ddebe7eSMichael Lotz CursorManager fCursorManager; 234e83820edSAxel Dörfler 235e83820edSAxel Dörfler #if USE_MULTI_LOCKER 236e83820edSAxel Dörfler MultiLocker fWindowLock; 237e83820edSAxel Dörfler #else 238e83820edSAxel Dörfler BLocker fWindowLock; 239e83820edSAxel Dörfler #endif 240e83820edSAxel Dörfler 241e83820edSAxel Dörfler BRegion fBackgroundRegion; 242e83820edSAxel Dörfler BRegion fScreenRegion; 243e83820edSAxel Dörfler 244e83820edSAxel Dörfler bool fFocusFollowsMouse; 245e83820edSAxel Dörfler 246e83820edSAxel Dörfler WindowLayer* fMouseEventWindow; 247*1e766d46SAxel Dörfler const WindowLayer* fWindowUnderMouse; 248*1e766d46SAxel Dörfler int32 fViewUnderMouse; 249*1e766d46SAxel Dörfler 250e83820edSAxel Dörfler WindowLayer* fFocus; 251e83820edSAxel Dörfler WindowLayer* fFront; 252e83820edSAxel Dörfler WindowLayer* fBack; 25333bbe223SAxel Dörfler }; 25433bbe223SAxel Dörfler 25527adb969SAxel Dörfler #endif // DESKTOP_H 256