16a0a0a80SAxel Dörfler /* 269f9a367SAxel Dörfler * Copyright 2001-2009, 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 9b09e2f6fSStephan Aßmus * Andrej Spielmann, <andrej.spielmann@seh.ox.ac.uk> 106a0a0a80SAxel Dörfler */ 1127adb969SAxel Dörfler #ifndef DESKTOP_H 1227adb969SAxel Dörfler #define DESKTOP_H 1333bbe223SAxel Dörfler 1408f35604SAxel Dörfler 153ddebe7eSMichael Lotz #include "CursorManager.h" 16ace2d5eeSStephan Aßmus #include "DesktopSettings.h" 1708f35604SAxel Dörfler #include "EventDispatcher.h" 18ace2d5eeSStephan Aßmus #include "MessageLooper.h" 19953d895eSAxel Dörfler #include "Screen.h" 20fd5bec1eSAxel Dörfler #include "ScreenManager.h" 21ace2d5eeSStephan Aßmus #include "ServerCursor.h" 22fd5bec1eSAxel Dörfler #include "VirtualScreen.h" 23e83820edSAxel Dörfler #include "WindowList.h" 2427adb969SAxel Dörfler #include "Workspace.h" 255ca8477eSAxel Dörfler #include "WorkspacePrivate.h" 26fd5bec1eSAxel Dörfler 27e83820edSAxel Dörfler #include <ObjectList.h> 28e83820edSAxel Dörfler 29e83820edSAxel Dörfler #include <Autolock.h> 3033bbe223SAxel Dörfler #include <InterfaceDefs.h> 313dcb3b07SStephan Aßmus #include <List.h> 323dcb3b07SStephan Aßmus #include <Menu.h> 33e83820edSAxel Dörfler #include <Region.h> 3457be2866SAxel Dörfler #include <Window.h> 356a0a0a80SAxel Dörfler 360eed9183SAxel Dörfler 3739c9925fSStephan Aßmus #define USE_MULTI_LOCKER 1 38e83820edSAxel Dörfler 39e83820edSAxel Dörfler #if USE_MULTI_LOCKER 40e83820edSAxel Dörfler # include "MultiLocker.h" 41e83820edSAxel Dörfler #else 42e83820edSAxel Dörfler # include <Locker.h> 43e83820edSAxel Dörfler #endif 4433bbe223SAxel Dörfler 450eed9183SAxel Dörfler 463dcb3b07SStephan Aßmus class BMessage; 476a0a0a80SAxel Dörfler 4858468dfeSStephan Aßmus class DrawingEngine; 493dcb3b07SStephan Aßmus class HWInterface; 50e83820edSAxel Dörfler class ServerApp; 51953d895eSAxel Dörfler class Window; 52953d895eSAxel Dörfler class WorkspacesView; 536d5488e1SAxel Dörfler struct server_read_only_memory; 5433bbe223SAxel Dörfler 556a0a0a80SAxel Dörfler namespace BPrivate { 566a0a0a80SAxel Dörfler class LinkSender; 576a0a0a80SAxel Dörfler }; 586a0a0a80SAxel Dörfler 590eed9183SAxel Dörfler 605f2edc0fSAxel Dörfler class Desktop : public MessageLooper, public ScreenOwner { 6133bbe223SAxel Dörfler public: 6236deda69SAxel Dörfler Desktop(uid_t userID); 633dcb3b07SStephan Aßmus virtual ~Desktop(); 643dcb3b07SStephan Aßmus 656d5488e1SAxel Dörfler status_t Init(); 6636deda69SAxel Dörfler 6736deda69SAxel Dörfler uid_t UserID() const { return fUserID; } 68770c05d6SAxel Dörfler virtual port_id MessagePort() const { return fMessagePort; } 699dbce7a4SAxel Dörfler area_id SharedReadOnlyArea() const 709dbce7a4SAxel Dörfler { return fSharedReadOnlyArea; } 71770c05d6SAxel Dörfler 72f7598223SAxel Dörfler ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 736c17d025SAxel Dörfler 74770c05d6SAxel Dörfler void BroadcastToAllApps(int32 code); 750a3f410fSAxel Dörfler void BroadcastToAllWindows(int32 code); 7633bbe223SAxel Dörfler 770eed9183SAxel Dörfler // Mouse and cursor methods 7833bbe223SAxel Dörfler 79195e980eSAxel Dörfler void SetCursor(ServerCursor* cursor); 80ace2d5eeSStephan Aßmus ServerCursorReference Cursor() const; 814d1c4228SStephan Aßmus void SetLastMouseState(const BPoint& position, 8221b40eddSStephan Aßmus int32 buttons, Window* windowUnderMouse); 834d1c4228SStephan Aßmus // for use by the mouse filter only 844d1c4228SStephan Aßmus // both mouse position calls require 854d1c4228SStephan Aßmus // the Desktop object to be locked 864d1c4228SStephan Aßmus // already 874d1c4228SStephan Aßmus void GetLastMouseState(BPoint* position, 884d1c4228SStephan Aßmus int32* buttons) const; 894d1c4228SStephan Aßmus // for use by ServerWindow 900eed9183SAxel Dörfler 910eed9183SAxel Dörfler // Screen and drawing related methods 920eed9183SAxel Dörfler 930eed9183SAxel Dörfler Screen* ScreenAt(int32 index) const 940eed9183SAxel Dörfler { return fActiveScreen; } 950eed9183SAxel Dörfler Screen* ActiveScreen() const 960eed9183SAxel Dörfler { return fActiveScreen; } 970eed9183SAxel Dörfler 980eed9183SAxel Dörfler CursorManager& GetCursorManager() { return fCursorManager; } 990eed9183SAxel Dörfler 1000eed9183SAxel Dörfler status_t SetScreenMode(int32 workspace, int32 id, 1010eed9183SAxel Dörfler const display_mode& mode, bool makeDefault); 1020eed9183SAxel Dörfler status_t GetScreenMode(int32 workspace, int32 id, 1030eed9183SAxel Dörfler display_mode& mode); 104e18224cdSAxel Dörfler status_t GetScreenFrame(int32 workspace, int32 id, 105e18224cdSAxel Dörfler BRect& frame); 106*5e3f4c41SAxel Dörfler void RevertScreenModes(uint32 workspaces); 1070eed9183SAxel Dörfler 1080eed9183SAxel Dörfler void ScreenChanged(Screen* screen); 1093dcb3b07SStephan Aßmus 110*5e3f4c41SAxel Dörfler const ::VirtualScreen& VirtualScreen() const 111*5e3f4c41SAxel Dörfler { return fVirtualScreen; } 11227adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 11358468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 11427adb969SAxel Dörfler ::HWInterface* HWInterface() const 115fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 11694fa2bd2SAdi Oanca 1170eed9183SAxel Dörfler // ScreenOwner implementation 118*5e3f4c41SAxel Dörfler virtual void ScreenRemoved(Screen* screen) {} 119*5e3f4c41SAxel Dörfler virtual void ScreenAdded(Screen* screen) {} 120*5e3f4c41SAxel Dörfler virtual bool ReleaseScreen(Screen* screen) { return false; } 1210eed9183SAxel Dörfler 12227adb969SAxel Dörfler // Workspace methods 12327adb969SAxel Dörfler 1244d1c4228SStephan Aßmus void SetWorkspaceAsync(int32 index); 12527adb969SAxel Dörfler void SetWorkspace(int32 index); 12627adb969SAxel Dörfler int32 CurrentWorkspace() 12727adb969SAxel Dörfler { return fCurrentWorkspace; } 1285ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 12927adb969SAxel Dörfler { return fWorkspaces[index]; } 13069f9a367SAxel Dörfler status_t SetWorkspacesLayout(int32 columns, int32 rows); 13127c43a2dSRene Gollent BRect WorkspaceFrame(int32 index) const; 13227adb969SAxel Dörfler 133953d895eSAxel Dörfler // Window methods 13427adb969SAxel Dörfler 135953d895eSAxel Dörfler void ActivateWindow(Window* window); 136953d895eSAxel Dörfler void SendWindowBehind(Window* window, 137953d895eSAxel Dörfler Window* behindOf = NULL); 13827adb969SAxel Dörfler 139953d895eSAxel Dörfler void ShowWindow(Window* window); 140953d895eSAxel Dörfler void HideWindow(Window* window); 14115918e4fSAxel Dörfler 142953d895eSAxel Dörfler void MoveWindowBy(Window* window, float x, float y, 14314fe11cfSAxel Dörfler int32 workspace = -1); 1449dbce7a4SAxel Dörfler void ResizeWindowBy(Window* window, float x, 1459dbce7a4SAxel Dörfler float y); 1469dbce7a4SAxel Dörfler bool SetWindowTabLocation(Window* window, 1479dbce7a4SAxel Dörfler float location); 148953d895eSAxel Dörfler bool SetWindowDecoratorSettings(Window* window, 149b30e9021SStephan Aßmus const BMessage& settings); 15019d801a6SAxel Dörfler 151953d895eSAxel Dörfler void SetWindowWorkspaces(Window* window, 152a631158aSAxel Dörfler uint32 workspaces); 15327adb969SAxel Dörfler 154953d895eSAxel Dörfler void AddWindow(Window* window); 155953d895eSAxel Dörfler void RemoveWindow(Window* window); 15657be2866SAxel Dörfler 157953d895eSAxel Dörfler bool AddWindowToSubset(Window* subset, 158953d895eSAxel Dörfler Window* window); 159953d895eSAxel Dörfler void RemoveWindowFromSubset(Window* subset, 160953d895eSAxel Dörfler Window* window); 16134227d2cSAxel Dörfler 1620a3f410fSAxel Dörfler void FontsChanged(Window* window); 1630a3f410fSAxel Dörfler 164953d895eSAxel Dörfler void SetWindowLook(Window* window, window_look look); 165953d895eSAxel Dörfler void SetWindowFeel(Window* window, window_feel feel); 166953d895eSAxel Dörfler void SetWindowFlags(Window* window, uint32 flags); 1679dbce7a4SAxel Dörfler void SetWindowTitle(Window* window, 1689dbce7a4SAxel Dörfler const char* title); 16933bbe223SAxel Dörfler 170953d895eSAxel Dörfler Window* FocusWindow() const { return fFocus; } 171953d895eSAxel Dörfler Window* FrontWindow() const { return fFront; } 172953d895eSAxel Dörfler Window* BackWindow() const { return fBack; } 173e83820edSAxel Dörfler 174953d895eSAxel Dörfler Window* WindowAt(BPoint where); 175e83820edSAxel Dörfler 1769dbce7a4SAxel Dörfler Window* MouseEventWindow() const 1779dbce7a4SAxel Dörfler { return fMouseEventWindow; } 178953d895eSAxel Dörfler void SetMouseEventWindow(Window* window); 179e83820edSAxel Dörfler 1809dbce7a4SAxel Dörfler void SetViewUnderMouse(const Window* window, 1819dbce7a4SAxel Dörfler int32 viewToken); 182953d895eSAxel Dörfler int32 ViewUnderMouse(const Window* window); 1831e766d46SAxel Dörfler 184953d895eSAxel Dörfler void SetFocusWindow(Window* window = NULL); 18507dc2c69SAxel Dörfler EventTarget* KeyboardEventTarget(); 18621b40eddSStephan Aßmus void SetFocusLocked(const Window* window); 187e83820edSAxel Dörfler 188953d895eSAxel Dörfler Window* FindWindowByClientToken(int32 token, 189953d895eSAxel Dörfler team_id teamID); 19095530739SAxel Dörfler EventTarget* FindTarget(BMessenger& messenger); 1916a0a0a80SAxel Dörfler 192e83820edSAxel Dörfler #if USE_MULTI_LOCKER 1939dbce7a4SAxel Dörfler bool LockSingleWindow() 1949dbce7a4SAxel Dörfler { return fWindowLock.ReadLock(); } 1959dbce7a4SAxel Dörfler void UnlockSingleWindow() 1969dbce7a4SAxel Dörfler { fWindowLock.ReadUnlock(); } 197e83820edSAxel Dörfler 1989dbce7a4SAxel Dörfler bool LockAllWindows() 1999dbce7a4SAxel Dörfler { return fWindowLock.WriteLock(); } 2009dbce7a4SAxel Dörfler void UnlockAllWindows() 2019dbce7a4SAxel Dörfler { fWindowLock.WriteUnlock(); } 2020eed9183SAxel Dörfler 2030eed9183SAxel Dörfler MultiLocker WindowLocker() { return fWindowLock; } 204e83820edSAxel Dörfler #else // USE_MULTI_LOCKER 2059dbce7a4SAxel Dörfler bool LockSingleWindow() 2069dbce7a4SAxel Dörfler { return fWindowLock.Lock(); } 2079dbce7a4SAxel Dörfler void UnlockSingleWindow() 2089dbce7a4SAxel Dörfler { fWindowLock.Unlock(); } 209e83820edSAxel Dörfler 2109dbce7a4SAxel Dörfler bool LockAllWindows() 2119dbce7a4SAxel Dörfler { return fWindowLock.Lock(); } 2129dbce7a4SAxel Dörfler void UnlockAllWindows() 2139dbce7a4SAxel Dörfler { fWindowLock.Unlock(); } 214e83820edSAxel Dörfler #endif // USE_MULTI_LOCKER 215e83820edSAxel Dörfler 216e83820edSAxel Dörfler void MarkDirty(BRegion& region); 217b09e2f6fSStephan Aßmus void Redraw(); 218e83820edSAxel Dörfler 219e83820edSAxel Dörfler BRegion& BackgroundRegion() 220e83820edSAxel Dörfler { return fBackgroundRegion; } 22133bbe223SAxel Dörfler 2223dcbe9fcSAxel Dörfler void RedrawBackground(); 22382081c70SJérôme Duval void StoreWorkspaceConfiguration(int32 index); 2243dcbe9fcSAxel Dörfler 225953d895eSAxel Dörfler void AddWorkspacesView(WorkspacesView* view); 226953d895eSAxel Dörfler void RemoveWorkspacesView(WorkspacesView* view); 2272c184b20SAxel Dörfler 228f877af82SAxel Dörfler void MinimizeApplication(team_id team); 229f877af82SAxel Dörfler void BringApplicationToFront(team_id team); 230bfe69873SAxel Dörfler void WindowAction(int32 windowToken, int32 action); 231f877af82SAxel Dörfler 23227adb969SAxel Dörfler void WriteWindowList(team_id team, 23327adb969SAxel Dörfler BPrivate::LinkSender& sender); 23427adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 23527adb969SAxel Dörfler BPrivate::LinkSender& sender); 236ae0606beSAxel Dörfler void WriteApplicationOrder(int32 workspace, 237ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 238ae0606beSAxel Dörfler void WriteWindowOrder(int32 workspace, 239ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 24033bbe223SAxel Dörfler 24133bbe223SAxel Dörfler private: 2426869c8a5SRyan Leavengood void _LaunchInputServer(); 243*5e3f4c41SAxel Dörfler void _SetCurrentWorkspaceConfiguration(); 244a17c3a48SAxel Dörfler void _SetWorkspace(int32 index); 245953d895eSAxel Dörfler void _ShowWindow(Window* window, 246e83820edSAxel Dörfler bool affectsOtherWindows = true); 247953d895eSAxel Dörfler void _HideWindow(Window* window); 248e83820edSAxel Dörfler 249953d895eSAxel Dörfler void _UpdateSubsetWorkspaces(Window* window, 25064747950SAxel Dörfler int32 previousIndex = -1, 25164747950SAxel Dörfler int32 newIndex = -1); 252953d895eSAxel Dörfler void _ChangeWindowWorkspaces(Window* window, 253a631158aSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 254e83820edSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 255e83820edSAxel Dörfler int32 list, bool wereVisible); 256d0283566SAxel Dörfler Window* _LastFocusSubsetWindow(Window* window); 25736deda69SAxel Dörfler status_t _ActivateApp(team_id team); 258953d895eSAxel Dörfler void _SendFakeMouseMoved(Window* window = NULL); 259e83820edSAxel Dörfler 2609dbce7a4SAxel Dörfler void _RebuildClippingForAllWindows( 2619dbce7a4SAxel Dörfler BRegion& stillAvailableOnScreen); 2629dbce7a4SAxel Dörfler void _TriggerWindowRedrawing( 2639dbce7a4SAxel Dörfler BRegion& newDirtyRegion); 264e83820edSAxel Dörfler void _SetBackground(BRegion& background); 2650a3f410fSAxel Dörfler void _RebuildAndRedrawAfterWindowChange( 2660a3f410fSAxel Dörfler Window* window, BRegion& dirty); 267e83820edSAxel Dörfler 26834227d2cSAxel Dörfler void _UpdateFloating(int32 previousWorkspace = -1, 269d479fa7aSAxel Dörfler int32 nextWorkspace = -1, 270953d895eSAxel Dörfler Window* mouseEventWindow = NULL); 271e83820edSAxel Dörfler void _UpdateBack(); 27234227d2cSAxel Dörfler void _UpdateFront(bool updateFloating = true); 27334227d2cSAxel Dörfler void _UpdateFronts(bool updateFloating = true); 274953d895eSAxel Dörfler bool _WindowHasModal(Window* window); 275e83820edSAxel Dörfler 276953d895eSAxel Dörfler void _WindowChanged(Window* window); 277953d895eSAxel Dörfler void _WindowRemoved(Window* window); 278ce8c4d79SAxel Dörfler 27927adb969SAxel Dörfler void _GetLooperName(char* name, size_t size); 28027adb969SAxel Dörfler void _PrepareQuit(); 28127adb969SAxel Dörfler void _DispatchMessage(int32 code, 28227adb969SAxel Dörfler BPrivate::LinkReceiver &link); 2835f2edc0fSAxel Dörfler 284e83820edSAxel Dörfler WindowList& _CurrentWindows(); 28534227d2cSAxel Dörfler WindowList& _Windows(int32 index); 286e83820edSAxel Dörfler 2875f2edc0fSAxel Dörfler private: 288ef8810f2SAxel Dörfler friend class DesktopSettings; 289a17c3a48SAxel Dörfler friend class LockedDesktopSettings; 290ef8810f2SAxel Dörfler 29136deda69SAxel Dörfler uid_t fUserID; 292fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 293a17c3a48SAxel Dörfler DesktopSettingsPrivate* fSettings; 2945f2edc0fSAxel Dörfler port_id fMessagePort; 295f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 2966c17d025SAxel Dörfler port_id fInputPort; 2976d5488e1SAxel Dörfler area_id fSharedReadOnlyArea; 2986d5488e1SAxel Dörfler server_read_only_memory* fServerReadOnlyMemory; 299770c05d6SAxel Dörfler 300e83820edSAxel Dörfler BLocker fApplicationsLock; 301e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 302770c05d6SAxel Dörfler 303770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 304770c05d6SAxel Dörfler int32 fShutdownCount; 305770c05d6SAxel Dörfler 30682081c70SJérôme Duval ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 30727adb969SAxel Dörfler int32 fCurrentWorkspace; 3084932bc5eSAxel Dörfler int32 fPreviousWorkspace; 30927adb969SAxel Dörfler 310e83820edSAxel Dörfler WindowList fAllWindows; 31134227d2cSAxel Dörfler WindowList fSubsetWindows; 312d01879e5SAxel Dörfler WindowList fFocusList; 313d8ebe612SAxel Dörfler 314953d895eSAxel Dörfler BObjectList<WorkspacesView> fWorkspacesViews; 315d8ebe612SAxel Dörfler BLocker fWorkspacesLock; 31633bbe223SAxel Dörfler 31733bbe223SAxel Dörfler Screen* fActiveScreen; 3183ddebe7eSMichael Lotz 3193ddebe7eSMichael Lotz CursorManager fCursorManager; 320e83820edSAxel Dörfler 321e83820edSAxel Dörfler #if USE_MULTI_LOCKER 322e83820edSAxel Dörfler MultiLocker fWindowLock; 323e83820edSAxel Dörfler #else 324e83820edSAxel Dörfler BLocker fWindowLock; 325e83820edSAxel Dörfler #endif 326e83820edSAxel Dörfler 327e83820edSAxel Dörfler BRegion fBackgroundRegion; 328e83820edSAxel Dörfler BRegion fScreenRegion; 329e83820edSAxel Dörfler 330953d895eSAxel Dörfler Window* fMouseEventWindow; 331953d895eSAxel Dörfler const Window* fWindowUnderMouse; 33221b40eddSStephan Aßmus const Window* fLockedFocusWindow; 3331e766d46SAxel Dörfler int32 fViewUnderMouse; 3344d1c4228SStephan Aßmus BPoint fLastMousePosition; 3354d1c4228SStephan Aßmus int32 fLastMouseButtons; 3361e766d46SAxel Dörfler 337953d895eSAxel Dörfler Window* fFocus; 338953d895eSAxel Dörfler Window* fFront; 339953d895eSAxel Dörfler Window* fBack; 34033bbe223SAxel Dörfler }; 34133bbe223SAxel Dörfler 34227adb969SAxel Dörfler #endif // DESKTOP_H 343