16a0a0a80SAxel Dörfler /* 2bb86786aSClemens Zeidler * Copyright 2001-2010, 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> 8926e63c8SBrecht Machiels * Axel Dörfler <axeld@pinc-software.de> 9b09e2f6fSStephan Aßmus * Andrej Spielmann, <andrej.spielmann@seh.ox.ac.uk> 10926e63c8SBrecht Machiels * Brecht Machiels <brecht@mos6581.org> 11bb86786aSClemens Zeidler * Clemens Zeidler <haiku@clemens-zeidler.de> 126a0a0a80SAxel Dörfler */ 1327adb969SAxel Dörfler #ifndef DESKTOP_H 1427adb969SAxel Dörfler #define DESKTOP_H 1533bbe223SAxel Dörfler 1608f35604SAxel Dörfler 17b6ba2290SClemens Zeidler #include <Autolock.h> 18b6ba2290SClemens Zeidler #include <InterfaceDefs.h> 19b6ba2290SClemens Zeidler #include <List.h> 20b6ba2290SClemens Zeidler #include <Menu.h> 21b6ba2290SClemens Zeidler #include <ObjectList.h> 22b6ba2290SClemens Zeidler #include <Region.h> 23b6ba2290SClemens Zeidler #include <Window.h> 24b6ba2290SClemens Zeidler 253ddebe7eSMichael Lotz #include "CursorManager.h" 26860dfc9aSClemens Zeidler #include "DesktopListener.h" 27ace2d5eeSStephan Aßmus #include "DesktopSettings.h" 2808f35604SAxel Dörfler #include "EventDispatcher.h" 29ace2d5eeSStephan Aßmus #include "MessageLooper.h" 3052ede95cSStephan Aßmus #include "MultiLocker.h" 31953d895eSAxel Dörfler #include "Screen.h" 32fd5bec1eSAxel Dörfler #include "ScreenManager.h" 33ace2d5eeSStephan Aßmus #include "ServerCursor.h" 34fd5bec1eSAxel Dörfler #include "VirtualScreen.h" 35e83820edSAxel Dörfler #include "WindowList.h" 3627adb969SAxel Dörfler #include "Workspace.h" 375ca8477eSAxel Dörfler #include "WorkspacePrivate.h" 38fd5bec1eSAxel Dörfler 3923e00a25SAxel Dörfler 403dcb3b07SStephan Aßmus class BMessage; 416a0a0a80SAxel Dörfler 4258468dfeSStephan Aßmus class DrawingEngine; 433dcb3b07SStephan Aßmus class HWInterface; 44e83820edSAxel Dörfler class ServerApp; 45953d895eSAxel Dörfler class Window; 46953d895eSAxel Dörfler class WorkspacesView; 476d5488e1SAxel Dörfler struct server_read_only_memory; 4833bbe223SAxel Dörfler 496a0a0a80SAxel Dörfler namespace BPrivate { 506a0a0a80SAxel Dörfler class LinkSender; 516a0a0a80SAxel Dörfler }; 526a0a0a80SAxel Dörfler 530eed9183SAxel Dörfler 54860dfc9aSClemens Zeidler class Desktop : public DesktopObservable, public MessageLooper, 55860dfc9aSClemens Zeidler public ScreenOwner { 5633bbe223SAxel Dörfler public: 5768667bf4SMichael Lotz Desktop(uid_t userID, const char* targetScreen); 583dcb3b07SStephan Aßmus virtual ~Desktop(); 593dcb3b07SStephan Aßmus 60d6734c08SClemens Zeidler void RegisterListener(DesktopListener* listener); 61d6734c08SClemens Zeidler 626d5488e1SAxel Dörfler status_t Init(); 6336deda69SAxel Dörfler 6436deda69SAxel Dörfler uid_t UserID() const { return fUserID; } 6568667bf4SMichael Lotz const char* TargetScreen() { return fTargetScreen; } 66770c05d6SAxel Dörfler virtual port_id MessagePort() const { return fMessagePort; } 679dbce7a4SAxel Dörfler area_id SharedReadOnlyArea() const 689dbce7a4SAxel Dörfler { return fSharedReadOnlyArea; } 69770c05d6SAxel Dörfler 70f7598223SAxel Dörfler ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 716c17d025SAxel Dörfler 72770c05d6SAxel Dörfler void BroadcastToAllApps(int32 code); 730a3f410fSAxel Dörfler void BroadcastToAllWindows(int32 code); 7433bbe223SAxel Dörfler 7583cdf43fSClemens Zeidler filter_result KeyEvent(uint32 what, int32 key, 76860dfc9aSClemens Zeidler int32 modifiers); 77cc93fbbbSAxel Dörfler // Locking 78cc93fbbbSAxel Dörfler bool LockSingleWindow() 79cc93fbbbSAxel Dörfler { return fWindowLock.ReadLock(); } 80cc93fbbbSAxel Dörfler void UnlockSingleWindow() 81cc93fbbbSAxel Dörfler { fWindowLock.ReadUnlock(); } 82cc93fbbbSAxel Dörfler 83cc93fbbbSAxel Dörfler bool LockAllWindows() 84cc93fbbbSAxel Dörfler { return fWindowLock.WriteLock(); } 85cc93fbbbSAxel Dörfler void UnlockAllWindows() 86cc93fbbbSAxel Dörfler { fWindowLock.WriteUnlock(); } 87cc93fbbbSAxel Dörfler 8878ca6157SAxel Dörfler const MultiLocker& WindowLocker() { return fWindowLock; } 89cc93fbbbSAxel Dörfler 900eed9183SAxel Dörfler // Mouse and cursor methods 9133bbe223SAxel Dörfler 92195e980eSAxel Dörfler void SetCursor(ServerCursor* cursor); 93ace2d5eeSStephan Aßmus ServerCursorReference Cursor() const; 948689fe06SIngo Weinhold void SetManagementCursor(ServerCursor* newCursor); 958689fe06SIngo Weinhold 964d1c4228SStephan Aßmus void SetLastMouseState(const BPoint& position, 9721b40eddSStephan Aßmus int32 buttons, Window* windowUnderMouse); 984d1c4228SStephan Aßmus // for use by the mouse filter only 994d1c4228SStephan Aßmus // both mouse position calls require 1004d1c4228SStephan Aßmus // the Desktop object to be locked 1014d1c4228SStephan Aßmus // already 1024d1c4228SStephan Aßmus void GetLastMouseState(BPoint* position, 1034d1c4228SStephan Aßmus int32* buttons) const; 1044d1c4228SStephan Aßmus // for use by ServerWindow 1050eed9183SAxel Dörfler 1060eed9183SAxel Dörfler CursorManager& GetCursorManager() { return fCursorManager; } 1070eed9183SAxel Dörfler 108fe7f167dSAxel Dörfler // Screen and drawing related methods 109fe7f167dSAxel Dörfler 1100eed9183SAxel Dörfler status_t SetScreenMode(int32 workspace, int32 id, 1110eed9183SAxel Dörfler const display_mode& mode, bool makeDefault); 1120eed9183SAxel Dörfler status_t GetScreenMode(int32 workspace, int32 id, 1130eed9183SAxel Dörfler display_mode& mode); 114e18224cdSAxel Dörfler status_t GetScreenFrame(int32 workspace, int32 id, 115e18224cdSAxel Dörfler BRect& frame); 1165e3f4c41SAxel Dörfler void RevertScreenModes(uint32 workspaces); 1170eed9183SAxel Dörfler 11878ca6157SAxel Dörfler MultiLocker& ScreenLocker() { return fScreenLock; } 11978ca6157SAxel Dörfler 1209fe35223SAxel Dörfler status_t LockDirectScreen(team_id team); 1219fe35223SAxel Dörfler status_t UnlockDirectScreen(team_id team); 1229fe35223SAxel Dörfler 1235e3f4c41SAxel Dörfler const ::VirtualScreen& VirtualScreen() const 1245e3f4c41SAxel Dörfler { return fVirtualScreen; } 12527adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 12658468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 12727adb969SAxel Dörfler ::HWInterface* HWInterface() const 128fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 12994fa2bd2SAdi Oanca 1305483fa4eSClemens Zeidler void RebuildAndRedrawAfterWindowChange( 1315483fa4eSClemens Zeidler Window* window, BRegion& dirty); 1325483fa4eSClemens Zeidler // the window lock must be held when calling 1335483fa4eSClemens Zeidler // this function 1345483fa4eSClemens Zeidler 1350eed9183SAxel Dörfler // ScreenOwner implementation 1365e3f4c41SAxel Dörfler virtual void ScreenRemoved(Screen* screen) {} 1375e3f4c41SAxel Dörfler virtual void ScreenAdded(Screen* screen) {} 1385e3f4c41SAxel Dörfler virtual bool ReleaseScreen(Screen* screen) { return false; } 1390eed9183SAxel Dörfler 14027adb969SAxel Dörfler // Workspace methods 14127adb969SAxel Dörfler 14247212dddSAxel Dörfler void SetWorkspaceAsync(int32 index, 14347212dddSAxel Dörfler bool moveFocusWindow = false); 14447212dddSAxel Dörfler void SetWorkspace(int32 index, 14547212dddSAxel Dörfler bool moveFocusWindow = false); 14627adb969SAxel Dörfler int32 CurrentWorkspace() 14727adb969SAxel Dörfler { return fCurrentWorkspace; } 1485ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 14927adb969SAxel Dörfler { return fWorkspaces[index]; } 15069f9a367SAxel Dörfler status_t SetWorkspacesLayout(int32 columns, int32 rows); 15127c43a2dSRene Gollent BRect WorkspaceFrame(int32 index) const; 15227adb969SAxel Dörfler 153cc93fbbbSAxel Dörfler void StoreWorkspaceConfiguration(int32 index); 154cc93fbbbSAxel Dörfler 155cc93fbbbSAxel Dörfler void AddWorkspacesView(WorkspacesView* view); 156cc93fbbbSAxel Dörfler void RemoveWorkspacesView(WorkspacesView* view); 157cc93fbbbSAxel Dörfler 158953d895eSAxel Dörfler // Window methods 15927adb969SAxel Dörfler 160926e63c8SBrecht Machiels void SelectWindow(Window* window); 161953d895eSAxel Dörfler void ActivateWindow(Window* window); 162953d895eSAxel Dörfler void SendWindowBehind(Window* window, 163953d895eSAxel Dörfler Window* behindOf = NULL); 16427adb969SAxel Dörfler 165953d895eSAxel Dörfler void ShowWindow(Window* window); 166953d895eSAxel Dörfler void HideWindow(Window* window); 167860dfc9aSClemens Zeidler void MinimizeWindow(Window* window, bool minimize); 16815918e4fSAxel Dörfler 169953d895eSAxel Dörfler void MoveWindowBy(Window* window, float x, float y, 17014fe11cfSAxel Dörfler int32 workspace = -1); 1719dbce7a4SAxel Dörfler void ResizeWindowBy(Window* window, float x, 1729dbce7a4SAxel Dörfler float y); 1739dbce7a4SAxel Dörfler bool SetWindowTabLocation(Window* window, 1749dbce7a4SAxel Dörfler float location); 175953d895eSAxel Dörfler bool SetWindowDecoratorSettings(Window* window, 176b30e9021SStephan Aßmus const BMessage& settings); 17719d801a6SAxel Dörfler 178953d895eSAxel Dörfler void SetWindowWorkspaces(Window* window, 179a631158aSAxel Dörfler uint32 workspaces); 18027adb969SAxel Dörfler 181953d895eSAxel Dörfler void AddWindow(Window* window); 182953d895eSAxel Dörfler void RemoveWindow(Window* window); 18357be2866SAxel Dörfler 184953d895eSAxel Dörfler bool AddWindowToSubset(Window* subset, 185953d895eSAxel Dörfler Window* window); 186953d895eSAxel Dörfler void RemoveWindowFromSubset(Window* subset, 187953d895eSAxel Dörfler Window* window); 18834227d2cSAxel Dörfler 1890a3f410fSAxel Dörfler void FontsChanged(Window* window); 1900a3f410fSAxel Dörfler 191953d895eSAxel Dörfler void SetWindowLook(Window* window, window_look look); 192953d895eSAxel Dörfler void SetWindowFeel(Window* window, window_feel feel); 193953d895eSAxel Dörfler void SetWindowFlags(Window* window, uint32 flags); 1949dbce7a4SAxel Dörfler void SetWindowTitle(Window* window, 1959dbce7a4SAxel Dörfler const char* title); 19633bbe223SAxel Dörfler 197953d895eSAxel Dörfler Window* FocusWindow() const { return fFocus; } 198953d895eSAxel Dörfler Window* FrontWindow() const { return fFront; } 199953d895eSAxel Dörfler Window* BackWindow() const { return fBack; } 200e83820edSAxel Dörfler 201953d895eSAxel Dörfler Window* WindowAt(BPoint where); 202e83820edSAxel Dörfler 2039dbce7a4SAxel Dörfler Window* MouseEventWindow() const 2049dbce7a4SAxel Dörfler { return fMouseEventWindow; } 205953d895eSAxel Dörfler void SetMouseEventWindow(Window* window); 206e83820edSAxel Dörfler 2079dbce7a4SAxel Dörfler void SetViewUnderMouse(const Window* window, 2089dbce7a4SAxel Dörfler int32 viewToken); 209953d895eSAxel Dörfler int32 ViewUnderMouse(const Window* window); 2101e766d46SAxel Dörfler 21107dc2c69SAxel Dörfler EventTarget* KeyboardEventTarget(); 212cc93fbbbSAxel Dörfler 213cc93fbbbSAxel Dörfler void SetFocusWindow(Window* window = NULL); 21421b40eddSStephan Aßmus void SetFocusLocked(const Window* window); 215e83820edSAxel Dörfler 216953d895eSAxel Dörfler Window* FindWindowByClientToken(int32 token, 217953d895eSAxel Dörfler team_id teamID); 21895530739SAxel Dörfler EventTarget* FindTarget(BMessenger& messenger); 2196a0a0a80SAxel Dörfler 220e83820edSAxel Dörfler void MarkDirty(BRegion& region); 221b09e2f6fSStephan Aßmus void Redraw(); 222cc93fbbbSAxel Dörfler void RedrawBackground(); 223e83820edSAxel Dörfler 224b6ba2290SClemens Zeidler void ReloadDecor(); 225bb86786aSClemens Zeidler 226e83820edSAxel Dörfler BRegion& BackgroundRegion() 227e83820edSAxel Dörfler { return fBackgroundRegion; } 22833bbe223SAxel Dörfler 229f877af82SAxel Dörfler void MinimizeApplication(team_id team); 230f877af82SAxel Dörfler void BringApplicationToFront(team_id team); 231bfe69873SAxel Dörfler void WindowAction(int32 windowToken, int32 action); 232f877af82SAxel Dörfler 23327adb969SAxel Dörfler void WriteWindowList(team_id team, 23427adb969SAxel Dörfler BPrivate::LinkSender& sender); 23527adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 23627adb969SAxel Dörfler BPrivate::LinkSender& sender); 237ae0606beSAxel Dörfler void WriteApplicationOrder(int32 workspace, 238ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 239ae0606beSAxel Dörfler void WriteWindowOrder(int32 workspace, 240ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 24133bbe223SAxel Dörfler 24252ede95cSStephan Aßmus //! The window lock must be held when accessing a window list! 243860dfc9aSClemens Zeidler WindowList& CurrentWindows(); 244d6734c08SClemens Zeidler WindowList& AllWindows(); 245860dfc9aSClemens Zeidler 246b8a44a25SClemens Zeidler Window* WindowForClientLooperPort(port_id port); 247b8a44a25SClemens Zeidler 24833bbe223SAxel Dörfler private: 2490265102fSClemens Zeidler WindowList& _Windows(int32 index); 2500265102fSClemens Zeidler 2516869c8a5SRyan Leavengood void _LaunchInputServer(); 252cc93fbbbSAxel Dörfler void _GetLooperName(char* name, size_t size); 253cc93fbbbSAxel Dörfler void _PrepareQuit(); 254cc93fbbbSAxel Dörfler void _DispatchMessage(int32 code, 255cc93fbbbSAxel Dörfler BPrivate::LinkReceiver &link); 256e83820edSAxel Dörfler 25734227d2cSAxel Dörfler void _UpdateFloating(int32 previousWorkspace = -1, 258d479fa7aSAxel Dörfler int32 nextWorkspace = -1, 259953d895eSAxel Dörfler Window* mouseEventWindow = NULL); 260e83820edSAxel Dörfler void _UpdateBack(); 26134227d2cSAxel Dörfler void _UpdateFront(bool updateFloating = true); 26234227d2cSAxel Dörfler void _UpdateFronts(bool updateFloating = true); 263953d895eSAxel Dörfler bool _WindowHasModal(Window* window); 264e83820edSAxel Dörfler 265953d895eSAxel Dörfler void _WindowChanged(Window* window); 266953d895eSAxel Dörfler void _WindowRemoved(Window* window); 267ce8c4d79SAxel Dörfler 268cc93fbbbSAxel Dörfler void _ShowWindow(Window* window, 269cc93fbbbSAxel Dörfler bool affectsOtherWindows = true); 270cc93fbbbSAxel Dörfler void _HideWindow(Window* window); 2715f2edc0fSAxel Dörfler 272cc93fbbbSAxel Dörfler void _UpdateSubsetWorkspaces(Window* window, 273cc93fbbbSAxel Dörfler int32 previousIndex = -1, 274cc93fbbbSAxel Dörfler int32 newIndex = -1); 275cc93fbbbSAxel Dörfler void _ChangeWindowWorkspaces(Window* window, 276cc93fbbbSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 277cc93fbbbSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 278cc93fbbbSAxel Dörfler int32 list, bool wereVisible); 279cc93fbbbSAxel Dörfler Window* _LastFocusSubsetWindow(Window* window); 280cc93fbbbSAxel Dörfler void _SendFakeMouseMoved(Window* window = NULL); 281cc93fbbbSAxel Dörfler 28278ca6157SAxel Dörfler Screen* _DetermineScreenFor(BRect frame); 283cc93fbbbSAxel Dörfler void _RebuildClippingForAllWindows( 284cc93fbbbSAxel Dörfler BRegion& stillAvailableOnScreen); 285cc93fbbbSAxel Dörfler void _TriggerWindowRedrawing( 286cc93fbbbSAxel Dörfler BRegion& newDirtyRegion); 287cc93fbbbSAxel Dörfler void _SetBackground(BRegion& background); 288cc93fbbbSAxel Dörfler 289cc93fbbbSAxel Dörfler status_t _ActivateApp(team_id team); 290cc93fbbbSAxel Dörfler 29178ca6157SAxel Dörfler void _SuspendDirectFrameBufferAccess(); 29278ca6157SAxel Dörfler void _ResumeDirectFrameBufferAccess(); 29378ca6157SAxel Dörfler 294cc93fbbbSAxel Dörfler void _ScreenChanged(Screen* screen); 295cc93fbbbSAxel Dörfler void _SetCurrentWorkspaceConfiguration(); 29647212dddSAxel Dörfler void _SetWorkspace(int32 index, 29747212dddSAxel Dörfler bool moveFocusWindow = false); 298e83820edSAxel Dörfler 2995f2edc0fSAxel Dörfler private: 300ef8810f2SAxel Dörfler friend class DesktopSettings; 301a17c3a48SAxel Dörfler friend class LockedDesktopSettings; 302ef8810f2SAxel Dörfler 30336deda69SAxel Dörfler uid_t fUserID; 304*d65593aaSMichael Lotz char* fTargetScreen; 305fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 306a17c3a48SAxel Dörfler DesktopSettingsPrivate* fSettings; 3075f2edc0fSAxel Dörfler port_id fMessagePort; 308f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 3096d5488e1SAxel Dörfler area_id fSharedReadOnlyArea; 3106d5488e1SAxel Dörfler server_read_only_memory* fServerReadOnlyMemory; 311770c05d6SAxel Dörfler 312e83820edSAxel Dörfler BLocker fApplicationsLock; 313e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 314770c05d6SAxel Dörfler 315770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 316770c05d6SAxel Dörfler int32 fShutdownCount; 317770c05d6SAxel Dörfler 31882081c70SJérôme Duval ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 31978ca6157SAxel Dörfler MultiLocker fScreenLock; 3209fe35223SAxel Dörfler BLocker fDirectScreenLock; 3219fe35223SAxel Dörfler team_id fDirectScreenTeam; 32227adb969SAxel Dörfler int32 fCurrentWorkspace; 3234932bc5eSAxel Dörfler int32 fPreviousWorkspace; 32427adb969SAxel Dörfler 325e83820edSAxel Dörfler WindowList fAllWindows; 32634227d2cSAxel Dörfler WindowList fSubsetWindows; 327d01879e5SAxel Dörfler WindowList fFocusList; 3280b63cc93SAxel Dörfler Window* fLastWorkspaceFocus[kMaxWorkspaces]; 329d8ebe612SAxel Dörfler 330953d895eSAxel Dörfler BObjectList<WorkspacesView> fWorkspacesViews; 331d8ebe612SAxel Dörfler BLocker fWorkspacesLock; 33233bbe223SAxel Dörfler 3333ddebe7eSMichael Lotz CursorManager fCursorManager; 3348689fe06SIngo Weinhold ServerCursorReference fCursor; 3358689fe06SIngo Weinhold ServerCursorReference fManagementCursor; 336e83820edSAxel Dörfler 337e83820edSAxel Dörfler MultiLocker fWindowLock; 338e83820edSAxel Dörfler 339e83820edSAxel Dörfler BRegion fBackgroundRegion; 340e83820edSAxel Dörfler BRegion fScreenRegion; 341e83820edSAxel Dörfler 342953d895eSAxel Dörfler Window* fMouseEventWindow; 343953d895eSAxel Dörfler const Window* fWindowUnderMouse; 34421b40eddSStephan Aßmus const Window* fLockedFocusWindow; 3451e766d46SAxel Dörfler int32 fViewUnderMouse; 3464d1c4228SStephan Aßmus BPoint fLastMousePosition; 3474d1c4228SStephan Aßmus int32 fLastMouseButtons; 3481e766d46SAxel Dörfler 349953d895eSAxel Dörfler Window* fFocus; 350953d895eSAxel Dörfler Window* fFront; 351953d895eSAxel Dörfler Window* fBack; 35233bbe223SAxel Dörfler }; 35333bbe223SAxel Dörfler 35427adb969SAxel Dörfler #endif // DESKTOP_H 355