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 42*89887831SClemens Zeidler class DecorAddOn; 4358468dfeSStephan Aßmus class DrawingEngine; 443dcb3b07SStephan Aßmus class HWInterface; 45e83820edSAxel Dörfler class ServerApp; 46953d895eSAxel Dörfler class Window; 47953d895eSAxel Dörfler class WorkspacesView; 486d5488e1SAxel Dörfler struct server_read_only_memory; 4933bbe223SAxel Dörfler 506a0a0a80SAxel Dörfler namespace BPrivate { 516a0a0a80SAxel Dörfler class LinkSender; 526a0a0a80SAxel Dörfler }; 536a0a0a80SAxel Dörfler 540eed9183SAxel Dörfler 55860dfc9aSClemens Zeidler class Desktop : public DesktopObservable, public MessageLooper, 56860dfc9aSClemens Zeidler public ScreenOwner { 5733bbe223SAxel Dörfler public: 5868667bf4SMichael Lotz Desktop(uid_t userID, const char* targetScreen); 593dcb3b07SStephan Aßmus virtual ~Desktop(); 603dcb3b07SStephan Aßmus 61d6734c08SClemens Zeidler void RegisterListener(DesktopListener* listener); 62d6734c08SClemens Zeidler 636d5488e1SAxel Dörfler status_t Init(); 6436deda69SAxel Dörfler 6536deda69SAxel Dörfler uid_t UserID() const { return fUserID; } 6668667bf4SMichael Lotz const char* TargetScreen() { return fTargetScreen; } 67770c05d6SAxel Dörfler virtual port_id MessagePort() const { return fMessagePort; } 689dbce7a4SAxel Dörfler area_id SharedReadOnlyArea() const 699dbce7a4SAxel Dörfler { return fSharedReadOnlyArea; } 70770c05d6SAxel Dörfler 71f7598223SAxel Dörfler ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 726c17d025SAxel Dörfler 73770c05d6SAxel Dörfler void BroadcastToAllApps(int32 code); 740a3f410fSAxel Dörfler void BroadcastToAllWindows(int32 code); 7533bbe223SAxel Dörfler 7683cdf43fSClemens Zeidler filter_result KeyEvent(uint32 what, int32 key, 77860dfc9aSClemens Zeidler int32 modifiers); 78cc93fbbbSAxel Dörfler // Locking 79cc93fbbbSAxel Dörfler bool LockSingleWindow() 80cc93fbbbSAxel Dörfler { return fWindowLock.ReadLock(); } 81cc93fbbbSAxel Dörfler void UnlockSingleWindow() 82cc93fbbbSAxel Dörfler { fWindowLock.ReadUnlock(); } 83cc93fbbbSAxel Dörfler 84cc93fbbbSAxel Dörfler bool LockAllWindows() 85cc93fbbbSAxel Dörfler { return fWindowLock.WriteLock(); } 86cc93fbbbSAxel Dörfler void UnlockAllWindows() 87cc93fbbbSAxel Dörfler { fWindowLock.WriteUnlock(); } 88cc93fbbbSAxel Dörfler 8978ca6157SAxel Dörfler const MultiLocker& WindowLocker() { return fWindowLock; } 90cc93fbbbSAxel Dörfler 910eed9183SAxel Dörfler // Mouse and cursor methods 9233bbe223SAxel Dörfler 93195e980eSAxel Dörfler void SetCursor(ServerCursor* cursor); 94ace2d5eeSStephan Aßmus ServerCursorReference Cursor() const; 958689fe06SIngo Weinhold void SetManagementCursor(ServerCursor* newCursor); 968689fe06SIngo Weinhold 974d1c4228SStephan Aßmus void SetLastMouseState(const BPoint& position, 9821b40eddSStephan Aßmus int32 buttons, Window* windowUnderMouse); 994d1c4228SStephan Aßmus // for use by the mouse filter only 1004d1c4228SStephan Aßmus // both mouse position calls require 1014d1c4228SStephan Aßmus // the Desktop object to be locked 1024d1c4228SStephan Aßmus // already 1034d1c4228SStephan Aßmus void GetLastMouseState(BPoint* position, 1044d1c4228SStephan Aßmus int32* buttons) const; 1054d1c4228SStephan Aßmus // for use by ServerWindow 1060eed9183SAxel Dörfler 1070eed9183SAxel Dörfler CursorManager& GetCursorManager() { return fCursorManager; } 1080eed9183SAxel Dörfler 109fe7f167dSAxel Dörfler // Screen and drawing related methods 110fe7f167dSAxel Dörfler 1110eed9183SAxel Dörfler status_t SetScreenMode(int32 workspace, int32 id, 1120eed9183SAxel Dörfler const display_mode& mode, bool makeDefault); 1130eed9183SAxel Dörfler status_t GetScreenMode(int32 workspace, int32 id, 1140eed9183SAxel Dörfler display_mode& mode); 115e18224cdSAxel Dörfler status_t GetScreenFrame(int32 workspace, int32 id, 116e18224cdSAxel Dörfler BRect& frame); 1175e3f4c41SAxel Dörfler void RevertScreenModes(uint32 workspaces); 1180eed9183SAxel Dörfler 11978ca6157SAxel Dörfler MultiLocker& ScreenLocker() { return fScreenLock; } 12078ca6157SAxel Dörfler 1219fe35223SAxel Dörfler status_t LockDirectScreen(team_id team); 1229fe35223SAxel Dörfler status_t UnlockDirectScreen(team_id team); 1239fe35223SAxel Dörfler 1245e3f4c41SAxel Dörfler const ::VirtualScreen& VirtualScreen() const 1255e3f4c41SAxel Dörfler { return fVirtualScreen; } 12627adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 12758468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 12827adb969SAxel Dörfler ::HWInterface* HWInterface() const 129fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 13094fa2bd2SAdi Oanca 1315483fa4eSClemens Zeidler void RebuildAndRedrawAfterWindowChange( 1325483fa4eSClemens Zeidler Window* window, BRegion& dirty); 1335483fa4eSClemens Zeidler // the window lock must be held when calling 1345483fa4eSClemens Zeidler // this function 1355483fa4eSClemens Zeidler 1360eed9183SAxel Dörfler // ScreenOwner implementation 1375e3f4c41SAxel Dörfler virtual void ScreenRemoved(Screen* screen) {} 1385e3f4c41SAxel Dörfler virtual void ScreenAdded(Screen* screen) {} 1395e3f4c41SAxel Dörfler virtual bool ReleaseScreen(Screen* screen) { return false; } 1400eed9183SAxel Dörfler 14127adb969SAxel Dörfler // Workspace methods 14227adb969SAxel Dörfler 14347212dddSAxel Dörfler void SetWorkspaceAsync(int32 index, 14447212dddSAxel Dörfler bool moveFocusWindow = false); 14547212dddSAxel Dörfler void SetWorkspace(int32 index, 14647212dddSAxel Dörfler bool moveFocusWindow = false); 14727adb969SAxel Dörfler int32 CurrentWorkspace() 14827adb969SAxel Dörfler { return fCurrentWorkspace; } 1495ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 15027adb969SAxel Dörfler { return fWorkspaces[index]; } 15169f9a367SAxel Dörfler status_t SetWorkspacesLayout(int32 columns, int32 rows); 15227c43a2dSRene Gollent BRect WorkspaceFrame(int32 index) const; 15327adb969SAxel Dörfler 154cc93fbbbSAxel Dörfler void StoreWorkspaceConfiguration(int32 index); 155cc93fbbbSAxel Dörfler 156cc93fbbbSAxel Dörfler void AddWorkspacesView(WorkspacesView* view); 157cc93fbbbSAxel Dörfler void RemoveWorkspacesView(WorkspacesView* view); 158cc93fbbbSAxel Dörfler 159953d895eSAxel Dörfler // Window methods 16027adb969SAxel Dörfler 161926e63c8SBrecht Machiels void SelectWindow(Window* window); 162953d895eSAxel Dörfler void ActivateWindow(Window* window); 163953d895eSAxel Dörfler void SendWindowBehind(Window* window, 164953d895eSAxel Dörfler Window* behindOf = NULL); 16527adb969SAxel Dörfler 166953d895eSAxel Dörfler void ShowWindow(Window* window); 167953d895eSAxel Dörfler void HideWindow(Window* window); 168860dfc9aSClemens Zeidler void MinimizeWindow(Window* window, bool minimize); 16915918e4fSAxel Dörfler 170953d895eSAxel Dörfler void MoveWindowBy(Window* window, float x, float y, 17114fe11cfSAxel Dörfler int32 workspace = -1); 1729dbce7a4SAxel Dörfler void ResizeWindowBy(Window* window, float x, 1739dbce7a4SAxel Dörfler float y); 1749dbce7a4SAxel Dörfler bool SetWindowTabLocation(Window* window, 175bb2e9b06SClemens Zeidler float location, bool isShifting); 176953d895eSAxel Dörfler bool SetWindowDecoratorSettings(Window* window, 177b30e9021SStephan Aßmus const BMessage& settings); 17819d801a6SAxel Dörfler 179953d895eSAxel Dörfler void SetWindowWorkspaces(Window* window, 180a631158aSAxel Dörfler uint32 workspaces); 18127adb969SAxel Dörfler 182953d895eSAxel Dörfler void AddWindow(Window* window); 183953d895eSAxel Dörfler void RemoveWindow(Window* window); 18457be2866SAxel Dörfler 185953d895eSAxel Dörfler bool AddWindowToSubset(Window* subset, 186953d895eSAxel Dörfler Window* window); 187953d895eSAxel Dörfler void RemoveWindowFromSubset(Window* subset, 188953d895eSAxel Dörfler Window* window); 18934227d2cSAxel Dörfler 1900a3f410fSAxel Dörfler void FontsChanged(Window* window); 1910a3f410fSAxel Dörfler 192953d895eSAxel Dörfler void SetWindowLook(Window* window, window_look look); 193953d895eSAxel Dörfler void SetWindowFeel(Window* window, window_feel feel); 194953d895eSAxel Dörfler void SetWindowFlags(Window* window, uint32 flags); 1959dbce7a4SAxel Dörfler void SetWindowTitle(Window* window, 1969dbce7a4SAxel Dörfler const char* title); 19733bbe223SAxel Dörfler 198953d895eSAxel Dörfler Window* FocusWindow() const { return fFocus; } 199953d895eSAxel Dörfler Window* FrontWindow() const { return fFront; } 200953d895eSAxel Dörfler Window* BackWindow() const { return fBack; } 201e83820edSAxel Dörfler 202953d895eSAxel Dörfler Window* WindowAt(BPoint where); 203e83820edSAxel Dörfler 2049dbce7a4SAxel Dörfler Window* MouseEventWindow() const 2059dbce7a4SAxel Dörfler { return fMouseEventWindow; } 206953d895eSAxel Dörfler void SetMouseEventWindow(Window* window); 207e83820edSAxel Dörfler 2089dbce7a4SAxel Dörfler void SetViewUnderMouse(const Window* window, 2099dbce7a4SAxel Dörfler int32 viewToken); 210953d895eSAxel Dörfler int32 ViewUnderMouse(const Window* window); 2111e766d46SAxel Dörfler 21207dc2c69SAxel Dörfler EventTarget* KeyboardEventTarget(); 213cc93fbbbSAxel Dörfler 214cc93fbbbSAxel Dörfler void SetFocusWindow(Window* window = NULL); 21521b40eddSStephan Aßmus void SetFocusLocked(const Window* window); 216e83820edSAxel Dörfler 217953d895eSAxel Dörfler Window* FindWindowByClientToken(int32 token, 218953d895eSAxel Dörfler team_id teamID); 21995530739SAxel Dörfler EventTarget* FindTarget(BMessenger& messenger); 2206a0a0a80SAxel Dörfler 221e83820edSAxel Dörfler void MarkDirty(BRegion& region); 222b09e2f6fSStephan Aßmus void Redraw(); 223cc93fbbbSAxel Dörfler void RedrawBackground(); 224e83820edSAxel Dörfler 225*89887831SClemens Zeidler bool ReloadDecor(DecorAddOn* oldDecor); 226bb86786aSClemens Zeidler 227e83820edSAxel Dörfler BRegion& BackgroundRegion() 228e83820edSAxel Dörfler { return fBackgroundRegion; } 22933bbe223SAxel Dörfler 230f877af82SAxel Dörfler void MinimizeApplication(team_id team); 231f877af82SAxel Dörfler void BringApplicationToFront(team_id team); 232bfe69873SAxel Dörfler void WindowAction(int32 windowToken, int32 action); 233f877af82SAxel Dörfler 23427adb969SAxel Dörfler void WriteWindowList(team_id team, 23527adb969SAxel Dörfler BPrivate::LinkSender& sender); 23627adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 23727adb969SAxel Dörfler BPrivate::LinkSender& sender); 238ae0606beSAxel Dörfler void WriteApplicationOrder(int32 workspace, 239ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 240ae0606beSAxel Dörfler void WriteWindowOrder(int32 workspace, 241ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 24233bbe223SAxel Dörfler 24352ede95cSStephan Aßmus //! The window lock must be held when accessing a window list! 244860dfc9aSClemens Zeidler WindowList& CurrentWindows(); 245d6734c08SClemens Zeidler WindowList& AllWindows(); 246860dfc9aSClemens Zeidler 247b8a44a25SClemens Zeidler Window* WindowForClientLooperPort(port_id port); 248b8a44a25SClemens Zeidler 24933bbe223SAxel Dörfler private: 2500265102fSClemens Zeidler WindowList& _Windows(int32 index); 2510265102fSClemens Zeidler 2526869c8a5SRyan Leavengood void _LaunchInputServer(); 253cc93fbbbSAxel Dörfler void _GetLooperName(char* name, size_t size); 254cc93fbbbSAxel Dörfler void _PrepareQuit(); 255cc93fbbbSAxel Dörfler void _DispatchMessage(int32 code, 256cc93fbbbSAxel Dörfler BPrivate::LinkReceiver &link); 257e83820edSAxel Dörfler 25834227d2cSAxel Dörfler void _UpdateFloating(int32 previousWorkspace = -1, 259d479fa7aSAxel Dörfler int32 nextWorkspace = -1, 260953d895eSAxel Dörfler Window* mouseEventWindow = NULL); 261e83820edSAxel Dörfler void _UpdateBack(); 26234227d2cSAxel Dörfler void _UpdateFront(bool updateFloating = true); 26334227d2cSAxel Dörfler void _UpdateFronts(bool updateFloating = true); 264953d895eSAxel Dörfler bool _WindowHasModal(Window* window); 265e83820edSAxel Dörfler 266953d895eSAxel Dörfler void _WindowChanged(Window* window); 267953d895eSAxel Dörfler void _WindowRemoved(Window* window); 268ce8c4d79SAxel Dörfler 269cc93fbbbSAxel Dörfler void _ShowWindow(Window* window, 270cc93fbbbSAxel Dörfler bool affectsOtherWindows = true); 271cc93fbbbSAxel Dörfler void _HideWindow(Window* window); 2725f2edc0fSAxel Dörfler 273cc93fbbbSAxel Dörfler void _UpdateSubsetWorkspaces(Window* window, 274cc93fbbbSAxel Dörfler int32 previousIndex = -1, 275cc93fbbbSAxel Dörfler int32 newIndex = -1); 276cc93fbbbSAxel Dörfler void _ChangeWindowWorkspaces(Window* window, 277cc93fbbbSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 278cc93fbbbSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 279cc93fbbbSAxel Dörfler int32 list, bool wereVisible); 280cc93fbbbSAxel Dörfler Window* _LastFocusSubsetWindow(Window* window); 281cc93fbbbSAxel Dörfler void _SendFakeMouseMoved(Window* window = NULL); 282cc93fbbbSAxel Dörfler 28378ca6157SAxel Dörfler Screen* _DetermineScreenFor(BRect frame); 284cc93fbbbSAxel Dörfler void _RebuildClippingForAllWindows( 285cc93fbbbSAxel Dörfler BRegion& stillAvailableOnScreen); 286cc93fbbbSAxel Dörfler void _TriggerWindowRedrawing( 287cc93fbbbSAxel Dörfler BRegion& newDirtyRegion); 288cc93fbbbSAxel Dörfler void _SetBackground(BRegion& background); 289cc93fbbbSAxel Dörfler 290cc93fbbbSAxel Dörfler status_t _ActivateApp(team_id team); 291cc93fbbbSAxel Dörfler 29278ca6157SAxel Dörfler void _SuspendDirectFrameBufferAccess(); 29378ca6157SAxel Dörfler void _ResumeDirectFrameBufferAccess(); 29478ca6157SAxel Dörfler 295cc93fbbbSAxel Dörfler void _ScreenChanged(Screen* screen); 296cc93fbbbSAxel Dörfler void _SetCurrentWorkspaceConfiguration(); 29747212dddSAxel Dörfler void _SetWorkspace(int32 index, 29847212dddSAxel Dörfler bool moveFocusWindow = false); 299e83820edSAxel Dörfler 3005f2edc0fSAxel Dörfler private: 301ef8810f2SAxel Dörfler friend class DesktopSettings; 302a17c3a48SAxel Dörfler friend class LockedDesktopSettings; 303ef8810f2SAxel Dörfler 30436deda69SAxel Dörfler uid_t fUserID; 305d65593aaSMichael Lotz char* fTargetScreen; 306fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 307a17c3a48SAxel Dörfler DesktopSettingsPrivate* fSettings; 3085f2edc0fSAxel Dörfler port_id fMessagePort; 309f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 3106d5488e1SAxel Dörfler area_id fSharedReadOnlyArea; 3116d5488e1SAxel Dörfler server_read_only_memory* fServerReadOnlyMemory; 312770c05d6SAxel Dörfler 313e83820edSAxel Dörfler BLocker fApplicationsLock; 314e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 315770c05d6SAxel Dörfler 316770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 317770c05d6SAxel Dörfler int32 fShutdownCount; 318770c05d6SAxel Dörfler 31982081c70SJérôme Duval ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 32078ca6157SAxel Dörfler MultiLocker fScreenLock; 3219fe35223SAxel Dörfler BLocker fDirectScreenLock; 3229fe35223SAxel Dörfler team_id fDirectScreenTeam; 32327adb969SAxel Dörfler int32 fCurrentWorkspace; 3244932bc5eSAxel Dörfler int32 fPreviousWorkspace; 32527adb969SAxel Dörfler 326e83820edSAxel Dörfler WindowList fAllWindows; 32734227d2cSAxel Dörfler WindowList fSubsetWindows; 328d01879e5SAxel Dörfler WindowList fFocusList; 3290b63cc93SAxel Dörfler Window* fLastWorkspaceFocus[kMaxWorkspaces]; 330d8ebe612SAxel Dörfler 331953d895eSAxel Dörfler BObjectList<WorkspacesView> fWorkspacesViews; 332d8ebe612SAxel Dörfler BLocker fWorkspacesLock; 33333bbe223SAxel Dörfler 3343ddebe7eSMichael Lotz CursorManager fCursorManager; 3358689fe06SIngo Weinhold ServerCursorReference fCursor; 3368689fe06SIngo Weinhold ServerCursorReference fManagementCursor; 337e83820edSAxel Dörfler 338e83820edSAxel Dörfler MultiLocker fWindowLock; 339e83820edSAxel Dörfler 340e83820edSAxel Dörfler BRegion fBackgroundRegion; 341e83820edSAxel Dörfler BRegion fScreenRegion; 342e83820edSAxel Dörfler 343953d895eSAxel Dörfler Window* fMouseEventWindow; 344953d895eSAxel Dörfler const Window* fWindowUnderMouse; 34521b40eddSStephan Aßmus const Window* fLockedFocusWindow; 3461e766d46SAxel Dörfler int32 fViewUnderMouse; 3474d1c4228SStephan Aßmus BPoint fLastMousePosition; 3484d1c4228SStephan Aßmus int32 fLastMouseButtons; 3491e766d46SAxel Dörfler 350953d895eSAxel Dörfler Window* fFocus; 351953d895eSAxel Dörfler Window* fFront; 352953d895eSAxel Dörfler Window* fBack; 35333bbe223SAxel Dörfler }; 35433bbe223SAxel Dörfler 35527adb969SAxel Dörfler #endif // DESKTOP_H 356