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> 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> 116a0a0a80SAxel Dörfler */ 1227adb969SAxel Dörfler #ifndef DESKTOP_H 1327adb969SAxel Dörfler #define DESKTOP_H 1433bbe223SAxel Dörfler 1508f35604SAxel Dörfler 163ddebe7eSMichael Lotz #include "CursorManager.h" 17ace2d5eeSStephan Aßmus #include "DesktopSettings.h" 1808f35604SAxel Dörfler #include "EventDispatcher.h" 19ace2d5eeSStephan Aßmus #include "MessageLooper.h" 20953d895eSAxel Dörfler #include "Screen.h" 21fd5bec1eSAxel Dörfler #include "ScreenManager.h" 22ace2d5eeSStephan Aßmus #include "ServerCursor.h" 23fd5bec1eSAxel Dörfler #include "VirtualScreen.h" 24e83820edSAxel Dörfler #include "WindowList.h" 2527adb969SAxel Dörfler #include "Workspace.h" 265ca8477eSAxel Dörfler #include "WorkspacePrivate.h" 27fd5bec1eSAxel Dörfler 28e83820edSAxel Dörfler #include <ObjectList.h> 29e83820edSAxel Dörfler 30e83820edSAxel Dörfler #include <Autolock.h> 3133bbe223SAxel Dörfler #include <InterfaceDefs.h> 323dcb3b07SStephan Aßmus #include <List.h> 333dcb3b07SStephan Aßmus #include <Menu.h> 34e83820edSAxel Dörfler #include <Region.h> 3557be2866SAxel Dörfler #include <Window.h> 366a0a0a80SAxel Dörfler 37ef831a1dSPhilippe Houdoin #include "LinearSpec.h" 380eed9183SAxel Dörfler 39*23e00a25SAxel Dörfler 4039c9925fSStephan Aßmus #define USE_MULTI_LOCKER 1 41e83820edSAxel Dörfler 42e83820edSAxel Dörfler #if USE_MULTI_LOCKER 43e83820edSAxel Dörfler # include "MultiLocker.h" 44e83820edSAxel Dörfler #else 45e83820edSAxel Dörfler # include <Locker.h> 46e83820edSAxel Dörfler #endif 4733bbe223SAxel Dörfler 480eed9183SAxel Dörfler 493dcb3b07SStephan Aßmus class BMessage; 506a0a0a80SAxel Dörfler 5158468dfeSStephan Aßmus class DrawingEngine; 523dcb3b07SStephan Aßmus class HWInterface; 53e83820edSAxel Dörfler class ServerApp; 54953d895eSAxel Dörfler class Window; 55953d895eSAxel Dörfler class WorkspacesView; 566d5488e1SAxel Dörfler struct server_read_only_memory; 5733bbe223SAxel Dörfler 586a0a0a80SAxel Dörfler namespace BPrivate { 596a0a0a80SAxel Dörfler class LinkSender; 606a0a0a80SAxel Dörfler }; 616a0a0a80SAxel Dörfler 620eed9183SAxel Dörfler 635f2edc0fSAxel Dörfler class Desktop : public MessageLooper, public ScreenOwner { 6433bbe223SAxel Dörfler public: 6568667bf4SMichael Lotz Desktop(uid_t userID, const char* targetScreen); 663dcb3b07SStephan Aßmus virtual ~Desktop(); 673dcb3b07SStephan Aßmus 686d5488e1SAxel Dörfler status_t Init(); 6936deda69SAxel Dörfler 7036deda69SAxel Dörfler uid_t UserID() const { return fUserID; } 7168667bf4SMichael Lotz const char* TargetScreen() { return fTargetScreen; } 72770c05d6SAxel Dörfler virtual port_id MessagePort() const { return fMessagePort; } 739dbce7a4SAxel Dörfler area_id SharedReadOnlyArea() const 749dbce7a4SAxel Dörfler { return fSharedReadOnlyArea; } 75770c05d6SAxel Dörfler 76f7598223SAxel Dörfler ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 776c17d025SAxel Dörfler 78770c05d6SAxel Dörfler void BroadcastToAllApps(int32 code); 790a3f410fSAxel Dörfler void BroadcastToAllWindows(int32 code); 8033bbe223SAxel Dörfler 81cc93fbbbSAxel Dörfler // Locking 82cc93fbbbSAxel Dörfler #if USE_MULTI_LOCKER 83cc93fbbbSAxel Dörfler bool LockSingleWindow() 84cc93fbbbSAxel Dörfler { return fWindowLock.ReadLock(); } 85cc93fbbbSAxel Dörfler void UnlockSingleWindow() 86cc93fbbbSAxel Dörfler { fWindowLock.ReadUnlock(); } 87cc93fbbbSAxel Dörfler 88cc93fbbbSAxel Dörfler bool LockAllWindows() 89cc93fbbbSAxel Dörfler { return fWindowLock.WriteLock(); } 90cc93fbbbSAxel Dörfler void UnlockAllWindows() 91cc93fbbbSAxel Dörfler { fWindowLock.WriteUnlock(); } 92cc93fbbbSAxel Dörfler 9378ca6157SAxel Dörfler const MultiLocker& WindowLocker() { return fWindowLock; } 94cc93fbbbSAxel Dörfler #else // USE_MULTI_LOCKER 95cc93fbbbSAxel Dörfler bool LockSingleWindow() 96cc93fbbbSAxel Dörfler { return fWindowLock.Lock(); } 97cc93fbbbSAxel Dörfler void UnlockSingleWindow() 98cc93fbbbSAxel Dörfler { fWindowLock.Unlock(); } 99cc93fbbbSAxel Dörfler 100cc93fbbbSAxel Dörfler bool LockAllWindows() 101cc93fbbbSAxel Dörfler { return fWindowLock.Lock(); } 102cc93fbbbSAxel Dörfler void UnlockAllWindows() 103cc93fbbbSAxel Dörfler { fWindowLock.Unlock(); } 104cc93fbbbSAxel Dörfler #endif // USE_MULTI_LOCKER 105cc93fbbbSAxel Dörfler 1060eed9183SAxel Dörfler // Mouse and cursor methods 10733bbe223SAxel Dörfler 108195e980eSAxel Dörfler void SetCursor(ServerCursor* cursor); 109ace2d5eeSStephan Aßmus ServerCursorReference Cursor() const; 1104d1c4228SStephan Aßmus void SetLastMouseState(const BPoint& position, 11121b40eddSStephan Aßmus int32 buttons, Window* windowUnderMouse); 1124d1c4228SStephan Aßmus // for use by the mouse filter only 1134d1c4228SStephan Aßmus // both mouse position calls require 1144d1c4228SStephan Aßmus // the Desktop object to be locked 1154d1c4228SStephan Aßmus // already 1164d1c4228SStephan Aßmus void GetLastMouseState(BPoint* position, 1174d1c4228SStephan Aßmus int32* buttons) const; 1184d1c4228SStephan Aßmus // for use by ServerWindow 1190eed9183SAxel Dörfler 1200eed9183SAxel Dörfler CursorManager& GetCursorManager() { return fCursorManager; } 1210eed9183SAxel Dörfler 122fe7f167dSAxel Dörfler // Screen and drawing related methods 123fe7f167dSAxel Dörfler 1240eed9183SAxel Dörfler status_t SetScreenMode(int32 workspace, int32 id, 1250eed9183SAxel Dörfler const display_mode& mode, bool makeDefault); 1260eed9183SAxel Dörfler status_t GetScreenMode(int32 workspace, int32 id, 1270eed9183SAxel Dörfler display_mode& mode); 128e18224cdSAxel Dörfler status_t GetScreenFrame(int32 workspace, int32 id, 129e18224cdSAxel Dörfler BRect& frame); 1305e3f4c41SAxel Dörfler void RevertScreenModes(uint32 workspaces); 1310eed9183SAxel Dörfler 13278ca6157SAxel Dörfler MultiLocker& ScreenLocker() { return fScreenLock; } 13378ca6157SAxel Dörfler 1349fe35223SAxel Dörfler status_t LockDirectScreen(team_id team); 1359fe35223SAxel Dörfler status_t UnlockDirectScreen(team_id team); 1369fe35223SAxel Dörfler 1375e3f4c41SAxel Dörfler const ::VirtualScreen& VirtualScreen() const 1385e3f4c41SAxel Dörfler { return fVirtualScreen; } 13927adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 14058468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 14127adb969SAxel Dörfler ::HWInterface* HWInterface() const 142fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 14394fa2bd2SAdi Oanca 1440eed9183SAxel Dörfler // ScreenOwner implementation 1455e3f4c41SAxel Dörfler virtual void ScreenRemoved(Screen* screen) {} 1465e3f4c41SAxel Dörfler virtual void ScreenAdded(Screen* screen) {} 1475e3f4c41SAxel Dörfler virtual bool ReleaseScreen(Screen* screen) { return false; } 1480eed9183SAxel Dörfler 14927adb969SAxel Dörfler // Workspace methods 15027adb969SAxel Dörfler 1514d1c4228SStephan Aßmus void SetWorkspaceAsync(int32 index); 15227adb969SAxel Dörfler void SetWorkspace(int32 index); 15327adb969SAxel Dörfler int32 CurrentWorkspace() 15427adb969SAxel Dörfler { return fCurrentWorkspace; } 1555ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 15627adb969SAxel Dörfler { return fWorkspaces[index]; } 15769f9a367SAxel Dörfler status_t SetWorkspacesLayout(int32 columns, int32 rows); 15827c43a2dSRene Gollent BRect WorkspaceFrame(int32 index) const; 15927adb969SAxel Dörfler 160cc93fbbbSAxel Dörfler void StoreWorkspaceConfiguration(int32 index); 161cc93fbbbSAxel Dörfler 162cc93fbbbSAxel Dörfler void AddWorkspacesView(WorkspacesView* view); 163cc93fbbbSAxel Dörfler void RemoveWorkspacesView(WorkspacesView* view); 164cc93fbbbSAxel Dörfler 165953d895eSAxel Dörfler // Window methods 16627adb969SAxel Dörfler 167926e63c8SBrecht Machiels void SelectWindow(Window* window); 168953d895eSAxel Dörfler void ActivateWindow(Window* window); 169953d895eSAxel Dörfler void SendWindowBehind(Window* window, 170953d895eSAxel Dörfler Window* behindOf = NULL); 17127adb969SAxel Dörfler 172953d895eSAxel Dörfler void ShowWindow(Window* window); 173953d895eSAxel Dörfler void HideWindow(Window* window); 17415918e4fSAxel Dörfler 175953d895eSAxel Dörfler void MoveWindowBy(Window* window, float x, float y, 17614fe11cfSAxel Dörfler int32 workspace = -1); 1779dbce7a4SAxel Dörfler void ResizeWindowBy(Window* window, float x, 1789dbce7a4SAxel Dörfler float y); 1799dbce7a4SAxel Dörfler bool SetWindowTabLocation(Window* window, 1809dbce7a4SAxel Dörfler float location); 181953d895eSAxel Dörfler bool SetWindowDecoratorSettings(Window* window, 182b30e9021SStephan Aßmus const BMessage& settings); 18319d801a6SAxel Dörfler 184953d895eSAxel Dörfler void SetWindowWorkspaces(Window* window, 185a631158aSAxel Dörfler uint32 workspaces); 18627adb969SAxel Dörfler 187953d895eSAxel Dörfler void AddWindow(Window* window); 188953d895eSAxel Dörfler void RemoveWindow(Window* window); 18957be2866SAxel Dörfler 190953d895eSAxel Dörfler bool AddWindowToSubset(Window* subset, 191953d895eSAxel Dörfler Window* window); 192953d895eSAxel Dörfler void RemoveWindowFromSubset(Window* subset, 193953d895eSAxel Dörfler Window* window); 19434227d2cSAxel Dörfler 1950a3f410fSAxel Dörfler void FontsChanged(Window* window); 1960a3f410fSAxel Dörfler 197953d895eSAxel Dörfler void SetWindowLook(Window* window, window_look look); 198953d895eSAxel Dörfler void SetWindowFeel(Window* window, window_feel feel); 199953d895eSAxel Dörfler void SetWindowFlags(Window* window, uint32 flags); 2009dbce7a4SAxel Dörfler void SetWindowTitle(Window* window, 2019dbce7a4SAxel Dörfler const char* title); 20233bbe223SAxel Dörfler 203953d895eSAxel Dörfler Window* FocusWindow() const { return fFocus; } 204953d895eSAxel Dörfler Window* FrontWindow() const { return fFront; } 205953d895eSAxel Dörfler Window* BackWindow() const { return fBack; } 206e83820edSAxel Dörfler 207953d895eSAxel Dörfler Window* WindowAt(BPoint where); 208e83820edSAxel Dörfler 2099dbce7a4SAxel Dörfler Window* MouseEventWindow() const 2109dbce7a4SAxel Dörfler { return fMouseEventWindow; } 211953d895eSAxel Dörfler void SetMouseEventWindow(Window* window); 212e83820edSAxel Dörfler 2139dbce7a4SAxel Dörfler void SetViewUnderMouse(const Window* window, 2149dbce7a4SAxel Dörfler int32 viewToken); 215953d895eSAxel Dörfler int32 ViewUnderMouse(const Window* window); 2161e766d46SAxel Dörfler 21707dc2c69SAxel Dörfler EventTarget* KeyboardEventTarget(); 218cc93fbbbSAxel Dörfler 219cc93fbbbSAxel Dörfler void SetFocusWindow(Window* window = NULL); 22021b40eddSStephan Aßmus void SetFocusLocked(const Window* window); 221e83820edSAxel Dörfler 222953d895eSAxel Dörfler Window* FindWindowByClientToken(int32 token, 223953d895eSAxel Dörfler team_id teamID); 22495530739SAxel Dörfler EventTarget* FindTarget(BMessenger& messenger); 2256a0a0a80SAxel Dörfler 226e83820edSAxel Dörfler void MarkDirty(BRegion& region); 227b09e2f6fSStephan Aßmus void Redraw(); 228cc93fbbbSAxel Dörfler void RedrawBackground(); 229e83820edSAxel Dörfler 230e83820edSAxel Dörfler BRegion& BackgroundRegion() 231e83820edSAxel Dörfler { return fBackgroundRegion; } 23233bbe223SAxel Dörfler 233f877af82SAxel Dörfler void MinimizeApplication(team_id team); 234f877af82SAxel Dörfler void BringApplicationToFront(team_id team); 235bfe69873SAxel Dörfler void WindowAction(int32 windowToken, int32 action); 236f877af82SAxel Dörfler 23727adb969SAxel Dörfler void WriteWindowList(team_id team, 23827adb969SAxel Dörfler BPrivate::LinkSender& sender); 23927adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 24027adb969SAxel Dörfler BPrivate::LinkSender& sender); 241ae0606beSAxel Dörfler void WriteApplicationOrder(int32 workspace, 242ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 243ae0606beSAxel Dörfler void WriteWindowOrder(int32 workspace, 244ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 24533bbe223SAxel Dörfler 246ef831a1dSPhilippe Houdoin WindowList& GetWindows(); 247ef831a1dSPhilippe Houdoin bool HighlightTab(Window* window, bool active); 248ef831a1dSPhilippe Houdoin bool HighlightBorders(Window* window, bool active); 249ef831a1dSPhilippe Houdoin void FinishStackingAndSnapping(); 250ef831a1dSPhilippe Houdoin Window* FindWindow(int32 windowId); 251ef831a1dSPhilippe Houdoin 252ef831a1dSPhilippe Houdoin bool fIsStackingAndSnapping; 253ef831a1dSPhilippe Houdoin LinearSpec* fStackAndTileSpec; 254ef831a1dSPhilippe Houdoin 25533bbe223SAxel Dörfler private: 2566869c8a5SRyan Leavengood void _LaunchInputServer(); 257cc93fbbbSAxel Dörfler void _GetLooperName(char* name, size_t size); 258cc93fbbbSAxel Dörfler void _PrepareQuit(); 259cc93fbbbSAxel Dörfler void _DispatchMessage(int32 code, 260cc93fbbbSAxel Dörfler BPrivate::LinkReceiver &link); 261e83820edSAxel Dörfler 262cc93fbbbSAxel Dörfler WindowList& _CurrentWindows(); 263cc93fbbbSAxel Dörfler WindowList& _Windows(int32 index); 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 276cc93fbbbSAxel Dörfler void _ShowWindow(Window* window, 277cc93fbbbSAxel Dörfler bool affectsOtherWindows = true); 278cc93fbbbSAxel Dörfler void _HideWindow(Window* window); 2795f2edc0fSAxel Dörfler 280cc93fbbbSAxel Dörfler void _UpdateSubsetWorkspaces(Window* window, 281cc93fbbbSAxel Dörfler int32 previousIndex = -1, 282cc93fbbbSAxel Dörfler int32 newIndex = -1); 283cc93fbbbSAxel Dörfler void _ChangeWindowWorkspaces(Window* window, 284cc93fbbbSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 285cc93fbbbSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 286cc93fbbbSAxel Dörfler int32 list, bool wereVisible); 287cc93fbbbSAxel Dörfler Window* _LastFocusSubsetWindow(Window* window); 288cc93fbbbSAxel Dörfler void _SendFakeMouseMoved(Window* window = NULL); 289cc93fbbbSAxel Dörfler 29078ca6157SAxel Dörfler Screen* _DetermineScreenFor(BRect frame); 291cc93fbbbSAxel Dörfler void _RebuildClippingForAllWindows( 292cc93fbbbSAxel Dörfler BRegion& stillAvailableOnScreen); 293cc93fbbbSAxel Dörfler void _TriggerWindowRedrawing( 294cc93fbbbSAxel Dörfler BRegion& newDirtyRegion); 295cc93fbbbSAxel Dörfler void _SetBackground(BRegion& background); 296cc93fbbbSAxel Dörfler void _RebuildAndRedrawAfterWindowChange( 297cc93fbbbSAxel Dörfler Window* window, BRegion& dirty); 298cc93fbbbSAxel Dörfler 299cc93fbbbSAxel Dörfler status_t _ActivateApp(team_id team); 300cc93fbbbSAxel Dörfler 30178ca6157SAxel Dörfler void _SuspendDirectFrameBufferAccess(); 30278ca6157SAxel Dörfler void _ResumeDirectFrameBufferAccess(); 30378ca6157SAxel Dörfler 304cc93fbbbSAxel Dörfler void _ScreenChanged(Screen* screen); 305cc93fbbbSAxel Dörfler void _SetCurrentWorkspaceConfiguration(); 306cc93fbbbSAxel Dörfler void _SetWorkspace(int32 index); 307e83820edSAxel Dörfler 308ef831a1dSPhilippe Houdoin bool _AddWindowsByIdsToList(BList* windowIdsToAdd, 309ef831a1dSPhilippe Houdoin BList* windows); 310ef831a1dSPhilippe Houdoin 3115f2edc0fSAxel Dörfler private: 312ef8810f2SAxel Dörfler friend class DesktopSettings; 313a17c3a48SAxel Dörfler friend class LockedDesktopSettings; 314ef8810f2SAxel Dörfler 31536deda69SAxel Dörfler uid_t fUserID; 31668667bf4SMichael Lotz const char* fTargetScreen; 317fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 318a17c3a48SAxel Dörfler DesktopSettingsPrivate* fSettings; 3195f2edc0fSAxel Dörfler port_id fMessagePort; 320f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 3216c17d025SAxel Dörfler port_id fInputPort; 3226d5488e1SAxel Dörfler area_id fSharedReadOnlyArea; 3236d5488e1SAxel Dörfler server_read_only_memory* fServerReadOnlyMemory; 324770c05d6SAxel Dörfler 325e83820edSAxel Dörfler BLocker fApplicationsLock; 326e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 327770c05d6SAxel Dörfler 328770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 329770c05d6SAxel Dörfler int32 fShutdownCount; 330770c05d6SAxel Dörfler 33182081c70SJérôme Duval ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 33278ca6157SAxel Dörfler MultiLocker fScreenLock; 3339fe35223SAxel Dörfler BLocker fDirectScreenLock; 3349fe35223SAxel Dörfler team_id fDirectScreenTeam; 33527adb969SAxel Dörfler int32 fCurrentWorkspace; 3364932bc5eSAxel Dörfler int32 fPreviousWorkspace; 33727adb969SAxel Dörfler 338e83820edSAxel Dörfler WindowList fAllWindows; 33934227d2cSAxel Dörfler WindowList fSubsetWindows; 340d01879e5SAxel Dörfler WindowList fFocusList; 341d8ebe612SAxel Dörfler 342953d895eSAxel Dörfler BObjectList<WorkspacesView> fWorkspacesViews; 343d8ebe612SAxel Dörfler BLocker fWorkspacesLock; 34433bbe223SAxel Dörfler 3453ddebe7eSMichael Lotz CursorManager fCursorManager; 346e83820edSAxel Dörfler 347e83820edSAxel Dörfler #if USE_MULTI_LOCKER 348e83820edSAxel Dörfler MultiLocker fWindowLock; 349e83820edSAxel Dörfler #else 350e83820edSAxel Dörfler BLocker fWindowLock; 351e83820edSAxel Dörfler #endif 352e83820edSAxel Dörfler 353e83820edSAxel Dörfler BRegion fBackgroundRegion; 354e83820edSAxel Dörfler BRegion fScreenRegion; 355e83820edSAxel Dörfler 356953d895eSAxel Dörfler Window* fMouseEventWindow; 357953d895eSAxel Dörfler const Window* fWindowUnderMouse; 35821b40eddSStephan Aßmus const Window* fLockedFocusWindow; 3591e766d46SAxel Dörfler int32 fViewUnderMouse; 3604d1c4228SStephan Aßmus BPoint fLastMousePosition; 3614d1c4228SStephan Aßmus int32 fLastMouseButtons; 3621e766d46SAxel Dörfler 363953d895eSAxel Dörfler Window* fFocus; 364953d895eSAxel Dörfler Window* fFront; 365953d895eSAxel Dörfler Window* fBack; 36633bbe223SAxel Dörfler }; 36733bbe223SAxel Dörfler 36827adb969SAxel Dörfler #endif // DESKTOP_H 369