16a0a0a80SAxel Dörfler /* 2d01879e5SAxel Dörfler * Copyright 2001-2008, 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> 86a0a0a80SAxel Dörfler * Axel Dörfler, axeld@pinc-software.de 9b09e2f6fSStephan Aßmus * Andrej Spielmann, <andrej.spielmann@seh.ox.ac.uk> 106a0a0a80SAxel Dörfler */ 1127adb969SAxel Dörfler #ifndef DESKTOP_H 1227adb969SAxel Dörfler #define DESKTOP_H 1333bbe223SAxel Dörfler 1408f35604SAxel Dörfler 153ddebe7eSMichael Lotz #include "CursorManager.h" 16ace2d5eeSStephan Aßmus #include "DesktopSettings.h" 1708f35604SAxel Dörfler #include "EventDispatcher.h" 18ace2d5eeSStephan Aßmus #include "MessageLooper.h" 19953d895eSAxel Dörfler #include "Screen.h" 20fd5bec1eSAxel Dörfler #include "ScreenManager.h" 21ace2d5eeSStephan Aßmus #include "ServerCursor.h" 22fd5bec1eSAxel Dörfler #include "VirtualScreen.h" 23e83820edSAxel Dörfler #include "WindowList.h" 2427adb969SAxel Dörfler #include "Workspace.h" 255ca8477eSAxel Dörfler #include "WorkspacePrivate.h" 26fd5bec1eSAxel Dörfler 27e83820edSAxel Dörfler #include <ObjectList.h> 28e83820edSAxel Dörfler 29e83820edSAxel Dörfler #include <Autolock.h> 3033bbe223SAxel Dörfler #include <InterfaceDefs.h> 313dcb3b07SStephan Aßmus #include <List.h> 323dcb3b07SStephan Aßmus #include <Menu.h> 33e83820edSAxel Dörfler #include <Region.h> 3457be2866SAxel Dörfler #include <Window.h> 356a0a0a80SAxel Dörfler 3639c9925fSStephan Aßmus #define USE_MULTI_LOCKER 1 37e83820edSAxel Dörfler 38e83820edSAxel Dörfler #if USE_MULTI_LOCKER 39e83820edSAxel Dörfler # include "MultiLocker.h" 40e83820edSAxel Dörfler #else 41e83820edSAxel Dörfler # include <Locker.h> 42e83820edSAxel Dörfler #endif 4333bbe223SAxel Dörfler 443dcb3b07SStephan Aßmus class BMessage; 456a0a0a80SAxel Dörfler 4658468dfeSStephan Aßmus class DrawingEngine; 473dcb3b07SStephan Aßmus class HWInterface; 48e83820edSAxel Dörfler class ServerApp; 49953d895eSAxel Dörfler class Window; 50953d895eSAxel Dörfler class WorkspacesView; 516d5488e1SAxel Dörfler struct server_read_only_memory; 5233bbe223SAxel Dörfler 536a0a0a80SAxel Dörfler namespace BPrivate { 546a0a0a80SAxel Dörfler class LinkSender; 556a0a0a80SAxel Dörfler }; 566a0a0a80SAxel Dörfler 575f2edc0fSAxel Dörfler class Desktop : public MessageLooper, public ScreenOwner { 5833bbe223SAxel Dörfler public: 5936deda69SAxel Dörfler Desktop(uid_t userID); 603dcb3b07SStephan Aßmus virtual ~Desktop(); 613dcb3b07SStephan Aßmus 626d5488e1SAxel Dörfler status_t Init(); 6336deda69SAxel Dörfler 6436deda69SAxel Dörfler uid_t UserID() const { return fUserID; } 65770c05d6SAxel Dörfler virtual port_id MessagePort() const { return fMessagePort; } 669dbce7a4SAxel Dörfler area_id SharedReadOnlyArea() const 679dbce7a4SAxel Dörfler { return fSharedReadOnlyArea; } 68770c05d6SAxel Dörfler 69f7598223SAxel Dörfler ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 706c17d025SAxel Dörfler 71770c05d6SAxel Dörfler void BroadcastToAllApps(int32 code); 720a3f410fSAxel Dörfler void BroadcastToAllWindows(int32 code); 7333bbe223SAxel Dörfler 7427adb969SAxel Dörfler // Screen and drawing related methods 7527adb969SAxel Dörfler 7627adb969SAxel Dörfler Screen* ScreenAt(int32 index) const 77fd5bec1eSAxel Dörfler { return fActiveScreen; } 7827adb969SAxel Dörfler Screen* ActiveScreen() const 7994fa2bd2SAdi Oanca { return fActiveScreen; } 80e83820edSAxel Dörfler 8127adb969SAxel Dörfler CursorManager& GetCursorManager() { return fCursorManager; } 8233bbe223SAxel Dörfler 83195e980eSAxel Dörfler void SetCursor(ServerCursor* cursor); 84ace2d5eeSStephan Aßmus ServerCursorReference Cursor() const; 854d1c4228SStephan Aßmus void SetLastMouseState(const BPoint& position, 8621b40eddSStephan Aßmus int32 buttons, Window* windowUnderMouse); 874d1c4228SStephan Aßmus // for use by the mouse filter only 884d1c4228SStephan Aßmus // both mouse position calls require 894d1c4228SStephan Aßmus // the Desktop object to be locked 904d1c4228SStephan Aßmus // already 914d1c4228SStephan Aßmus void GetLastMouseState(BPoint* position, 924d1c4228SStephan Aßmus int32* buttons) const; 934d1c4228SStephan Aßmus // for use by ServerWindow 948527f8ffSAxel Dörfler void ScreenChanged(Screen* screen, bool makeDefault); 9527adb969SAxel Dörfler void ScreenRemoved(Screen* screen) {} 9627adb969SAxel Dörfler void ScreenAdded(Screen* screen) {} 9727adb969SAxel Dörfler bool ReleaseScreen(Screen* screen) { return false; } 98*27c43a2dSRene Gollent status_t StoreConfiguration(int32 workspace); 993dcb3b07SStephan Aßmus 100fd5bec1eSAxel Dörfler const ::VirtualScreen& VirtualScreen() const { return fVirtualScreen; } 10127adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 10258468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 10327adb969SAxel Dörfler ::HWInterface* HWInterface() const 104fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 10594fa2bd2SAdi Oanca 10627adb969SAxel Dörfler // Workspace methods 10727adb969SAxel Dörfler 1084d1c4228SStephan Aßmus void SetWorkspaceAsync(int32 index); 10927adb969SAxel Dörfler void SetWorkspace(int32 index); 11027adb969SAxel Dörfler int32 CurrentWorkspace() 11127adb969SAxel Dörfler { return fCurrentWorkspace; } 1125ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 11327adb969SAxel Dörfler { return fWorkspaces[index]; } 114a17c3a48SAxel Dörfler status_t SetWorkspacesCount(int32 newCount); 115*27c43a2dSRene Gollent BRect WorkspaceFrame(int32 index) const; 11627adb969SAxel Dörfler 117953d895eSAxel Dörfler // Window methods 11827adb969SAxel Dörfler 119953d895eSAxel Dörfler void ActivateWindow(Window* window); 120953d895eSAxel Dörfler void SendWindowBehind(Window* window, 121953d895eSAxel Dörfler Window* behindOf = NULL); 12227adb969SAxel Dörfler 123953d895eSAxel Dörfler void ShowWindow(Window* window); 124953d895eSAxel Dörfler void HideWindow(Window* window); 12515918e4fSAxel Dörfler 126953d895eSAxel Dörfler void MoveWindowBy(Window* window, float x, float y, 12714fe11cfSAxel Dörfler int32 workspace = -1); 1289dbce7a4SAxel Dörfler void ResizeWindowBy(Window* window, float x, 1299dbce7a4SAxel Dörfler float y); 1309dbce7a4SAxel Dörfler bool SetWindowTabLocation(Window* window, 1319dbce7a4SAxel Dörfler float location); 132953d895eSAxel Dörfler bool SetWindowDecoratorSettings(Window* window, 133b30e9021SStephan Aßmus const BMessage& settings); 13419d801a6SAxel Dörfler 135953d895eSAxel Dörfler void SetWindowWorkspaces(Window* window, 136a631158aSAxel Dörfler uint32 workspaces); 13727adb969SAxel Dörfler 138953d895eSAxel Dörfler void AddWindow(Window* window); 139953d895eSAxel Dörfler void RemoveWindow(Window* window); 14057be2866SAxel Dörfler 141953d895eSAxel Dörfler bool AddWindowToSubset(Window* subset, 142953d895eSAxel Dörfler Window* window); 143953d895eSAxel Dörfler void RemoveWindowFromSubset(Window* subset, 144953d895eSAxel Dörfler Window* window); 14534227d2cSAxel Dörfler 1460a3f410fSAxel Dörfler void FontsChanged(Window* window); 1470a3f410fSAxel Dörfler 148953d895eSAxel Dörfler void SetWindowLook(Window* window, window_look look); 149953d895eSAxel Dörfler void SetWindowFeel(Window* window, window_feel feel); 150953d895eSAxel Dörfler void SetWindowFlags(Window* window, uint32 flags); 1519dbce7a4SAxel Dörfler void SetWindowTitle(Window* window, 1529dbce7a4SAxel Dörfler const char* title); 15333bbe223SAxel Dörfler 154953d895eSAxel Dörfler Window* FocusWindow() const { return fFocus; } 155953d895eSAxel Dörfler Window* FrontWindow() const { return fFront; } 156953d895eSAxel Dörfler Window* BackWindow() const { return fBack; } 157e83820edSAxel Dörfler 158953d895eSAxel Dörfler Window* WindowAt(BPoint where); 159e83820edSAxel Dörfler 1609dbce7a4SAxel Dörfler Window* MouseEventWindow() const 1619dbce7a4SAxel Dörfler { return fMouseEventWindow; } 162953d895eSAxel Dörfler void SetMouseEventWindow(Window* window); 163e83820edSAxel Dörfler 1649dbce7a4SAxel Dörfler void SetViewUnderMouse(const Window* window, 1659dbce7a4SAxel Dörfler int32 viewToken); 166953d895eSAxel Dörfler int32 ViewUnderMouse(const Window* window); 1671e766d46SAxel Dörfler 168953d895eSAxel Dörfler void SetFocusWindow(Window* window = NULL); 16907dc2c69SAxel Dörfler EventTarget* KeyboardEventTarget(); 17021b40eddSStephan Aßmus void SetFocusLocked(const Window* window); 171e83820edSAxel Dörfler 172953d895eSAxel Dörfler Window* FindWindowByClientToken(int32 token, 173953d895eSAxel Dörfler team_id teamID); 17495530739SAxel Dörfler EventTarget* FindTarget(BMessenger& messenger); 1756a0a0a80SAxel Dörfler 176e83820edSAxel Dörfler #if USE_MULTI_LOCKER 1779dbce7a4SAxel Dörfler bool LockSingleWindow() 1789dbce7a4SAxel Dörfler { return fWindowLock.ReadLock(); } 1799dbce7a4SAxel Dörfler void UnlockSingleWindow() 1809dbce7a4SAxel Dörfler { fWindowLock.ReadUnlock(); } 181e83820edSAxel Dörfler 1829dbce7a4SAxel Dörfler bool LockAllWindows() 1839dbce7a4SAxel Dörfler { return fWindowLock.WriteLock(); } 1849dbce7a4SAxel Dörfler void UnlockAllWindows() 1859dbce7a4SAxel Dörfler { fWindowLock.WriteUnlock(); } 186e83820edSAxel Dörfler #else // USE_MULTI_LOCKER 1879dbce7a4SAxel Dörfler bool LockSingleWindow() 1889dbce7a4SAxel Dörfler { return fWindowLock.Lock(); } 1899dbce7a4SAxel Dörfler void UnlockSingleWindow() 1909dbce7a4SAxel Dörfler { fWindowLock.Unlock(); } 191e83820edSAxel Dörfler 1929dbce7a4SAxel Dörfler bool LockAllWindows() 1939dbce7a4SAxel Dörfler { return fWindowLock.Lock(); } 1949dbce7a4SAxel Dörfler void UnlockAllWindows() 1959dbce7a4SAxel Dörfler { fWindowLock.Unlock(); } 196e83820edSAxel Dörfler #endif // USE_MULTI_LOCKER 197e83820edSAxel Dörfler 198e83820edSAxel Dörfler void MarkDirty(BRegion& region); 199b09e2f6fSStephan Aßmus void Redraw(); 200e83820edSAxel Dörfler 201e83820edSAxel Dörfler BRegion& BackgroundRegion() 202e83820edSAxel Dörfler { return fBackgroundRegion; } 20333bbe223SAxel Dörfler 2043dcbe9fcSAxel Dörfler void RedrawBackground(); 20582081c70SJérôme Duval void StoreWorkspaceConfiguration(int32 index); 2063dcbe9fcSAxel Dörfler 207953d895eSAxel Dörfler void AddWorkspacesView(WorkspacesView* view); 208953d895eSAxel Dörfler void RemoveWorkspacesView(WorkspacesView* view); 2092c184b20SAxel Dörfler 210f877af82SAxel Dörfler void MinimizeApplication(team_id team); 211f877af82SAxel Dörfler void BringApplicationToFront(team_id team); 212bfe69873SAxel Dörfler void WindowAction(int32 windowToken, int32 action); 213f877af82SAxel Dörfler 21427adb969SAxel Dörfler void WriteWindowList(team_id team, 21527adb969SAxel Dörfler BPrivate::LinkSender& sender); 21627adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 21727adb969SAxel Dörfler BPrivate::LinkSender& sender); 218ae0606beSAxel Dörfler void WriteApplicationOrder(int32 workspace, 219ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 220ae0606beSAxel Dörfler void WriteWindowOrder(int32 workspace, 221ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 22233bbe223SAxel Dörfler 22333bbe223SAxel Dörfler private: 2246869c8a5SRyan Leavengood void _LaunchInputServer(); 225a17c3a48SAxel Dörfler void _SetWorkspace(int32 index); 226953d895eSAxel Dörfler void _ShowWindow(Window* window, 227e83820edSAxel Dörfler bool affectsOtherWindows = true); 228953d895eSAxel Dörfler void _HideWindow(Window* window); 229e83820edSAxel Dörfler 230953d895eSAxel Dörfler void _UpdateSubsetWorkspaces(Window* window, 23164747950SAxel Dörfler int32 previousIndex = -1, 23264747950SAxel Dörfler int32 newIndex = -1); 233953d895eSAxel Dörfler void _ChangeWindowWorkspaces(Window* window, 234a631158aSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 235e83820edSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 236e83820edSAxel Dörfler int32 list, bool wereVisible); 237d0283566SAxel Dörfler Window* _LastFocusSubsetWindow(Window* window); 23836deda69SAxel Dörfler status_t _ActivateApp(team_id team); 239953d895eSAxel Dörfler void _SendFakeMouseMoved(Window* window = NULL); 240e83820edSAxel Dörfler 2419dbce7a4SAxel Dörfler void _RebuildClippingForAllWindows( 2429dbce7a4SAxel Dörfler BRegion& stillAvailableOnScreen); 2439dbce7a4SAxel Dörfler void _TriggerWindowRedrawing( 2449dbce7a4SAxel Dörfler BRegion& newDirtyRegion); 245e83820edSAxel Dörfler void _SetBackground(BRegion& background); 2460a3f410fSAxel Dörfler void _RebuildAndRedrawAfterWindowChange( 2470a3f410fSAxel Dörfler Window* window, BRegion& dirty); 248e83820edSAxel Dörfler 24934227d2cSAxel Dörfler void _UpdateFloating(int32 previousWorkspace = -1, 250d479fa7aSAxel Dörfler int32 nextWorkspace = -1, 251953d895eSAxel Dörfler Window* mouseEventWindow = NULL); 252e83820edSAxel Dörfler void _UpdateBack(); 25334227d2cSAxel Dörfler void _UpdateFront(bool updateFloating = true); 25434227d2cSAxel Dörfler void _UpdateFronts(bool updateFloating = true); 255953d895eSAxel Dörfler bool _WindowHasModal(Window* window); 256e83820edSAxel Dörfler 257953d895eSAxel Dörfler void _WindowChanged(Window* window); 258953d895eSAxel Dörfler void _WindowRemoved(Window* window); 259ce8c4d79SAxel Dörfler 26027adb969SAxel Dörfler void _GetLooperName(char* name, size_t size); 26127adb969SAxel Dörfler void _PrepareQuit(); 26227adb969SAxel Dörfler void _DispatchMessage(int32 code, 26327adb969SAxel Dörfler BPrivate::LinkReceiver &link); 2645f2edc0fSAxel Dörfler 265e83820edSAxel Dörfler WindowList& _CurrentWindows(); 26634227d2cSAxel Dörfler WindowList& _Windows(int32 index); 267e83820edSAxel Dörfler 2685f2edc0fSAxel Dörfler private: 269ef8810f2SAxel Dörfler friend class DesktopSettings; 270a17c3a48SAxel Dörfler friend class LockedDesktopSettings; 271ef8810f2SAxel Dörfler 27236deda69SAxel Dörfler uid_t fUserID; 273fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 274a17c3a48SAxel Dörfler DesktopSettingsPrivate* fSettings; 2755f2edc0fSAxel Dörfler port_id fMessagePort; 276f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 2776c17d025SAxel Dörfler port_id fInputPort; 2786d5488e1SAxel Dörfler area_id fSharedReadOnlyArea; 2796d5488e1SAxel Dörfler server_read_only_memory* fServerReadOnlyMemory; 280770c05d6SAxel Dörfler 281e83820edSAxel Dörfler BLocker fApplicationsLock; 282e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 283770c05d6SAxel Dörfler 284770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 285770c05d6SAxel Dörfler int32 fShutdownCount; 286770c05d6SAxel Dörfler 28782081c70SJérôme Duval ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 28827adb969SAxel Dörfler int32 fCurrentWorkspace; 2894932bc5eSAxel Dörfler int32 fPreviousWorkspace; 29027adb969SAxel Dörfler 291e83820edSAxel Dörfler WindowList fAllWindows; 29234227d2cSAxel Dörfler WindowList fSubsetWindows; 293d01879e5SAxel Dörfler WindowList fFocusList; 294d8ebe612SAxel Dörfler 295953d895eSAxel Dörfler BObjectList<WorkspacesView> fWorkspacesViews; 296d8ebe612SAxel Dörfler BLocker fWorkspacesLock; 29733bbe223SAxel Dörfler 29833bbe223SAxel Dörfler Screen* fActiveScreen; 2993ddebe7eSMichael Lotz 3003ddebe7eSMichael Lotz CursorManager fCursorManager; 301e83820edSAxel Dörfler 302e83820edSAxel Dörfler #if USE_MULTI_LOCKER 303e83820edSAxel Dörfler MultiLocker fWindowLock; 304e83820edSAxel Dörfler #else 305e83820edSAxel Dörfler BLocker fWindowLock; 306e83820edSAxel Dörfler #endif 307e83820edSAxel Dörfler 308e83820edSAxel Dörfler BRegion fBackgroundRegion; 309e83820edSAxel Dörfler BRegion fScreenRegion; 310e83820edSAxel Dörfler 311953d895eSAxel Dörfler Window* fMouseEventWindow; 312953d895eSAxel Dörfler const Window* fWindowUnderMouse; 31321b40eddSStephan Aßmus const Window* fLockedFocusWindow; 3141e766d46SAxel Dörfler int32 fViewUnderMouse; 3154d1c4228SStephan Aßmus BPoint fLastMousePosition; 3164d1c4228SStephan Aßmus int32 fLastMouseButtons; 3171e766d46SAxel Dörfler 318953d895eSAxel Dörfler Window* fFocus; 319953d895eSAxel Dörfler Window* fFront; 320953d895eSAxel Dörfler Window* fBack; 32133bbe223SAxel Dörfler }; 32233bbe223SAxel Dörfler 32327adb969SAxel Dörfler #endif // DESKTOP_H 324