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 3723e00a25SAxel Dörfler 3839c9925fSStephan Aßmus #define USE_MULTI_LOCKER 1 39e83820edSAxel Dörfler 40e83820edSAxel Dörfler #if USE_MULTI_LOCKER 41e83820edSAxel Dörfler # include "MultiLocker.h" 42e83820edSAxel Dörfler #else 43e83820edSAxel Dörfler # include <Locker.h> 44e83820edSAxel Dörfler #endif 4533bbe223SAxel Dörfler 460eed9183SAxel Dörfler 473dcb3b07SStephan Aßmus class BMessage; 486a0a0a80SAxel Dörfler 4958468dfeSStephan Aßmus class DrawingEngine; 503dcb3b07SStephan Aßmus class HWInterface; 51e83820edSAxel Dörfler class ServerApp; 52953d895eSAxel Dörfler class Window; 53953d895eSAxel Dörfler class WorkspacesView; 546d5488e1SAxel Dörfler struct server_read_only_memory; 5533bbe223SAxel Dörfler 566a0a0a80SAxel Dörfler namespace BPrivate { 576a0a0a80SAxel Dörfler class LinkSender; 586a0a0a80SAxel Dörfler }; 596a0a0a80SAxel Dörfler 600eed9183SAxel Dörfler 615f2edc0fSAxel Dörfler class Desktop : public MessageLooper, public ScreenOwner { 6233bbe223SAxel Dörfler public: 6368667bf4SMichael Lotz Desktop(uid_t userID, const char* targetScreen); 643dcb3b07SStephan Aßmus virtual ~Desktop(); 653dcb3b07SStephan Aßmus 666d5488e1SAxel Dörfler status_t Init(); 6736deda69SAxel Dörfler 6836deda69SAxel Dörfler uid_t UserID() const { return fUserID; } 6968667bf4SMichael Lotz const char* TargetScreen() { return fTargetScreen; } 70770c05d6SAxel Dörfler virtual port_id MessagePort() const { return fMessagePort; } 719dbce7a4SAxel Dörfler area_id SharedReadOnlyArea() const 729dbce7a4SAxel Dörfler { return fSharedReadOnlyArea; } 73770c05d6SAxel Dörfler 74f7598223SAxel Dörfler ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 756c17d025SAxel Dörfler 76770c05d6SAxel Dörfler void BroadcastToAllApps(int32 code); 770a3f410fSAxel Dörfler void BroadcastToAllWindows(int32 code); 7833bbe223SAxel Dörfler 79cc93fbbbSAxel Dörfler // Locking 80cc93fbbbSAxel Dörfler #if USE_MULTI_LOCKER 81cc93fbbbSAxel Dörfler bool LockSingleWindow() 82cc93fbbbSAxel Dörfler { return fWindowLock.ReadLock(); } 83cc93fbbbSAxel Dörfler void UnlockSingleWindow() 84cc93fbbbSAxel Dörfler { fWindowLock.ReadUnlock(); } 85cc93fbbbSAxel Dörfler 86cc93fbbbSAxel Dörfler bool LockAllWindows() 87cc93fbbbSAxel Dörfler { return fWindowLock.WriteLock(); } 88cc93fbbbSAxel Dörfler void UnlockAllWindows() 89cc93fbbbSAxel Dörfler { fWindowLock.WriteUnlock(); } 90cc93fbbbSAxel Dörfler 9178ca6157SAxel Dörfler const MultiLocker& WindowLocker() { return fWindowLock; } 92cc93fbbbSAxel Dörfler #else // USE_MULTI_LOCKER 93cc93fbbbSAxel Dörfler bool LockSingleWindow() 94cc93fbbbSAxel Dörfler { return fWindowLock.Lock(); } 95cc93fbbbSAxel Dörfler void UnlockSingleWindow() 96cc93fbbbSAxel Dörfler { fWindowLock.Unlock(); } 97cc93fbbbSAxel Dörfler 98cc93fbbbSAxel Dörfler bool LockAllWindows() 99cc93fbbbSAxel Dörfler { return fWindowLock.Lock(); } 100cc93fbbbSAxel Dörfler void UnlockAllWindows() 101cc93fbbbSAxel Dörfler { fWindowLock.Unlock(); } 102cc93fbbbSAxel Dörfler #endif // USE_MULTI_LOCKER 103cc93fbbbSAxel Dörfler 1040eed9183SAxel Dörfler // Mouse and cursor methods 10533bbe223SAxel Dörfler 106195e980eSAxel Dörfler void SetCursor(ServerCursor* cursor); 107ace2d5eeSStephan Aßmus ServerCursorReference Cursor() const; 1084d1c4228SStephan Aßmus void SetLastMouseState(const BPoint& position, 10921b40eddSStephan Aßmus int32 buttons, Window* windowUnderMouse); 1104d1c4228SStephan Aßmus // for use by the mouse filter only 1114d1c4228SStephan Aßmus // both mouse position calls require 1124d1c4228SStephan Aßmus // the Desktop object to be locked 1134d1c4228SStephan Aßmus // already 1144d1c4228SStephan Aßmus void GetLastMouseState(BPoint* position, 1154d1c4228SStephan Aßmus int32* buttons) const; 1164d1c4228SStephan Aßmus // for use by ServerWindow 1170eed9183SAxel Dörfler 1180eed9183SAxel Dörfler CursorManager& GetCursorManager() { return fCursorManager; } 1190eed9183SAxel Dörfler 120fe7f167dSAxel Dörfler // Screen and drawing related methods 121fe7f167dSAxel Dörfler 1220eed9183SAxel Dörfler status_t SetScreenMode(int32 workspace, int32 id, 1230eed9183SAxel Dörfler const display_mode& mode, bool makeDefault); 1240eed9183SAxel Dörfler status_t GetScreenMode(int32 workspace, int32 id, 1250eed9183SAxel Dörfler display_mode& mode); 126e18224cdSAxel Dörfler status_t GetScreenFrame(int32 workspace, int32 id, 127e18224cdSAxel Dörfler BRect& frame); 1285e3f4c41SAxel Dörfler void RevertScreenModes(uint32 workspaces); 1290eed9183SAxel Dörfler 13078ca6157SAxel Dörfler MultiLocker& ScreenLocker() { return fScreenLock; } 13178ca6157SAxel Dörfler 1329fe35223SAxel Dörfler status_t LockDirectScreen(team_id team); 1339fe35223SAxel Dörfler status_t UnlockDirectScreen(team_id team); 1349fe35223SAxel Dörfler 1355e3f4c41SAxel Dörfler const ::VirtualScreen& VirtualScreen() const 1365e3f4c41SAxel Dörfler { return fVirtualScreen; } 13727adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 13858468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 13927adb969SAxel Dörfler ::HWInterface* HWInterface() const 140fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 14194fa2bd2SAdi Oanca 1420eed9183SAxel Dörfler // ScreenOwner implementation 1435e3f4c41SAxel Dörfler virtual void ScreenRemoved(Screen* screen) {} 1445e3f4c41SAxel Dörfler virtual void ScreenAdded(Screen* screen) {} 1455e3f4c41SAxel Dörfler virtual bool ReleaseScreen(Screen* screen) { return false; } 1460eed9183SAxel Dörfler 14727adb969SAxel Dörfler // Workspace methods 14827adb969SAxel Dörfler 14947212dddSAxel Dörfler void SetWorkspaceAsync(int32 index, 15047212dddSAxel Dörfler bool moveFocusWindow = false); 15147212dddSAxel Dörfler void SetWorkspace(int32 index, 15247212dddSAxel Dörfler bool moveFocusWindow = false); 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 24633bbe223SAxel Dörfler private: 2476869c8a5SRyan Leavengood void _LaunchInputServer(); 248cc93fbbbSAxel Dörfler void _GetLooperName(char* name, size_t size); 249cc93fbbbSAxel Dörfler void _PrepareQuit(); 250cc93fbbbSAxel Dörfler void _DispatchMessage(int32 code, 251cc93fbbbSAxel Dörfler BPrivate::LinkReceiver &link); 252e83820edSAxel Dörfler 253cc93fbbbSAxel Dörfler WindowList& _CurrentWindows(); 254cc93fbbbSAxel Dörfler WindowList& _Windows(int32 index); 255e83820edSAxel Dörfler 25634227d2cSAxel Dörfler void _UpdateFloating(int32 previousWorkspace = -1, 257d479fa7aSAxel Dörfler int32 nextWorkspace = -1, 258953d895eSAxel Dörfler Window* mouseEventWindow = NULL); 259e83820edSAxel Dörfler void _UpdateBack(); 26034227d2cSAxel Dörfler void _UpdateFront(bool updateFloating = true); 26134227d2cSAxel Dörfler void _UpdateFronts(bool updateFloating = true); 262953d895eSAxel Dörfler bool _WindowHasModal(Window* window); 263e83820edSAxel Dörfler 264953d895eSAxel Dörfler void _WindowChanged(Window* window); 265953d895eSAxel Dörfler void _WindowRemoved(Window* window); 266ce8c4d79SAxel Dörfler 267cc93fbbbSAxel Dörfler void _ShowWindow(Window* window, 268cc93fbbbSAxel Dörfler bool affectsOtherWindows = true); 269cc93fbbbSAxel Dörfler void _HideWindow(Window* window); 2705f2edc0fSAxel Dörfler 271cc93fbbbSAxel Dörfler void _UpdateSubsetWorkspaces(Window* window, 272cc93fbbbSAxel Dörfler int32 previousIndex = -1, 273cc93fbbbSAxel Dörfler int32 newIndex = -1); 274cc93fbbbSAxel Dörfler void _ChangeWindowWorkspaces(Window* window, 275cc93fbbbSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 276cc93fbbbSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 277cc93fbbbSAxel Dörfler int32 list, bool wereVisible); 278cc93fbbbSAxel Dörfler Window* _LastFocusSubsetWindow(Window* window); 279cc93fbbbSAxel Dörfler void _SendFakeMouseMoved(Window* window = NULL); 280cc93fbbbSAxel Dörfler 28178ca6157SAxel Dörfler Screen* _DetermineScreenFor(BRect frame); 282cc93fbbbSAxel Dörfler void _RebuildClippingForAllWindows( 283cc93fbbbSAxel Dörfler BRegion& stillAvailableOnScreen); 284cc93fbbbSAxel Dörfler void _TriggerWindowRedrawing( 285cc93fbbbSAxel Dörfler BRegion& newDirtyRegion); 286cc93fbbbSAxel Dörfler void _SetBackground(BRegion& background); 287cc93fbbbSAxel Dörfler void _RebuildAndRedrawAfterWindowChange( 288cc93fbbbSAxel Dörfler Window* window, BRegion& dirty); 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; 30568667bf4SMichael Lotz const char* fTargetScreen; 306fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 307a17c3a48SAxel Dörfler DesktopSettingsPrivate* fSettings; 3085f2edc0fSAxel Dörfler port_id fMessagePort; 309f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 3106c17d025SAxel Dörfler port_id fInputPort; 3116d5488e1SAxel Dörfler area_id fSharedReadOnlyArea; 3126d5488e1SAxel Dörfler server_read_only_memory* fServerReadOnlyMemory; 313770c05d6SAxel Dörfler 314e83820edSAxel Dörfler BLocker fApplicationsLock; 315e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 316770c05d6SAxel Dörfler 317770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 318770c05d6SAxel Dörfler int32 fShutdownCount; 319770c05d6SAxel Dörfler 32082081c70SJérôme Duval ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 32178ca6157SAxel Dörfler MultiLocker fScreenLock; 3229fe35223SAxel Dörfler BLocker fDirectScreenLock; 3239fe35223SAxel Dörfler team_id fDirectScreenTeam; 32427adb969SAxel Dörfler int32 fCurrentWorkspace; 3254932bc5eSAxel Dörfler int32 fPreviousWorkspace; 32627adb969SAxel Dörfler 327e83820edSAxel Dörfler WindowList fAllWindows; 32834227d2cSAxel Dörfler WindowList fSubsetWindows; 329d01879e5SAxel Dörfler WindowList fFocusList; 330*0b63cc93SAxel Dörfler Window* fLastWorkspaceFocus[kMaxWorkspaces]; 331d8ebe612SAxel Dörfler 332953d895eSAxel Dörfler BObjectList<WorkspacesView> fWorkspacesViews; 333d8ebe612SAxel Dörfler BLocker fWorkspacesLock; 33433bbe223SAxel Dörfler 3353ddebe7eSMichael Lotz CursorManager fCursorManager; 336e83820edSAxel Dörfler 337e83820edSAxel Dörfler #if USE_MULTI_LOCKER 338e83820edSAxel Dörfler MultiLocker fWindowLock; 339e83820edSAxel Dörfler #else 340e83820edSAxel Dörfler BLocker fWindowLock; 341e83820edSAxel Dörfler #endif 342e83820edSAxel Dörfler 343e83820edSAxel Dörfler BRegion fBackgroundRegion; 344e83820edSAxel Dörfler BRegion fScreenRegion; 345e83820edSAxel Dörfler 346953d895eSAxel Dörfler Window* fMouseEventWindow; 347953d895eSAxel Dörfler const Window* fWindowUnderMouse; 34821b40eddSStephan Aßmus const Window* fLockedFocusWindow; 3491e766d46SAxel Dörfler int32 fViewUnderMouse; 3504d1c4228SStephan Aßmus BPoint fLastMousePosition; 3514d1c4228SStephan Aßmus int32 fLastMouseButtons; 3521e766d46SAxel Dörfler 353953d895eSAxel Dörfler Window* fFocus; 354953d895eSAxel Dörfler Window* fFront; 355953d895eSAxel Dörfler Window* fBack; 35633bbe223SAxel Dörfler }; 35733bbe223SAxel Dörfler 35827adb969SAxel Dörfler #endif // DESKTOP_H 359