16a0a0a80SAxel Dörfler /* 2*bb86786aSClemens 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> 11*bb86786aSClemens 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 173ddebe7eSMichael Lotz #include "CursorManager.h" 18860dfc9aSClemens Zeidler #include "DesktopListener.h" 19ace2d5eeSStephan Aßmus #include "DesktopSettings.h" 2008f35604SAxel Dörfler #include "EventDispatcher.h" 21ace2d5eeSStephan Aßmus #include "MessageLooper.h" 22953d895eSAxel Dörfler #include "Screen.h" 23fd5bec1eSAxel Dörfler #include "ScreenManager.h" 24ace2d5eeSStephan Aßmus #include "ServerCursor.h" 25fd5bec1eSAxel Dörfler #include "VirtualScreen.h" 26e83820edSAxel Dörfler #include "WindowList.h" 2727adb969SAxel Dörfler #include "Workspace.h" 285ca8477eSAxel Dörfler #include "WorkspacePrivate.h" 29fd5bec1eSAxel Dörfler 30e83820edSAxel Dörfler #include <ObjectList.h> 31e83820edSAxel Dörfler 32e83820edSAxel Dörfler #include <Autolock.h> 3333bbe223SAxel Dörfler #include <InterfaceDefs.h> 343dcb3b07SStephan Aßmus #include <List.h> 353dcb3b07SStephan Aßmus #include <Menu.h> 36e83820edSAxel Dörfler #include <Region.h> 3757be2866SAxel Dörfler #include <Window.h> 386a0a0a80SAxel Dörfler 3923e00a25SAxel 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 63860dfc9aSClemens Zeidler class Desktop : public DesktopObservable, public MessageLooper, 64860dfc9aSClemens Zeidler public ScreenOwner { 6533bbe223SAxel Dörfler public: 6668667bf4SMichael Lotz Desktop(uid_t userID, const char* targetScreen); 673dcb3b07SStephan Aßmus virtual ~Desktop(); 683dcb3b07SStephan Aßmus 696d5488e1SAxel Dörfler status_t Init(); 7036deda69SAxel Dörfler 7136deda69SAxel Dörfler uid_t UserID() const { return fUserID; } 7268667bf4SMichael Lotz const char* TargetScreen() { return fTargetScreen; } 73770c05d6SAxel Dörfler virtual port_id MessagePort() const { return fMessagePort; } 749dbce7a4SAxel Dörfler area_id SharedReadOnlyArea() const 759dbce7a4SAxel Dörfler { return fSharedReadOnlyArea; } 76770c05d6SAxel Dörfler 77f7598223SAxel Dörfler ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 786c17d025SAxel Dörfler 79770c05d6SAxel Dörfler void BroadcastToAllApps(int32 code); 800a3f410fSAxel Dörfler void BroadcastToAllWindows(int32 code); 8133bbe223SAxel Dörfler 82860dfc9aSClemens Zeidler void KeyEvent(uint32 what, int32 key, 83860dfc9aSClemens Zeidler int32 modifiers); 84cc93fbbbSAxel Dörfler // Locking 85cc93fbbbSAxel Dörfler #if USE_MULTI_LOCKER 86cc93fbbbSAxel Dörfler bool LockSingleWindow() 87cc93fbbbSAxel Dörfler { return fWindowLock.ReadLock(); } 88cc93fbbbSAxel Dörfler void UnlockSingleWindow() 89cc93fbbbSAxel Dörfler { fWindowLock.ReadUnlock(); } 90cc93fbbbSAxel Dörfler 91cc93fbbbSAxel Dörfler bool LockAllWindows() 92cc93fbbbSAxel Dörfler { return fWindowLock.WriteLock(); } 93cc93fbbbSAxel Dörfler void UnlockAllWindows() 94cc93fbbbSAxel Dörfler { fWindowLock.WriteUnlock(); } 95cc93fbbbSAxel Dörfler 9678ca6157SAxel Dörfler const MultiLocker& WindowLocker() { return fWindowLock; } 97cc93fbbbSAxel Dörfler #else // USE_MULTI_LOCKER 98cc93fbbbSAxel Dörfler bool LockSingleWindow() 99cc93fbbbSAxel Dörfler { return fWindowLock.Lock(); } 100cc93fbbbSAxel Dörfler void UnlockSingleWindow() 101cc93fbbbSAxel Dörfler { fWindowLock.Unlock(); } 102cc93fbbbSAxel Dörfler 103cc93fbbbSAxel Dörfler bool LockAllWindows() 104cc93fbbbSAxel Dörfler { return fWindowLock.Lock(); } 105cc93fbbbSAxel Dörfler void UnlockAllWindows() 106cc93fbbbSAxel Dörfler { fWindowLock.Unlock(); } 107cc93fbbbSAxel Dörfler #endif // USE_MULTI_LOCKER 108cc93fbbbSAxel Dörfler 1090eed9183SAxel Dörfler // Mouse and cursor methods 11033bbe223SAxel Dörfler 111195e980eSAxel Dörfler void SetCursor(ServerCursor* cursor); 112ace2d5eeSStephan Aßmus ServerCursorReference Cursor() const; 1134d1c4228SStephan Aßmus void SetLastMouseState(const BPoint& position, 11421b40eddSStephan Aßmus int32 buttons, Window* windowUnderMouse); 1154d1c4228SStephan Aßmus // for use by the mouse filter only 1164d1c4228SStephan Aßmus // both mouse position calls require 1174d1c4228SStephan Aßmus // the Desktop object to be locked 1184d1c4228SStephan Aßmus // already 1194d1c4228SStephan Aßmus void GetLastMouseState(BPoint* position, 1204d1c4228SStephan Aßmus int32* buttons) const; 1214d1c4228SStephan Aßmus // for use by ServerWindow 1220eed9183SAxel Dörfler 1230eed9183SAxel Dörfler CursorManager& GetCursorManager() { return fCursorManager; } 1240eed9183SAxel Dörfler 125fe7f167dSAxel Dörfler // Screen and drawing related methods 126fe7f167dSAxel Dörfler 1270eed9183SAxel Dörfler status_t SetScreenMode(int32 workspace, int32 id, 1280eed9183SAxel Dörfler const display_mode& mode, bool makeDefault); 1290eed9183SAxel Dörfler status_t GetScreenMode(int32 workspace, int32 id, 1300eed9183SAxel Dörfler display_mode& mode); 131e18224cdSAxel Dörfler status_t GetScreenFrame(int32 workspace, int32 id, 132e18224cdSAxel Dörfler BRect& frame); 1335e3f4c41SAxel Dörfler void RevertScreenModes(uint32 workspaces); 1340eed9183SAxel Dörfler 13578ca6157SAxel Dörfler MultiLocker& ScreenLocker() { return fScreenLock; } 13678ca6157SAxel Dörfler 1379fe35223SAxel Dörfler status_t LockDirectScreen(team_id team); 1389fe35223SAxel Dörfler status_t UnlockDirectScreen(team_id team); 1399fe35223SAxel Dörfler 1405e3f4c41SAxel Dörfler const ::VirtualScreen& VirtualScreen() const 1415e3f4c41SAxel Dörfler { return fVirtualScreen; } 14227adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 14358468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 14427adb969SAxel Dörfler ::HWInterface* HWInterface() const 145fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 14694fa2bd2SAdi Oanca 1470eed9183SAxel Dörfler // ScreenOwner implementation 1485e3f4c41SAxel Dörfler virtual void ScreenRemoved(Screen* screen) {} 1495e3f4c41SAxel Dörfler virtual void ScreenAdded(Screen* screen) {} 1505e3f4c41SAxel Dörfler virtual bool ReleaseScreen(Screen* screen) { return false; } 1510eed9183SAxel Dörfler 15227adb969SAxel Dörfler // Workspace methods 15327adb969SAxel Dörfler 15447212dddSAxel Dörfler void SetWorkspaceAsync(int32 index, 15547212dddSAxel Dörfler bool moveFocusWindow = false); 15647212dddSAxel Dörfler void SetWorkspace(int32 index, 15747212dddSAxel Dörfler bool moveFocusWindow = false); 15827adb969SAxel Dörfler int32 CurrentWorkspace() 15927adb969SAxel Dörfler { return fCurrentWorkspace; } 1605ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 16127adb969SAxel Dörfler { return fWorkspaces[index]; } 16269f9a367SAxel Dörfler status_t SetWorkspacesLayout(int32 columns, int32 rows); 16327c43a2dSRene Gollent BRect WorkspaceFrame(int32 index) const; 16427adb969SAxel Dörfler 165cc93fbbbSAxel Dörfler void StoreWorkspaceConfiguration(int32 index); 166cc93fbbbSAxel Dörfler 167cc93fbbbSAxel Dörfler void AddWorkspacesView(WorkspacesView* view); 168cc93fbbbSAxel Dörfler void RemoveWorkspacesView(WorkspacesView* view); 169cc93fbbbSAxel Dörfler 170953d895eSAxel Dörfler // Window methods 17127adb969SAxel Dörfler 172926e63c8SBrecht Machiels void SelectWindow(Window* window); 173953d895eSAxel Dörfler void ActivateWindow(Window* window); 174953d895eSAxel Dörfler void SendWindowBehind(Window* window, 175953d895eSAxel Dörfler Window* behindOf = NULL); 17627adb969SAxel Dörfler 177953d895eSAxel Dörfler void ShowWindow(Window* window); 178953d895eSAxel Dörfler void HideWindow(Window* window); 179860dfc9aSClemens Zeidler void MinimizeWindow(Window* window, bool minimize); 18015918e4fSAxel Dörfler 181953d895eSAxel Dörfler void MoveWindowBy(Window* window, float x, float y, 18214fe11cfSAxel Dörfler int32 workspace = -1); 1839dbce7a4SAxel Dörfler void ResizeWindowBy(Window* window, float x, 1849dbce7a4SAxel Dörfler float y); 1859dbce7a4SAxel Dörfler bool SetWindowTabLocation(Window* window, 1869dbce7a4SAxel Dörfler float location); 187953d895eSAxel Dörfler bool SetWindowDecoratorSettings(Window* window, 188b30e9021SStephan Aßmus const BMessage& settings); 18919d801a6SAxel Dörfler 190953d895eSAxel Dörfler void SetWindowWorkspaces(Window* window, 191a631158aSAxel Dörfler uint32 workspaces); 19227adb969SAxel Dörfler 193953d895eSAxel Dörfler void AddWindow(Window* window); 194953d895eSAxel Dörfler void RemoveWindow(Window* window); 19557be2866SAxel Dörfler 196953d895eSAxel Dörfler bool AddWindowToSubset(Window* subset, 197953d895eSAxel Dörfler Window* window); 198953d895eSAxel Dörfler void RemoveWindowFromSubset(Window* subset, 199953d895eSAxel Dörfler Window* window); 20034227d2cSAxel Dörfler 2010a3f410fSAxel Dörfler void FontsChanged(Window* window); 2020a3f410fSAxel Dörfler 203953d895eSAxel Dörfler void SetWindowLook(Window* window, window_look look); 204953d895eSAxel Dörfler void SetWindowFeel(Window* window, window_feel feel); 205953d895eSAxel Dörfler void SetWindowFlags(Window* window, uint32 flags); 2069dbce7a4SAxel Dörfler void SetWindowTitle(Window* window, 2079dbce7a4SAxel Dörfler const char* title); 20833bbe223SAxel Dörfler 209953d895eSAxel Dörfler Window* FocusWindow() const { return fFocus; } 210953d895eSAxel Dörfler Window* FrontWindow() const { return fFront; } 211953d895eSAxel Dörfler Window* BackWindow() const { return fBack; } 212e83820edSAxel Dörfler 213953d895eSAxel Dörfler Window* WindowAt(BPoint where); 214e83820edSAxel Dörfler 2159dbce7a4SAxel Dörfler Window* MouseEventWindow() const 2169dbce7a4SAxel Dörfler { return fMouseEventWindow; } 217953d895eSAxel Dörfler void SetMouseEventWindow(Window* window); 218e83820edSAxel Dörfler 2199dbce7a4SAxel Dörfler void SetViewUnderMouse(const Window* window, 2209dbce7a4SAxel Dörfler int32 viewToken); 221953d895eSAxel Dörfler int32 ViewUnderMouse(const Window* window); 2221e766d46SAxel Dörfler 22307dc2c69SAxel Dörfler EventTarget* KeyboardEventTarget(); 224cc93fbbbSAxel Dörfler 225cc93fbbbSAxel Dörfler void SetFocusWindow(Window* window = NULL); 22621b40eddSStephan Aßmus void SetFocusLocked(const Window* window); 227e83820edSAxel Dörfler 228953d895eSAxel Dörfler Window* FindWindowByClientToken(int32 token, 229953d895eSAxel Dörfler team_id teamID); 23095530739SAxel Dörfler EventTarget* FindTarget(BMessenger& messenger); 2316a0a0a80SAxel Dörfler 232e83820edSAxel Dörfler void MarkDirty(BRegion& region); 233b09e2f6fSStephan Aßmus void Redraw(); 234cc93fbbbSAxel Dörfler void RedrawBackground(); 235e83820edSAxel Dörfler 236*bb86786aSClemens Zeidler void ReloadDecorator(Window* window); 237*bb86786aSClemens Zeidler 238e83820edSAxel Dörfler BRegion& BackgroundRegion() 239e83820edSAxel Dörfler { return fBackgroundRegion; } 24033bbe223SAxel Dörfler 241f877af82SAxel Dörfler void MinimizeApplication(team_id team); 242f877af82SAxel Dörfler void BringApplicationToFront(team_id team); 243bfe69873SAxel Dörfler void WindowAction(int32 windowToken, int32 action); 244f877af82SAxel Dörfler 24527adb969SAxel Dörfler void WriteWindowList(team_id team, 24627adb969SAxel Dörfler BPrivate::LinkSender& sender); 24727adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 24827adb969SAxel Dörfler BPrivate::LinkSender& sender); 249ae0606beSAxel Dörfler void WriteApplicationOrder(int32 workspace, 250ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 251ae0606beSAxel Dörfler void WriteWindowOrder(int32 workspace, 252ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 25333bbe223SAxel Dörfler 254860dfc9aSClemens Zeidler WindowList& CurrentWindows(); 255*bb86786aSClemens Zeidler WindowList& Windows(int32 index); 256860dfc9aSClemens Zeidler 25733bbe223SAxel Dörfler private: 2586869c8a5SRyan Leavengood void _LaunchInputServer(); 259cc93fbbbSAxel Dörfler void _GetLooperName(char* name, size_t size); 260cc93fbbbSAxel Dörfler void _PrepareQuit(); 261cc93fbbbSAxel Dörfler void _DispatchMessage(int32 code, 262cc93fbbbSAxel Dörfler BPrivate::LinkReceiver &link); 263e83820edSAxel Dörfler 26434227d2cSAxel Dörfler void _UpdateFloating(int32 previousWorkspace = -1, 265d479fa7aSAxel Dörfler int32 nextWorkspace = -1, 266953d895eSAxel Dörfler Window* mouseEventWindow = NULL); 267e83820edSAxel Dörfler void _UpdateBack(); 26834227d2cSAxel Dörfler void _UpdateFront(bool updateFloating = true); 26934227d2cSAxel Dörfler void _UpdateFronts(bool updateFloating = true); 270953d895eSAxel Dörfler bool _WindowHasModal(Window* window); 271e83820edSAxel Dörfler 272953d895eSAxel Dörfler void _WindowChanged(Window* window); 273953d895eSAxel Dörfler void _WindowRemoved(Window* window); 274ce8c4d79SAxel Dörfler 275cc93fbbbSAxel Dörfler void _ShowWindow(Window* window, 276cc93fbbbSAxel Dörfler bool affectsOtherWindows = true); 277cc93fbbbSAxel Dörfler void _HideWindow(Window* window); 2785f2edc0fSAxel Dörfler 279cc93fbbbSAxel Dörfler void _UpdateSubsetWorkspaces(Window* window, 280cc93fbbbSAxel Dörfler int32 previousIndex = -1, 281cc93fbbbSAxel Dörfler int32 newIndex = -1); 282cc93fbbbSAxel Dörfler void _ChangeWindowWorkspaces(Window* window, 283cc93fbbbSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 284cc93fbbbSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 285cc93fbbbSAxel Dörfler int32 list, bool wereVisible); 286cc93fbbbSAxel Dörfler Window* _LastFocusSubsetWindow(Window* window); 287cc93fbbbSAxel Dörfler void _SendFakeMouseMoved(Window* window = NULL); 288cc93fbbbSAxel Dörfler 28978ca6157SAxel Dörfler Screen* _DetermineScreenFor(BRect frame); 290cc93fbbbSAxel Dörfler void _RebuildClippingForAllWindows( 291cc93fbbbSAxel Dörfler BRegion& stillAvailableOnScreen); 292cc93fbbbSAxel Dörfler void _TriggerWindowRedrawing( 293cc93fbbbSAxel Dörfler BRegion& newDirtyRegion); 294cc93fbbbSAxel Dörfler void _SetBackground(BRegion& background); 295cc93fbbbSAxel Dörfler void _RebuildAndRedrawAfterWindowChange( 296cc93fbbbSAxel Dörfler Window* window, BRegion& dirty); 297cc93fbbbSAxel Dörfler 298cc93fbbbSAxel Dörfler status_t _ActivateApp(team_id team); 299cc93fbbbSAxel Dörfler 30078ca6157SAxel Dörfler void _SuspendDirectFrameBufferAccess(); 30178ca6157SAxel Dörfler void _ResumeDirectFrameBufferAccess(); 30278ca6157SAxel Dörfler 303cc93fbbbSAxel Dörfler void _ScreenChanged(Screen* screen); 304cc93fbbbSAxel Dörfler void _SetCurrentWorkspaceConfiguration(); 30547212dddSAxel Dörfler void _SetWorkspace(int32 index, 30647212dddSAxel Dörfler bool moveFocusWindow = false); 307e83820edSAxel Dörfler 3085f2edc0fSAxel Dörfler private: 309ef8810f2SAxel Dörfler friend class DesktopSettings; 310a17c3a48SAxel Dörfler friend class LockedDesktopSettings; 311ef8810f2SAxel Dörfler 31236deda69SAxel Dörfler uid_t fUserID; 31368667bf4SMichael Lotz const char* fTargetScreen; 314fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 315a17c3a48SAxel Dörfler DesktopSettingsPrivate* fSettings; 3165f2edc0fSAxel Dörfler port_id fMessagePort; 317f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 3186c17d025SAxel Dörfler port_id fInputPort; 3196d5488e1SAxel Dörfler area_id fSharedReadOnlyArea; 3206d5488e1SAxel Dörfler server_read_only_memory* fServerReadOnlyMemory; 321770c05d6SAxel Dörfler 322e83820edSAxel Dörfler BLocker fApplicationsLock; 323e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 324770c05d6SAxel Dörfler 325770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 326770c05d6SAxel Dörfler int32 fShutdownCount; 327770c05d6SAxel Dörfler 32882081c70SJérôme Duval ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 32978ca6157SAxel Dörfler MultiLocker fScreenLock; 3309fe35223SAxel Dörfler BLocker fDirectScreenLock; 3319fe35223SAxel Dörfler team_id fDirectScreenTeam; 33227adb969SAxel Dörfler int32 fCurrentWorkspace; 3334932bc5eSAxel Dörfler int32 fPreviousWorkspace; 33427adb969SAxel Dörfler 335e83820edSAxel Dörfler WindowList fAllWindows; 33634227d2cSAxel Dörfler WindowList fSubsetWindows; 337d01879e5SAxel Dörfler WindowList fFocusList; 3380b63cc93SAxel Dörfler Window* fLastWorkspaceFocus[kMaxWorkspaces]; 339d8ebe612SAxel Dörfler 340953d895eSAxel Dörfler BObjectList<WorkspacesView> fWorkspacesViews; 341d8ebe612SAxel Dörfler BLocker fWorkspacesLock; 34233bbe223SAxel Dörfler 3433ddebe7eSMichael Lotz CursorManager fCursorManager; 344e83820edSAxel Dörfler 345e83820edSAxel Dörfler #if USE_MULTI_LOCKER 346e83820edSAxel Dörfler MultiLocker fWindowLock; 347e83820edSAxel Dörfler #else 348e83820edSAxel Dörfler BLocker fWindowLock; 349e83820edSAxel Dörfler #endif 350e83820edSAxel Dörfler 351e83820edSAxel Dörfler BRegion fBackgroundRegion; 352e83820edSAxel Dörfler BRegion fScreenRegion; 353e83820edSAxel Dörfler 354953d895eSAxel Dörfler Window* fMouseEventWindow; 355953d895eSAxel Dörfler const Window* fWindowUnderMouse; 35621b40eddSStephan Aßmus const Window* fLockedFocusWindow; 3571e766d46SAxel Dörfler int32 fViewUnderMouse; 3584d1c4228SStephan Aßmus BPoint fLastMousePosition; 3594d1c4228SStephan Aßmus int32 fLastMouseButtons; 3601e766d46SAxel Dörfler 361953d895eSAxel Dörfler Window* fFocus; 362953d895eSAxel Dörfler Window* fFront; 363953d895eSAxel Dörfler Window* fBack; 36433bbe223SAxel Dörfler }; 36533bbe223SAxel Dörfler 36627adb969SAxel Dörfler #endif // DESKTOP_H 367