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> 8*926e63c8SBrecht Machiels * Axel Dörfler <axeld@pinc-software.de> 9b09e2f6fSStephan Aßmus * Andrej Spielmann, <andrej.spielmann@seh.ox.ac.uk> 10*926e63c8SBrecht 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 370eed9183SAxel 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 1494d1c4228SStephan Aßmus void SetWorkspaceAsync(int32 index); 15027adb969SAxel Dörfler void SetWorkspace(int32 index); 15127adb969SAxel Dörfler int32 CurrentWorkspace() 15227adb969SAxel Dörfler { return fCurrentWorkspace; } 1535ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 15427adb969SAxel Dörfler { return fWorkspaces[index]; } 15569f9a367SAxel Dörfler status_t SetWorkspacesLayout(int32 columns, int32 rows); 15627c43a2dSRene Gollent BRect WorkspaceFrame(int32 index) const; 15727adb969SAxel Dörfler 158cc93fbbbSAxel Dörfler void StoreWorkspaceConfiguration(int32 index); 159cc93fbbbSAxel Dörfler 160cc93fbbbSAxel Dörfler void AddWorkspacesView(WorkspacesView* view); 161cc93fbbbSAxel Dörfler void RemoveWorkspacesView(WorkspacesView* view); 162cc93fbbbSAxel Dörfler 163953d895eSAxel Dörfler // Window methods 16427adb969SAxel Dörfler 165*926e63c8SBrecht Machiels void SelectWindow(Window* window); 166953d895eSAxel Dörfler void ActivateWindow(Window* window); 167953d895eSAxel Dörfler void SendWindowBehind(Window* window, 168953d895eSAxel Dörfler Window* behindOf = NULL); 16927adb969SAxel Dörfler 170953d895eSAxel Dörfler void ShowWindow(Window* window); 171953d895eSAxel Dörfler void HideWindow(Window* window); 17215918e4fSAxel Dörfler 173953d895eSAxel Dörfler void MoveWindowBy(Window* window, float x, float y, 17414fe11cfSAxel Dörfler int32 workspace = -1); 1759dbce7a4SAxel Dörfler void ResizeWindowBy(Window* window, float x, 1769dbce7a4SAxel Dörfler float y); 1779dbce7a4SAxel Dörfler bool SetWindowTabLocation(Window* window, 1789dbce7a4SAxel Dörfler float location); 179953d895eSAxel Dörfler bool SetWindowDecoratorSettings(Window* window, 180b30e9021SStephan Aßmus const BMessage& settings); 18119d801a6SAxel Dörfler 182953d895eSAxel Dörfler void SetWindowWorkspaces(Window* window, 183a631158aSAxel Dörfler uint32 workspaces); 18427adb969SAxel Dörfler 185953d895eSAxel Dörfler void AddWindow(Window* window); 186953d895eSAxel Dörfler void RemoveWindow(Window* window); 18757be2866SAxel Dörfler 188953d895eSAxel Dörfler bool AddWindowToSubset(Window* subset, 189953d895eSAxel Dörfler Window* window); 190953d895eSAxel Dörfler void RemoveWindowFromSubset(Window* subset, 191953d895eSAxel Dörfler Window* window); 19234227d2cSAxel Dörfler 1930a3f410fSAxel Dörfler void FontsChanged(Window* window); 1940a3f410fSAxel Dörfler 195953d895eSAxel Dörfler void SetWindowLook(Window* window, window_look look); 196953d895eSAxel Dörfler void SetWindowFeel(Window* window, window_feel feel); 197953d895eSAxel Dörfler void SetWindowFlags(Window* window, uint32 flags); 1989dbce7a4SAxel Dörfler void SetWindowTitle(Window* window, 1999dbce7a4SAxel Dörfler const char* title); 20033bbe223SAxel Dörfler 201953d895eSAxel Dörfler Window* FocusWindow() const { return fFocus; } 202953d895eSAxel Dörfler Window* FrontWindow() const { return fFront; } 203953d895eSAxel Dörfler Window* BackWindow() const { return fBack; } 204e83820edSAxel Dörfler 205953d895eSAxel Dörfler Window* WindowAt(BPoint where); 206e83820edSAxel Dörfler 2079dbce7a4SAxel Dörfler Window* MouseEventWindow() const 2089dbce7a4SAxel Dörfler { return fMouseEventWindow; } 209953d895eSAxel Dörfler void SetMouseEventWindow(Window* window); 210e83820edSAxel Dörfler 2119dbce7a4SAxel Dörfler void SetViewUnderMouse(const Window* window, 2129dbce7a4SAxel Dörfler int32 viewToken); 213953d895eSAxel Dörfler int32 ViewUnderMouse(const Window* window); 2141e766d46SAxel Dörfler 21507dc2c69SAxel Dörfler EventTarget* KeyboardEventTarget(); 216cc93fbbbSAxel Dörfler 217cc93fbbbSAxel Dörfler void SetFocusWindow(Window* window = NULL); 21821b40eddSStephan Aßmus void SetFocusLocked(const Window* window); 219e83820edSAxel Dörfler 220953d895eSAxel Dörfler Window* FindWindowByClientToken(int32 token, 221953d895eSAxel Dörfler team_id teamID); 22295530739SAxel Dörfler EventTarget* FindTarget(BMessenger& messenger); 2236a0a0a80SAxel Dörfler 224e83820edSAxel Dörfler void MarkDirty(BRegion& region); 225b09e2f6fSStephan Aßmus void Redraw(); 226cc93fbbbSAxel Dörfler void RedrawBackground(); 227e83820edSAxel Dörfler 228e83820edSAxel Dörfler BRegion& BackgroundRegion() 229e83820edSAxel Dörfler { return fBackgroundRegion; } 23033bbe223SAxel Dörfler 231f877af82SAxel Dörfler void MinimizeApplication(team_id team); 232f877af82SAxel Dörfler void BringApplicationToFront(team_id team); 233bfe69873SAxel Dörfler void WindowAction(int32 windowToken, int32 action); 234f877af82SAxel Dörfler 23527adb969SAxel Dörfler void WriteWindowList(team_id team, 23627adb969SAxel Dörfler BPrivate::LinkSender& sender); 23727adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 23827adb969SAxel Dörfler BPrivate::LinkSender& sender); 239ae0606beSAxel Dörfler void WriteApplicationOrder(int32 workspace, 240ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 241ae0606beSAxel Dörfler void WriteWindowOrder(int32 workspace, 242ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 24333bbe223SAxel Dörfler 24433bbe223SAxel Dörfler private: 2456869c8a5SRyan Leavengood void _LaunchInputServer(); 246cc93fbbbSAxel Dörfler void _GetLooperName(char* name, size_t size); 247cc93fbbbSAxel Dörfler void _PrepareQuit(); 248cc93fbbbSAxel Dörfler void _DispatchMessage(int32 code, 249cc93fbbbSAxel Dörfler BPrivate::LinkReceiver &link); 250e83820edSAxel Dörfler 251cc93fbbbSAxel Dörfler WindowList& _CurrentWindows(); 252cc93fbbbSAxel Dörfler WindowList& _Windows(int32 index); 253e83820edSAxel Dörfler 25434227d2cSAxel Dörfler void _UpdateFloating(int32 previousWorkspace = -1, 255d479fa7aSAxel Dörfler int32 nextWorkspace = -1, 256953d895eSAxel Dörfler Window* mouseEventWindow = NULL); 257e83820edSAxel Dörfler void _UpdateBack(); 25834227d2cSAxel Dörfler void _UpdateFront(bool updateFloating = true); 25934227d2cSAxel Dörfler void _UpdateFronts(bool updateFloating = true); 260953d895eSAxel Dörfler bool _WindowHasModal(Window* window); 261e83820edSAxel Dörfler 262953d895eSAxel Dörfler void _WindowChanged(Window* window); 263953d895eSAxel Dörfler void _WindowRemoved(Window* window); 264ce8c4d79SAxel Dörfler 265cc93fbbbSAxel Dörfler void _ShowWindow(Window* window, 266cc93fbbbSAxel Dörfler bool affectsOtherWindows = true); 267cc93fbbbSAxel Dörfler void _HideWindow(Window* window); 2685f2edc0fSAxel Dörfler 269cc93fbbbSAxel Dörfler void _UpdateSubsetWorkspaces(Window* window, 270cc93fbbbSAxel Dörfler int32 previousIndex = -1, 271cc93fbbbSAxel Dörfler int32 newIndex = -1); 272cc93fbbbSAxel Dörfler void _ChangeWindowWorkspaces(Window* window, 273cc93fbbbSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 274cc93fbbbSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 275cc93fbbbSAxel Dörfler int32 list, bool wereVisible); 276cc93fbbbSAxel Dörfler Window* _LastFocusSubsetWindow(Window* window); 277cc93fbbbSAxel Dörfler void _SendFakeMouseMoved(Window* window = NULL); 278cc93fbbbSAxel Dörfler 27978ca6157SAxel Dörfler Screen* _DetermineScreenFor(BRect frame); 280cc93fbbbSAxel Dörfler void _RebuildClippingForAllWindows( 281cc93fbbbSAxel Dörfler BRegion& stillAvailableOnScreen); 282cc93fbbbSAxel Dörfler void _TriggerWindowRedrawing( 283cc93fbbbSAxel Dörfler BRegion& newDirtyRegion); 284cc93fbbbSAxel Dörfler void _SetBackground(BRegion& background); 285cc93fbbbSAxel Dörfler void _RebuildAndRedrawAfterWindowChange( 286cc93fbbbSAxel Dörfler Window* window, BRegion& dirty); 287cc93fbbbSAxel Dörfler 288cc93fbbbSAxel Dörfler status_t _ActivateApp(team_id team); 289cc93fbbbSAxel Dörfler 29078ca6157SAxel Dörfler void _SuspendDirectFrameBufferAccess(); 29178ca6157SAxel Dörfler void _ResumeDirectFrameBufferAccess(); 29278ca6157SAxel Dörfler 293cc93fbbbSAxel Dörfler void _ScreenChanged(Screen* screen); 294cc93fbbbSAxel Dörfler void _SetCurrentWorkspaceConfiguration(); 295cc93fbbbSAxel Dörfler void _SetWorkspace(int32 index); 296e83820edSAxel Dörfler 2975f2edc0fSAxel Dörfler private: 298ef8810f2SAxel Dörfler friend class DesktopSettings; 299a17c3a48SAxel Dörfler friend class LockedDesktopSettings; 300ef8810f2SAxel Dörfler 30136deda69SAxel Dörfler uid_t fUserID; 30268667bf4SMichael Lotz const char* fTargetScreen; 303fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 304a17c3a48SAxel Dörfler DesktopSettingsPrivate* fSettings; 3055f2edc0fSAxel Dörfler port_id fMessagePort; 306f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 3076c17d025SAxel Dörfler port_id fInputPort; 3086d5488e1SAxel Dörfler area_id fSharedReadOnlyArea; 3096d5488e1SAxel Dörfler server_read_only_memory* fServerReadOnlyMemory; 310770c05d6SAxel Dörfler 311e83820edSAxel Dörfler BLocker fApplicationsLock; 312e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 313770c05d6SAxel Dörfler 314770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 315770c05d6SAxel Dörfler int32 fShutdownCount; 316770c05d6SAxel Dörfler 31782081c70SJérôme Duval ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 31878ca6157SAxel Dörfler MultiLocker fScreenLock; 3199fe35223SAxel Dörfler BLocker fDirectScreenLock; 3209fe35223SAxel Dörfler team_id fDirectScreenTeam; 32127adb969SAxel Dörfler int32 fCurrentWorkspace; 3224932bc5eSAxel Dörfler int32 fPreviousWorkspace; 32327adb969SAxel Dörfler 324e83820edSAxel Dörfler WindowList fAllWindows; 32534227d2cSAxel Dörfler WindowList fSubsetWindows; 326d01879e5SAxel Dörfler WindowList fFocusList; 327d8ebe612SAxel Dörfler 328953d895eSAxel Dörfler BObjectList<WorkspacesView> fWorkspacesViews; 329d8ebe612SAxel Dörfler BLocker fWorkspacesLock; 33033bbe223SAxel Dörfler 3313ddebe7eSMichael Lotz CursorManager fCursorManager; 332e83820edSAxel Dörfler 333e83820edSAxel Dörfler #if USE_MULTI_LOCKER 334e83820edSAxel Dörfler MultiLocker fWindowLock; 335e83820edSAxel Dörfler #else 336e83820edSAxel Dörfler BLocker fWindowLock; 337e83820edSAxel Dörfler #endif 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