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); 104*e18224cdSAxel Dörfler status_t GetScreenFrame(int32 workspace, int32 id, 105*e18224cdSAxel Dörfler BRect& frame); 1060eed9183SAxel Dörfler 1070eed9183SAxel Dörfler void ScreenChanged(Screen* screen); 1083dcb3b07SStephan Aßmus 109fd5bec1eSAxel Dörfler const ::VirtualScreen& VirtualScreen() const { return fVirtualScreen; } 11027adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 11158468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 11227adb969SAxel Dörfler ::HWInterface* HWInterface() const 113fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 11494fa2bd2SAdi Oanca 1150eed9183SAxel Dörfler // ScreenOwner implementation 1160eed9183SAxel Dörfler void ScreenRemoved(Screen* screen) {} 1170eed9183SAxel Dörfler void ScreenAdded(Screen* screen) {} 1180eed9183SAxel Dörfler bool ReleaseScreen(Screen* screen) { return false; } 1190eed9183SAxel Dörfler 12027adb969SAxel Dörfler // Workspace methods 12127adb969SAxel Dörfler 1224d1c4228SStephan Aßmus void SetWorkspaceAsync(int32 index); 12327adb969SAxel Dörfler void SetWorkspace(int32 index); 12427adb969SAxel Dörfler int32 CurrentWorkspace() 12527adb969SAxel Dörfler { return fCurrentWorkspace; } 1265ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 12727adb969SAxel Dörfler { return fWorkspaces[index]; } 12869f9a367SAxel Dörfler status_t SetWorkspacesLayout(int32 columns, int32 rows); 12927c43a2dSRene Gollent BRect WorkspaceFrame(int32 index) const; 13027adb969SAxel Dörfler 131953d895eSAxel Dörfler // Window methods 13227adb969SAxel Dörfler 133953d895eSAxel Dörfler void ActivateWindow(Window* window); 134953d895eSAxel Dörfler void SendWindowBehind(Window* window, 135953d895eSAxel Dörfler Window* behindOf = NULL); 13627adb969SAxel Dörfler 137953d895eSAxel Dörfler void ShowWindow(Window* window); 138953d895eSAxel Dörfler void HideWindow(Window* window); 13915918e4fSAxel Dörfler 140953d895eSAxel Dörfler void MoveWindowBy(Window* window, float x, float y, 14114fe11cfSAxel Dörfler int32 workspace = -1); 1429dbce7a4SAxel Dörfler void ResizeWindowBy(Window* window, float x, 1439dbce7a4SAxel Dörfler float y); 1449dbce7a4SAxel Dörfler bool SetWindowTabLocation(Window* window, 1459dbce7a4SAxel Dörfler float location); 146953d895eSAxel Dörfler bool SetWindowDecoratorSettings(Window* window, 147b30e9021SStephan Aßmus const BMessage& settings); 14819d801a6SAxel Dörfler 149953d895eSAxel Dörfler void SetWindowWorkspaces(Window* window, 150a631158aSAxel Dörfler uint32 workspaces); 15127adb969SAxel Dörfler 152953d895eSAxel Dörfler void AddWindow(Window* window); 153953d895eSAxel Dörfler void RemoveWindow(Window* window); 15457be2866SAxel Dörfler 155953d895eSAxel Dörfler bool AddWindowToSubset(Window* subset, 156953d895eSAxel Dörfler Window* window); 157953d895eSAxel Dörfler void RemoveWindowFromSubset(Window* subset, 158953d895eSAxel Dörfler Window* window); 15934227d2cSAxel Dörfler 1600a3f410fSAxel Dörfler void FontsChanged(Window* window); 1610a3f410fSAxel Dörfler 162953d895eSAxel Dörfler void SetWindowLook(Window* window, window_look look); 163953d895eSAxel Dörfler void SetWindowFeel(Window* window, window_feel feel); 164953d895eSAxel Dörfler void SetWindowFlags(Window* window, uint32 flags); 1659dbce7a4SAxel Dörfler void SetWindowTitle(Window* window, 1669dbce7a4SAxel Dörfler const char* title); 16733bbe223SAxel Dörfler 168953d895eSAxel Dörfler Window* FocusWindow() const { return fFocus; } 169953d895eSAxel Dörfler Window* FrontWindow() const { return fFront; } 170953d895eSAxel Dörfler Window* BackWindow() const { return fBack; } 171e83820edSAxel Dörfler 172953d895eSAxel Dörfler Window* WindowAt(BPoint where); 173e83820edSAxel Dörfler 1749dbce7a4SAxel Dörfler Window* MouseEventWindow() const 1759dbce7a4SAxel Dörfler { return fMouseEventWindow; } 176953d895eSAxel Dörfler void SetMouseEventWindow(Window* window); 177e83820edSAxel Dörfler 1789dbce7a4SAxel Dörfler void SetViewUnderMouse(const Window* window, 1799dbce7a4SAxel Dörfler int32 viewToken); 180953d895eSAxel Dörfler int32 ViewUnderMouse(const Window* window); 1811e766d46SAxel Dörfler 182953d895eSAxel Dörfler void SetFocusWindow(Window* window = NULL); 18307dc2c69SAxel Dörfler EventTarget* KeyboardEventTarget(); 18421b40eddSStephan Aßmus void SetFocusLocked(const Window* window); 185e83820edSAxel Dörfler 186953d895eSAxel Dörfler Window* FindWindowByClientToken(int32 token, 187953d895eSAxel Dörfler team_id teamID); 18895530739SAxel Dörfler EventTarget* FindTarget(BMessenger& messenger); 1896a0a0a80SAxel Dörfler 190e83820edSAxel Dörfler #if USE_MULTI_LOCKER 1919dbce7a4SAxel Dörfler bool LockSingleWindow() 1929dbce7a4SAxel Dörfler { return fWindowLock.ReadLock(); } 1939dbce7a4SAxel Dörfler void UnlockSingleWindow() 1949dbce7a4SAxel Dörfler { fWindowLock.ReadUnlock(); } 195e83820edSAxel Dörfler 1969dbce7a4SAxel Dörfler bool LockAllWindows() 1979dbce7a4SAxel Dörfler { return fWindowLock.WriteLock(); } 1989dbce7a4SAxel Dörfler void UnlockAllWindows() 1999dbce7a4SAxel Dörfler { fWindowLock.WriteUnlock(); } 2000eed9183SAxel Dörfler 2010eed9183SAxel Dörfler MultiLocker WindowLocker() { return fWindowLock; } 202e83820edSAxel Dörfler #else // USE_MULTI_LOCKER 2039dbce7a4SAxel Dörfler bool LockSingleWindow() 2049dbce7a4SAxel Dörfler { return fWindowLock.Lock(); } 2059dbce7a4SAxel Dörfler void UnlockSingleWindow() 2069dbce7a4SAxel Dörfler { fWindowLock.Unlock(); } 207e83820edSAxel Dörfler 2089dbce7a4SAxel Dörfler bool LockAllWindows() 2099dbce7a4SAxel Dörfler { return fWindowLock.Lock(); } 2109dbce7a4SAxel Dörfler void UnlockAllWindows() 2119dbce7a4SAxel Dörfler { fWindowLock.Unlock(); } 212e83820edSAxel Dörfler #endif // USE_MULTI_LOCKER 213e83820edSAxel Dörfler 214e83820edSAxel Dörfler void MarkDirty(BRegion& region); 215b09e2f6fSStephan Aßmus void Redraw(); 216e83820edSAxel Dörfler 217e83820edSAxel Dörfler BRegion& BackgroundRegion() 218e83820edSAxel Dörfler { return fBackgroundRegion; } 21933bbe223SAxel Dörfler 2203dcbe9fcSAxel Dörfler void RedrawBackground(); 22182081c70SJérôme Duval void StoreWorkspaceConfiguration(int32 index); 2223dcbe9fcSAxel Dörfler 223953d895eSAxel Dörfler void AddWorkspacesView(WorkspacesView* view); 224953d895eSAxel Dörfler void RemoveWorkspacesView(WorkspacesView* view); 2252c184b20SAxel Dörfler 226f877af82SAxel Dörfler void MinimizeApplication(team_id team); 227f877af82SAxel Dörfler void BringApplicationToFront(team_id team); 228bfe69873SAxel Dörfler void WindowAction(int32 windowToken, int32 action); 229f877af82SAxel Dörfler 23027adb969SAxel Dörfler void WriteWindowList(team_id team, 23127adb969SAxel Dörfler BPrivate::LinkSender& sender); 23227adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 23327adb969SAxel Dörfler BPrivate::LinkSender& sender); 234ae0606beSAxel Dörfler void WriteApplicationOrder(int32 workspace, 235ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 236ae0606beSAxel Dörfler void WriteWindowOrder(int32 workspace, 237ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 23833bbe223SAxel Dörfler 23933bbe223SAxel Dörfler private: 2406869c8a5SRyan Leavengood void _LaunchInputServer(); 241a17c3a48SAxel Dörfler void _SetWorkspace(int32 index); 242953d895eSAxel Dörfler void _ShowWindow(Window* window, 243e83820edSAxel Dörfler bool affectsOtherWindows = true); 244953d895eSAxel Dörfler void _HideWindow(Window* window); 245e83820edSAxel Dörfler 246953d895eSAxel Dörfler void _UpdateSubsetWorkspaces(Window* window, 24764747950SAxel Dörfler int32 previousIndex = -1, 24864747950SAxel Dörfler int32 newIndex = -1); 249953d895eSAxel Dörfler void _ChangeWindowWorkspaces(Window* window, 250a631158aSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 251e83820edSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 252e83820edSAxel Dörfler int32 list, bool wereVisible); 253d0283566SAxel Dörfler Window* _LastFocusSubsetWindow(Window* window); 25436deda69SAxel Dörfler status_t _ActivateApp(team_id team); 255953d895eSAxel Dörfler void _SendFakeMouseMoved(Window* window = NULL); 256e83820edSAxel Dörfler 2579dbce7a4SAxel Dörfler void _RebuildClippingForAllWindows( 2589dbce7a4SAxel Dörfler BRegion& stillAvailableOnScreen); 2599dbce7a4SAxel Dörfler void _TriggerWindowRedrawing( 2609dbce7a4SAxel Dörfler BRegion& newDirtyRegion); 261e83820edSAxel Dörfler void _SetBackground(BRegion& background); 2620a3f410fSAxel Dörfler void _RebuildAndRedrawAfterWindowChange( 2630a3f410fSAxel Dörfler Window* window, BRegion& dirty); 264e83820edSAxel Dörfler 26534227d2cSAxel Dörfler void _UpdateFloating(int32 previousWorkspace = -1, 266d479fa7aSAxel Dörfler int32 nextWorkspace = -1, 267953d895eSAxel Dörfler Window* mouseEventWindow = NULL); 268e83820edSAxel Dörfler void _UpdateBack(); 26934227d2cSAxel Dörfler void _UpdateFront(bool updateFloating = true); 27034227d2cSAxel Dörfler void _UpdateFronts(bool updateFloating = true); 271953d895eSAxel Dörfler bool _WindowHasModal(Window* window); 272e83820edSAxel Dörfler 273953d895eSAxel Dörfler void _WindowChanged(Window* window); 274953d895eSAxel Dörfler void _WindowRemoved(Window* window); 275ce8c4d79SAxel Dörfler 27627adb969SAxel Dörfler void _GetLooperName(char* name, size_t size); 27727adb969SAxel Dörfler void _PrepareQuit(); 27827adb969SAxel Dörfler void _DispatchMessage(int32 code, 27927adb969SAxel Dörfler BPrivate::LinkReceiver &link); 2805f2edc0fSAxel Dörfler 281e83820edSAxel Dörfler WindowList& _CurrentWindows(); 28234227d2cSAxel Dörfler WindowList& _Windows(int32 index); 283e83820edSAxel Dörfler 2845f2edc0fSAxel Dörfler private: 285ef8810f2SAxel Dörfler friend class DesktopSettings; 286a17c3a48SAxel Dörfler friend class LockedDesktopSettings; 287ef8810f2SAxel Dörfler 28836deda69SAxel Dörfler uid_t fUserID; 289fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 290a17c3a48SAxel Dörfler DesktopSettingsPrivate* fSettings; 2915f2edc0fSAxel Dörfler port_id fMessagePort; 292f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 2936c17d025SAxel Dörfler port_id fInputPort; 2946d5488e1SAxel Dörfler area_id fSharedReadOnlyArea; 2956d5488e1SAxel Dörfler server_read_only_memory* fServerReadOnlyMemory; 296770c05d6SAxel Dörfler 297e83820edSAxel Dörfler BLocker fApplicationsLock; 298e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 299770c05d6SAxel Dörfler 300770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 301770c05d6SAxel Dörfler int32 fShutdownCount; 302770c05d6SAxel Dörfler 30382081c70SJérôme Duval ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 30427adb969SAxel Dörfler int32 fCurrentWorkspace; 3054932bc5eSAxel Dörfler int32 fPreviousWorkspace; 30627adb969SAxel Dörfler 307e83820edSAxel Dörfler WindowList fAllWindows; 30834227d2cSAxel Dörfler WindowList fSubsetWindows; 309d01879e5SAxel Dörfler WindowList fFocusList; 310d8ebe612SAxel Dörfler 311953d895eSAxel Dörfler BObjectList<WorkspacesView> fWorkspacesViews; 312d8ebe612SAxel Dörfler BLocker fWorkspacesLock; 31333bbe223SAxel Dörfler 31433bbe223SAxel Dörfler Screen* fActiveScreen; 3153ddebe7eSMichael Lotz 3163ddebe7eSMichael Lotz CursorManager fCursorManager; 317e83820edSAxel Dörfler 318e83820edSAxel Dörfler #if USE_MULTI_LOCKER 319e83820edSAxel Dörfler MultiLocker fWindowLock; 320e83820edSAxel Dörfler #else 321e83820edSAxel Dörfler BLocker fWindowLock; 322e83820edSAxel Dörfler #endif 323e83820edSAxel Dörfler 324e83820edSAxel Dörfler BRegion fBackgroundRegion; 325e83820edSAxel Dörfler BRegion fScreenRegion; 326e83820edSAxel Dörfler 327953d895eSAxel Dörfler Window* fMouseEventWindow; 328953d895eSAxel Dörfler const Window* fWindowUnderMouse; 32921b40eddSStephan Aßmus const Window* fLockedFocusWindow; 3301e766d46SAxel Dörfler int32 fViewUnderMouse; 3314d1c4228SStephan Aßmus BPoint fLastMousePosition; 3324d1c4228SStephan Aßmus int32 fLastMouseButtons; 3331e766d46SAxel Dörfler 334953d895eSAxel Dörfler Window* fFocus; 335953d895eSAxel Dörfler Window* fFront; 336953d895eSAxel Dörfler Window* fBack; 33733bbe223SAxel Dörfler }; 33833bbe223SAxel Dörfler 33927adb969SAxel Dörfler #endif // DESKTOP_H 340