16a0a0a80SAxel Dörfler /* 2d01879e5SAxel Dörfler * Copyright 2001-2008, 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" 15*ace2d5eeSStephan Aßmus #include "DesktopSettings.h" 1608f35604SAxel Dörfler #include "EventDispatcher.h" 17*ace2d5eeSStephan Aßmus #include "MessageLooper.h" 18953d895eSAxel Dörfler #include "Screen.h" 19fd5bec1eSAxel Dörfler #include "ScreenManager.h" 20*ace2d5eeSStephan Aßmus #include "ServerCursor.h" 21fd5bec1eSAxel Dörfler #include "VirtualScreen.h" 22e83820edSAxel Dörfler #include "WindowList.h" 2327adb969SAxel Dörfler #include "Workspace.h" 245ca8477eSAxel Dörfler #include "WorkspacePrivate.h" 25fd5bec1eSAxel Dörfler 26e83820edSAxel Dörfler #include <ObjectList.h> 27e83820edSAxel Dörfler 28e83820edSAxel Dörfler #include <Autolock.h> 2933bbe223SAxel Dörfler #include <InterfaceDefs.h> 303dcb3b07SStephan Aßmus #include <List.h> 313dcb3b07SStephan Aßmus #include <Menu.h> 32e83820edSAxel Dörfler #include <Region.h> 3357be2866SAxel Dörfler #include <Window.h> 346a0a0a80SAxel Dörfler 3539c9925fSStephan Aßmus #define USE_MULTI_LOCKER 1 36e83820edSAxel Dörfler 37e83820edSAxel Dörfler #if USE_MULTI_LOCKER 38e83820edSAxel Dörfler # include "MultiLocker.h" 39e83820edSAxel Dörfler #else 40e83820edSAxel Dörfler # include <Locker.h> 41e83820edSAxel Dörfler #endif 4233bbe223SAxel Dörfler 433dcb3b07SStephan Aßmus class BMessage; 446a0a0a80SAxel Dörfler 4558468dfeSStephan Aßmus class DrawingEngine; 463dcb3b07SStephan Aßmus class HWInterface; 47e83820edSAxel Dörfler class ServerApp; 48953d895eSAxel Dörfler class Window; 49953d895eSAxel Dörfler class WorkspacesView; 506d5488e1SAxel Dörfler struct server_read_only_memory; 5133bbe223SAxel Dörfler 526a0a0a80SAxel Dörfler namespace BPrivate { 536a0a0a80SAxel Dörfler class LinkSender; 546a0a0a80SAxel Dörfler }; 556a0a0a80SAxel Dörfler 565f2edc0fSAxel Dörfler class Desktop : public MessageLooper, public ScreenOwner { 5733bbe223SAxel Dörfler public: 5836deda69SAxel Dörfler Desktop(uid_t userID); 593dcb3b07SStephan Aßmus virtual ~Desktop(); 603dcb3b07SStephan Aßmus 616d5488e1SAxel Dörfler status_t Init(); 6236deda69SAxel Dörfler 6336deda69SAxel Dörfler uid_t UserID() const { return fUserID; } 64770c05d6SAxel Dörfler virtual port_id MessagePort() const { return fMessagePort; } 659dbce7a4SAxel Dörfler area_id SharedReadOnlyArea() const 669dbce7a4SAxel Dörfler { return fSharedReadOnlyArea; } 67770c05d6SAxel Dörfler 68f7598223SAxel Dörfler ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 696c17d025SAxel Dörfler 70770c05d6SAxel Dörfler void BroadcastToAllApps(int32 code); 7133bbe223SAxel Dörfler 7227adb969SAxel Dörfler // Screen and drawing related methods 7327adb969SAxel Dörfler 7427adb969SAxel Dörfler Screen* ScreenAt(int32 index) const 75fd5bec1eSAxel Dörfler { return fActiveScreen; } 7627adb969SAxel Dörfler Screen* ActiveScreen() const 7794fa2bd2SAdi Oanca { return fActiveScreen; } 78e83820edSAxel Dörfler 7927adb969SAxel Dörfler CursorManager& GetCursorManager() { return fCursorManager; } 8033bbe223SAxel Dörfler 81195e980eSAxel Dörfler void SetCursor(ServerCursor* cursor); 82*ace2d5eeSStephan Aßmus ServerCursorReference Cursor() const; 834d1c4228SStephan Aßmus void SetLastMouseState(const BPoint& position, 844d1c4228SStephan Aßmus int32 buttons); 854d1c4228SStephan Aßmus // for use by the mouse filter only 864d1c4228SStephan Aßmus // both mouse position calls require 874d1c4228SStephan Aßmus // the Desktop object to be locked 884d1c4228SStephan Aßmus // already 894d1c4228SStephan Aßmus void GetLastMouseState(BPoint* position, 904d1c4228SStephan Aßmus int32* buttons) const; 914d1c4228SStephan Aßmus // for use by ServerWindow 92195e980eSAxel Dörfler 938527f8ffSAxel Dörfler void ScreenChanged(Screen* screen, bool makeDefault); 94df362433SAxel Dörfler 9527adb969SAxel Dörfler void ScreenRemoved(Screen* screen) {} 9627adb969SAxel Dörfler void ScreenAdded(Screen* screen) {} 9727adb969SAxel Dörfler bool ReleaseScreen(Screen* screen) { return false; } 983dcb3b07SStephan Aßmus 99fd5bec1eSAxel Dörfler const ::VirtualScreen& VirtualScreen() const { return fVirtualScreen; } 10027adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 10158468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 10227adb969SAxel Dörfler ::HWInterface* HWInterface() const 103fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 10494fa2bd2SAdi Oanca 10527adb969SAxel Dörfler // Workspace methods 10627adb969SAxel Dörfler 1074d1c4228SStephan Aßmus void SetWorkspaceAsync(int32 index); 10827adb969SAxel Dörfler void SetWorkspace(int32 index); 10927adb969SAxel Dörfler int32 CurrentWorkspace() 11027adb969SAxel Dörfler { return fCurrentWorkspace; } 1115ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 11227adb969SAxel Dörfler { return fWorkspaces[index]; } 113a17c3a48SAxel Dörfler status_t SetWorkspacesCount(int32 newCount); 11427adb969SAxel Dörfler 115953d895eSAxel Dörfler // Window methods 11627adb969SAxel Dörfler 117953d895eSAxel Dörfler void ActivateWindow(Window* window); 118953d895eSAxel Dörfler void SendWindowBehind(Window* window, 119953d895eSAxel Dörfler Window* behindOf = NULL); 12027adb969SAxel Dörfler 121953d895eSAxel Dörfler void ShowWindow(Window* window); 122953d895eSAxel Dörfler void HideWindow(Window* window); 12315918e4fSAxel Dörfler 124953d895eSAxel Dörfler void MoveWindowBy(Window* window, float x, float y, 12514fe11cfSAxel Dörfler int32 workspace = -1); 1269dbce7a4SAxel Dörfler void ResizeWindowBy(Window* window, float x, 1279dbce7a4SAxel Dörfler float y); 1289dbce7a4SAxel Dörfler bool SetWindowTabLocation(Window* window, 1299dbce7a4SAxel Dörfler float location); 130953d895eSAxel Dörfler bool SetWindowDecoratorSettings(Window* window, 131b30e9021SStephan Aßmus const BMessage& settings); 13219d801a6SAxel Dörfler 133953d895eSAxel Dörfler void SetWindowWorkspaces(Window* window, 134a631158aSAxel Dörfler uint32 workspaces); 13527adb969SAxel Dörfler 136953d895eSAxel Dörfler void AddWindow(Window* window); 137953d895eSAxel Dörfler void RemoveWindow(Window* window); 13857be2866SAxel Dörfler 139953d895eSAxel Dörfler bool AddWindowToSubset(Window* subset, 140953d895eSAxel Dörfler Window* window); 141953d895eSAxel Dörfler void RemoveWindowFromSubset(Window* subset, 142953d895eSAxel Dörfler Window* window); 14334227d2cSAxel Dörfler 144953d895eSAxel Dörfler void SetWindowLook(Window* window, window_look look); 145953d895eSAxel Dörfler void SetWindowFeel(Window* window, window_feel feel); 146953d895eSAxel Dörfler void SetWindowFlags(Window* window, uint32 flags); 1479dbce7a4SAxel Dörfler void SetWindowTitle(Window* window, 1489dbce7a4SAxel Dörfler const char* title); 14933bbe223SAxel Dörfler 150953d895eSAxel Dörfler Window* FocusWindow() const { return fFocus; } 151953d895eSAxel Dörfler Window* FrontWindow() const { return fFront; } 152953d895eSAxel Dörfler Window* BackWindow() const { return fBack; } 153e83820edSAxel Dörfler 154953d895eSAxel Dörfler Window* WindowAt(BPoint where); 155e83820edSAxel Dörfler 1569dbce7a4SAxel Dörfler Window* MouseEventWindow() const 1579dbce7a4SAxel Dörfler { return fMouseEventWindow; } 158953d895eSAxel Dörfler void SetMouseEventWindow(Window* window); 159e83820edSAxel Dörfler 1609dbce7a4SAxel Dörfler void SetViewUnderMouse(const Window* window, 1619dbce7a4SAxel Dörfler int32 viewToken); 162953d895eSAxel Dörfler int32 ViewUnderMouse(const Window* window); 1631e766d46SAxel Dörfler 164953d895eSAxel Dörfler void SetFocusWindow(Window* window = NULL); 16507dc2c69SAxel Dörfler EventTarget* KeyboardEventTarget(); 166e83820edSAxel Dörfler 167953d895eSAxel Dörfler Window* FindWindowByClientToken(int32 token, 168953d895eSAxel Dörfler team_id teamID); 1696a0a0a80SAxel Dörfler 170e83820edSAxel Dörfler #if USE_MULTI_LOCKER 1719dbce7a4SAxel Dörfler bool LockSingleWindow() 1729dbce7a4SAxel Dörfler { return fWindowLock.ReadLock(); } 1739dbce7a4SAxel Dörfler void UnlockSingleWindow() 1749dbce7a4SAxel Dörfler { fWindowLock.ReadUnlock(); } 175e83820edSAxel Dörfler 1769dbce7a4SAxel Dörfler bool LockAllWindows() 1779dbce7a4SAxel Dörfler { return fWindowLock.WriteLock(); } 1789dbce7a4SAxel Dörfler void UnlockAllWindows() 1799dbce7a4SAxel Dörfler { fWindowLock.WriteUnlock(); } 180e83820edSAxel Dörfler #else // USE_MULTI_LOCKER 1819dbce7a4SAxel Dörfler bool LockSingleWindow() 1829dbce7a4SAxel Dörfler { return fWindowLock.Lock(); } 1839dbce7a4SAxel Dörfler void UnlockSingleWindow() 1849dbce7a4SAxel Dörfler { fWindowLock.Unlock(); } 185e83820edSAxel Dörfler 1869dbce7a4SAxel Dörfler bool LockAllWindows() 1879dbce7a4SAxel Dörfler { return fWindowLock.Lock(); } 1889dbce7a4SAxel Dörfler void UnlockAllWindows() 1899dbce7a4SAxel Dörfler { fWindowLock.Unlock(); } 190e83820edSAxel Dörfler #endif // USE_MULTI_LOCKER 191e83820edSAxel Dörfler 192e83820edSAxel Dörfler void MarkDirty(BRegion& region); 193e83820edSAxel Dörfler 194e83820edSAxel Dörfler BRegion& BackgroundRegion() 195e83820edSAxel Dörfler { return fBackgroundRegion; } 19633bbe223SAxel Dörfler 1973dcbe9fcSAxel Dörfler void RedrawBackground(); 19882081c70SJérôme Duval void StoreWorkspaceConfiguration(int32 index); 1993dcbe9fcSAxel Dörfler 200953d895eSAxel Dörfler void AddWorkspacesView(WorkspacesView* view); 201953d895eSAxel Dörfler void RemoveWorkspacesView(WorkspacesView* view); 2022c184b20SAxel Dörfler 203f877af82SAxel Dörfler void MinimizeApplication(team_id team); 204f877af82SAxel Dörfler void BringApplicationToFront(team_id team); 205bfe69873SAxel Dörfler void WindowAction(int32 windowToken, int32 action); 206f877af82SAxel Dörfler 20727adb969SAxel Dörfler void WriteWindowList(team_id team, 20827adb969SAxel Dörfler BPrivate::LinkSender& sender); 20927adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 21027adb969SAxel Dörfler BPrivate::LinkSender& sender); 21133bbe223SAxel Dörfler 21233bbe223SAxel Dörfler private: 2136869c8a5SRyan Leavengood void _LaunchInputServer(); 214a17c3a48SAxel Dörfler void _SetWorkspace(int32 index); 215953d895eSAxel Dörfler void _ShowWindow(Window* window, 216e83820edSAxel Dörfler bool affectsOtherWindows = true); 217953d895eSAxel Dörfler void _HideWindow(Window* window); 218e83820edSAxel Dörfler 219953d895eSAxel Dörfler void _UpdateSubsetWorkspaces(Window* window, 22064747950SAxel Dörfler int32 previousIndex = -1, 22164747950SAxel Dörfler int32 newIndex = -1); 222953d895eSAxel Dörfler void _ChangeWindowWorkspaces(Window* window, 223a631158aSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 224e83820edSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 225e83820edSAxel Dörfler int32 list, bool wereVisible); 22636deda69SAxel Dörfler status_t _ActivateApp(team_id team); 227953d895eSAxel Dörfler void _SendFakeMouseMoved(Window* window = NULL); 228e83820edSAxel Dörfler 2299dbce7a4SAxel Dörfler void _RebuildClippingForAllWindows( 2309dbce7a4SAxel Dörfler BRegion& stillAvailableOnScreen); 2319dbce7a4SAxel Dörfler void _TriggerWindowRedrawing( 2329dbce7a4SAxel Dörfler BRegion& newDirtyRegion); 233e83820edSAxel Dörfler void _SetBackground(BRegion& background); 234e83820edSAxel Dörfler 23534227d2cSAxel Dörfler void _UpdateFloating(int32 previousWorkspace = -1, 236d479fa7aSAxel Dörfler int32 nextWorkspace = -1, 237953d895eSAxel Dörfler Window* mouseEventWindow = NULL); 238e83820edSAxel Dörfler void _UpdateBack(); 23934227d2cSAxel Dörfler void _UpdateFront(bool updateFloating = true); 24034227d2cSAxel Dörfler void _UpdateFronts(bool updateFloating = true); 241953d895eSAxel Dörfler bool _WindowHasModal(Window* window); 242e83820edSAxel Dörfler 243953d895eSAxel Dörfler void _WindowChanged(Window* window); 244953d895eSAxel Dörfler void _WindowRemoved(Window* window); 245ce8c4d79SAxel Dörfler 24627adb969SAxel Dörfler void _GetLooperName(char* name, size_t size); 24727adb969SAxel Dörfler void _PrepareQuit(); 24827adb969SAxel Dörfler void _DispatchMessage(int32 code, 24927adb969SAxel Dörfler BPrivate::LinkReceiver &link); 2505f2edc0fSAxel Dörfler 251e83820edSAxel Dörfler WindowList& _CurrentWindows(); 25234227d2cSAxel Dörfler WindowList& _Windows(int32 index); 253e83820edSAxel Dörfler 2545f2edc0fSAxel Dörfler private: 255ef8810f2SAxel Dörfler friend class DesktopSettings; 256a17c3a48SAxel Dörfler friend class LockedDesktopSettings; 257ef8810f2SAxel Dörfler 25836deda69SAxel Dörfler uid_t fUserID; 259fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 260a17c3a48SAxel Dörfler DesktopSettingsPrivate* fSettings; 2615f2edc0fSAxel Dörfler port_id fMessagePort; 262f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 2636c17d025SAxel Dörfler port_id fInputPort; 2646d5488e1SAxel Dörfler area_id fSharedReadOnlyArea; 2656d5488e1SAxel Dörfler server_read_only_memory* fServerReadOnlyMemory; 266770c05d6SAxel Dörfler 267e83820edSAxel Dörfler BLocker fApplicationsLock; 268e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 269770c05d6SAxel Dörfler 270770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 271770c05d6SAxel Dörfler int32 fShutdownCount; 272770c05d6SAxel Dörfler 27382081c70SJérôme Duval ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 27427adb969SAxel Dörfler int32 fCurrentWorkspace; 27527adb969SAxel Dörfler 276e83820edSAxel Dörfler WindowList fAllWindows; 27734227d2cSAxel Dörfler WindowList fSubsetWindows; 278d01879e5SAxel Dörfler WindowList fFocusList; 279d8ebe612SAxel Dörfler 280953d895eSAxel Dörfler BObjectList<WorkspacesView> fWorkspacesViews; 281d8ebe612SAxel Dörfler BLocker fWorkspacesLock; 28233bbe223SAxel Dörfler 28333bbe223SAxel Dörfler Screen* fActiveScreen; 2843ddebe7eSMichael Lotz 2853ddebe7eSMichael Lotz CursorManager fCursorManager; 286e83820edSAxel Dörfler 287e83820edSAxel Dörfler #if USE_MULTI_LOCKER 288e83820edSAxel Dörfler MultiLocker fWindowLock; 289e83820edSAxel Dörfler #else 290e83820edSAxel Dörfler BLocker fWindowLock; 291e83820edSAxel Dörfler #endif 292e83820edSAxel Dörfler 293e83820edSAxel Dörfler BRegion fBackgroundRegion; 294e83820edSAxel Dörfler BRegion fScreenRegion; 295e83820edSAxel Dörfler 296953d895eSAxel Dörfler Window* fMouseEventWindow; 297953d895eSAxel Dörfler const Window* fWindowUnderMouse; 2981e766d46SAxel Dörfler int32 fViewUnderMouse; 2994d1c4228SStephan Aßmus BPoint fLastMousePosition; 3004d1c4228SStephan Aßmus int32 fLastMouseButtons; 3011e766d46SAxel Dörfler 302953d895eSAxel Dörfler Window* fFocus; 303953d895eSAxel Dörfler Window* fFront; 304953d895eSAxel Dörfler Window* fBack; 30533bbe223SAxel Dörfler }; 30633bbe223SAxel Dörfler 30727adb969SAxel Dörfler #endif // DESKTOP_H 308