16a0a0a80SAxel Dörfler /* 26a0a0a80SAxel Dörfler * Copyright 2001-2005, 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; 4733bbe223SAxel Dörfler 486a0a0a80SAxel Dörfler namespace BPrivate { 496a0a0a80SAxel Dörfler class LinkSender; 506a0a0a80SAxel Dörfler }; 516a0a0a80SAxel Dörfler 525f2edc0fSAxel Dörfler class Desktop : public MessageLooper, public ScreenOwner { 5333bbe223SAxel Dörfler public: 5436deda69SAxel Dörfler Desktop(uid_t userID); 553dcb3b07SStephan Aßmus virtual ~Desktop(); 563dcb3b07SStephan Aßmus 573dcb3b07SStephan Aßmus void Init(); 5836deda69SAxel Dörfler 5936deda69SAxel Dörfler uid_t UserID() const { return fUserID; } 60770c05d6SAxel Dörfler virtual port_id MessagePort() const { return fMessagePort; } 61770c05d6SAxel Dörfler 62f7598223SAxel Dörfler ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 636c17d025SAxel Dörfler 64770c05d6SAxel Dörfler void BroadcastToAllApps(int32 code); 6533bbe223SAxel Dörfler 6627adb969SAxel Dörfler // Screen and drawing related methods 6727adb969SAxel Dörfler 6827adb969SAxel Dörfler Screen* ScreenAt(int32 index) const 69fd5bec1eSAxel Dörfler { return fActiveScreen; } 7027adb969SAxel Dörfler Screen* ActiveScreen() const 7194fa2bd2SAdi Oanca { return fActiveScreen; } 72e83820edSAxel Dörfler 7327adb969SAxel Dörfler CursorManager& GetCursorManager() { return fCursorManager; } 7433bbe223SAxel Dörfler 75df362433SAxel Dörfler void ScreenChanged(Screen* screen); 76df362433SAxel Dörfler 7727adb969SAxel Dörfler void ScreenRemoved(Screen* screen) {} 7827adb969SAxel Dörfler void ScreenAdded(Screen* screen) {} 7927adb969SAxel Dörfler bool ReleaseScreen(Screen* screen) { return false; } 803dcb3b07SStephan Aßmus 81fd5bec1eSAxel Dörfler const ::VirtualScreen& VirtualScreen() const { return fVirtualScreen; } 8227adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 8358468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 8427adb969SAxel Dörfler ::HWInterface* HWInterface() const 85fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 8694fa2bd2SAdi Oanca 8727adb969SAxel Dörfler // Workspace methods 8827adb969SAxel Dörfler 8927adb969SAxel Dörfler void SetWorkspace(int32 index); 9027adb969SAxel Dörfler int32 CurrentWorkspace() 9127adb969SAxel Dörfler { return fCurrentWorkspace; } 925ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 9327adb969SAxel Dörfler { return fWorkspaces[index]; } 94e83820edSAxel Dörfler void UpdateWorkspaces(); 9527adb969SAxel Dörfler 9627adb969SAxel Dörfler // WindowLayer methods 9727adb969SAxel Dörfler 9827adb969SAxel Dörfler void ActivateWindow(WindowLayer* window); 99e83820edSAxel Dörfler void SendWindowBehind(WindowLayer* window, 100e83820edSAxel Dörfler WindowLayer* behindOf = NULL); 10127adb969SAxel Dörfler 10215918e4fSAxel Dörfler void ShowWindow(WindowLayer* window); 10315918e4fSAxel Dörfler void HideWindow(WindowLayer* window); 10415918e4fSAxel Dörfler 10519d801a6SAxel Dörfler void MoveWindowBy(WindowLayer* window, float x, float y); 10619d801a6SAxel Dörfler void ResizeWindowBy(WindowLayer* window, float x, float y); 10719d801a6SAxel Dörfler 108a631158aSAxel Dörfler void SetWindowWorkspaces(WindowLayer* window, 109a631158aSAxel Dörfler uint32 workspaces); 11027adb969SAxel Dörfler 111a631158aSAxel Dörfler void AddWindow(WindowLayer* window); 112a631158aSAxel Dörfler void RemoveWindow(WindowLayer* window); 11357be2866SAxel Dörfler 11457be2866SAxel Dörfler void SetWindowLook(WindowLayer* window, window_look look); 11557be2866SAxel Dörfler void SetWindowFeel(WindowLayer* window, window_feel feel); 11657be2866SAxel Dörfler void SetWindowFlags(WindowLayer* window, uint32 flags); 117*939fb407SStephan Aßmus void SetWindowTitle(WindowLayer* window, const char* title); 11833bbe223SAxel Dörfler 119e83820edSAxel Dörfler WindowLayer* FocusWindow() const { return fFocus; } 120e83820edSAxel Dörfler WindowLayer* FrontWindow() const { return fFront; } 121e83820edSAxel Dörfler WindowLayer* BackWindow() const { return fBack; } 122e83820edSAxel Dörfler 123e83820edSAxel Dörfler WindowLayer* WindowAt(BPoint where); 124e83820edSAxel Dörfler 125e83820edSAxel Dörfler WindowLayer* MouseEventWindow() const { return fMouseEventWindow; } 126e83820edSAxel Dörfler void SetMouseEventWindow(WindowLayer* window); 127e83820edSAxel Dörfler 128e83820edSAxel Dörfler void SetFocusWindow(WindowLayer* window); 129e83820edSAxel Dörfler 1304b813bf2SAxel Dörfler WindowLayer* FindWindowLayerByClientToken(int32 token, team_id teamID); 1314b813bf2SAxel Dörfler //WindowLayer* FindWindowLayerByServerToken(int32 token); 1326a0a0a80SAxel Dörfler 133e83820edSAxel Dörfler #if USE_MULTI_LOCKER 134e83820edSAxel Dörfler bool ReadLockWindows() { return fWindowLock.ReadLock(); } 135e83820edSAxel Dörfler void ReadUnlockWindows() { fWindowLock.ReadUnlock(); } 136e83820edSAxel Dörfler 137e83820edSAxel Dörfler bool WriteLockWindows() { return fWindowLock.WriteLock(); } 138e83820edSAxel Dörfler void WriteUnlockWindows() { fWindowLock.WriteUnlock(); } 139e83820edSAxel Dörfler #else // USE_MULTI_LOCKER 140e83820edSAxel Dörfler bool ReadLockWindows() { return fWindowLock.Lock(); } 141e83820edSAxel Dörfler void ReadUnlockWindows() { fWindowLock.Unlock(); } 142e83820edSAxel Dörfler 143e83820edSAxel Dörfler bool WriteLockWindows() { return fWindowLock.Lock(); } 144e83820edSAxel Dörfler void WriteUnlockWindows() { fWindowLock.Unlock(); } 145e83820edSAxel Dörfler #endif // USE_MULTI_LOCKER 146e83820edSAxel Dörfler 147e83820edSAxel Dörfler void MarkDirty(BRegion& region); 148e83820edSAxel Dörfler 149e83820edSAxel Dörfler BRegion& BackgroundRegion() 150e83820edSAxel Dörfler { return fBackgroundRegion; } 15133bbe223SAxel Dörfler 15227adb969SAxel Dörfler void WriteWindowList(team_id team, 15327adb969SAxel Dörfler BPrivate::LinkSender& sender); 15427adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 15527adb969SAxel Dörfler BPrivate::LinkSender& sender); 15633bbe223SAxel Dörfler 15733bbe223SAxel Dörfler private: 158e83820edSAxel Dörfler void _ShowWindow(WindowLayer* window, 159e83820edSAxel Dörfler bool affectsOtherWindows = true); 160e83820edSAxel Dörfler void _HideWindow(WindowLayer* window); 161e83820edSAxel Dörfler 162a631158aSAxel Dörfler void _ChangeWindowWorkspaces(WindowLayer* window, 163a631158aSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 164e83820edSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 165e83820edSAxel Dörfler int32 list, bool wereVisible); 16636deda69SAxel Dörfler status_t _ActivateApp(team_id team); 167e83820edSAxel Dörfler 168e83820edSAxel Dörfler void _RebuildClippingForAllWindows(BRegion& stillAvailableOnScreen); 169e83820edSAxel Dörfler void _TriggerWindowRedrawing(BRegion& newDirtyRegion); 170e83820edSAxel Dörfler void _SetBackground(BRegion& background); 171e83820edSAxel Dörfler 172e83820edSAxel Dörfler void _UpdateBack(); 173e83820edSAxel Dörfler void _UpdateFront(); 174e83820edSAxel Dörfler void _UpdateFronts(); 175e83820edSAxel Dörfler 17627adb969SAxel Dörfler void _GetLooperName(char* name, size_t size); 17727adb969SAxel Dörfler void _PrepareQuit(); 17827adb969SAxel Dörfler void _DispatchMessage(int32 code, 17927adb969SAxel Dörfler BPrivate::LinkReceiver &link); 1805f2edc0fSAxel Dörfler 181e83820edSAxel Dörfler WindowList& _CurrentWindows(); 182e83820edSAxel Dörfler 1835f2edc0fSAxel Dörfler private: 184ef8810f2SAxel Dörfler friend class DesktopSettings; 185ef8810f2SAxel Dörfler 18636deda69SAxel Dörfler uid_t fUserID; 187fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 188ef8810f2SAxel Dörfler DesktopSettings::Private* fSettings; 1895f2edc0fSAxel Dörfler port_id fMessagePort; 190f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 1916c17d025SAxel Dörfler port_id fInputPort; 192770c05d6SAxel Dörfler 193e83820edSAxel Dörfler BLocker fApplicationsLock; 194e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 195770c05d6SAxel Dörfler 196770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 197770c05d6SAxel Dörfler int32 fShutdownCount; 198770c05d6SAxel Dörfler 1995ca8477eSAxel Dörfler ::Workspace::Private fWorkspaces[32]; 20027adb969SAxel Dörfler int32 fCurrentWorkspace; 20127adb969SAxel Dörfler 202e83820edSAxel Dörfler WindowList fAllWindows; 20333bbe223SAxel Dörfler 204fa26723bSAxel Dörfler ::RootLayer* fRootLayer; 20533bbe223SAxel Dörfler Screen* fActiveScreen; 2063ddebe7eSMichael Lotz 2073ddebe7eSMichael Lotz CursorManager fCursorManager; 208e83820edSAxel Dörfler 209e83820edSAxel Dörfler #if USE_MULTI_LOCKER 210e83820edSAxel Dörfler MultiLocker fWindowLock; 211e83820edSAxel Dörfler #else 212e83820edSAxel Dörfler BLocker fWindowLock; 213e83820edSAxel Dörfler #endif 214e83820edSAxel Dörfler 215e83820edSAxel Dörfler BRegion fBackgroundRegion; 216e83820edSAxel Dörfler BRegion fScreenRegion; 217e83820edSAxel Dörfler 218e83820edSAxel Dörfler bool fFocusFollowsMouse; 219e83820edSAxel Dörfler 220e83820edSAxel Dörfler WindowLayer* fMouseEventWindow; 221e83820edSAxel Dörfler WindowLayer* fFocus; 222e83820edSAxel Dörfler WindowLayer* fFront; 223e83820edSAxel Dörfler WindowLayer* fBack; 22433bbe223SAxel Dörfler }; 22533bbe223SAxel Dörfler 22627adb969SAxel Dörfler #endif // DESKTOP_H 227