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 96a0a0a80SAxel Dörfler */ 1027adb969SAxel Dörfler #ifndef DESKTOP_H 1127adb969SAxel Dörfler #define DESKTOP_H 1233bbe223SAxel Dörfler 1308f35604SAxel Dörfler 143ddebe7eSMichael Lotz #include "CursorManager.h" 1508f35604SAxel Dörfler #include "EventDispatcher.h" 16953d895eSAxel Dörfler #include "Screen.h" 17fd5bec1eSAxel Dörfler #include "ScreenManager.h" 18fd5bec1eSAxel Dörfler #include "VirtualScreen.h" 19ef8810f2SAxel Dörfler #include "DesktopSettings.h" 205f2edc0fSAxel Dörfler #include "MessageLooper.h" 21e83820edSAxel Dörfler #include "WindowList.h" 2227adb969SAxel Dörfler #include "Workspace.h" 235ca8477eSAxel Dörfler #include "WorkspacePrivate.h" 24fd5bec1eSAxel Dörfler 25e83820edSAxel Dörfler #include <ObjectList.h> 26e83820edSAxel Dörfler 27e83820edSAxel Dörfler #include <Autolock.h> 2833bbe223SAxel Dörfler #include <InterfaceDefs.h> 293dcb3b07SStephan Aßmus #include <List.h> 303dcb3b07SStephan Aßmus #include <Menu.h> 31e83820edSAxel Dörfler #include <Region.h> 3257be2866SAxel Dörfler #include <Window.h> 336a0a0a80SAxel Dörfler 3439c9925fSStephan Aßmus #define USE_MULTI_LOCKER 1 35e83820edSAxel Dörfler 36e83820edSAxel Dörfler #if USE_MULTI_LOCKER 37e83820edSAxel Dörfler # include "MultiLocker.h" 38e83820edSAxel Dörfler #else 39e83820edSAxel Dörfler # include <Locker.h> 40e83820edSAxel Dörfler #endif 4133bbe223SAxel Dörfler 423dcb3b07SStephan Aßmus class BMessage; 436a0a0a80SAxel Dörfler 4458468dfeSStephan Aßmus class DrawingEngine; 453dcb3b07SStephan Aßmus class HWInterface; 46e83820edSAxel Dörfler class ServerApp; 47953d895eSAxel Dörfler class Window; 48953d895eSAxel Dörfler class WorkspacesView; 496d5488e1SAxel Dörfler struct server_read_only_memory; 5033bbe223SAxel Dörfler 516a0a0a80SAxel Dörfler namespace BPrivate { 526a0a0a80SAxel Dörfler class LinkSender; 536a0a0a80SAxel Dörfler }; 546a0a0a80SAxel Dörfler 555f2edc0fSAxel Dörfler class Desktop : public MessageLooper, public ScreenOwner { 5633bbe223SAxel Dörfler public: 5736deda69SAxel Dörfler Desktop(uid_t userID); 583dcb3b07SStephan Aßmus virtual ~Desktop(); 593dcb3b07SStephan Aßmus 606d5488e1SAxel Dörfler status_t Init(); 6136deda69SAxel Dörfler 6236deda69SAxel Dörfler uid_t UserID() const { return fUserID; } 63770c05d6SAxel Dörfler virtual port_id MessagePort() const { return fMessagePort; } 646d5488e1SAxel Dörfler area_id SharedReadOnlyArea() const { return fSharedReadOnlyArea; } 65770c05d6SAxel Dörfler 66f7598223SAxel Dörfler ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 676c17d025SAxel Dörfler 68770c05d6SAxel Dörfler void BroadcastToAllApps(int32 code); 6933bbe223SAxel Dörfler 7027adb969SAxel Dörfler // Screen and drawing related methods 7127adb969SAxel Dörfler 7227adb969SAxel Dörfler Screen* ScreenAt(int32 index) const 73fd5bec1eSAxel Dörfler { return fActiveScreen; } 7427adb969SAxel Dörfler Screen* ActiveScreen() const 7594fa2bd2SAdi Oanca { return fActiveScreen; } 76e83820edSAxel Dörfler 7727adb969SAxel Dörfler CursorManager& GetCursorManager() { return fCursorManager; } 7833bbe223SAxel Dörfler 79195e980eSAxel Dörfler void SetCursor(ServerCursor* cursor); 80195e980eSAxel Dörfler ServerCursor* Cursor() const; 814d1c4228SStephan Aßmus void SetLastMouseState(const BPoint& position, 824d1c4228SStephan Aßmus int32 buttons); 834d1c4228SStephan Aßmus // for use by the mouse filter only 844d1c4228SStephan Aßmus // both mouse position calls require 854d1c4228SStephan Aßmus // the Desktop object to be locked 864d1c4228SStephan Aßmus // already 874d1c4228SStephan Aßmus void GetLastMouseState(BPoint* position, 884d1c4228SStephan Aßmus int32* buttons) const; 894d1c4228SStephan Aßmus // for use by ServerWindow 90195e980eSAxel Dörfler 918527f8ffSAxel Dörfler void ScreenChanged(Screen* screen, bool makeDefault); 92df362433SAxel Dörfler 9327adb969SAxel Dörfler void ScreenRemoved(Screen* screen) {} 9427adb969SAxel Dörfler void ScreenAdded(Screen* screen) {} 9527adb969SAxel Dörfler bool ReleaseScreen(Screen* screen) { return false; } 963dcb3b07SStephan Aßmus 97fd5bec1eSAxel Dörfler const ::VirtualScreen& VirtualScreen() const { return fVirtualScreen; } 9827adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 9958468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 10027adb969SAxel Dörfler ::HWInterface* HWInterface() const 101fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 10294fa2bd2SAdi Oanca 10327adb969SAxel Dörfler // Workspace methods 10427adb969SAxel Dörfler 1054d1c4228SStephan Aßmus void SetWorkspaceAsync(int32 index); 10627adb969SAxel Dörfler void SetWorkspace(int32 index); 10727adb969SAxel Dörfler int32 CurrentWorkspace() 10827adb969SAxel Dörfler { return fCurrentWorkspace; } 1095ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 11027adb969SAxel Dörfler { return fWorkspaces[index]; } 111a17c3a48SAxel Dörfler status_t SetWorkspacesCount(int32 newCount); 11227adb969SAxel Dörfler 113953d895eSAxel Dörfler // Window methods 11427adb969SAxel Dörfler 115953d895eSAxel Dörfler void ActivateWindow(Window* window); 116953d895eSAxel Dörfler void SendWindowBehind(Window* window, 117953d895eSAxel Dörfler Window* behindOf = NULL); 11827adb969SAxel Dörfler 119953d895eSAxel Dörfler void ShowWindow(Window* window); 120953d895eSAxel Dörfler void HideWindow(Window* window); 12115918e4fSAxel Dörfler 122953d895eSAxel Dörfler void MoveWindowBy(Window* window, float x, float y, 12314fe11cfSAxel Dörfler int32 workspace = -1); 124953d895eSAxel Dörfler void ResizeWindowBy(Window* window, float x, float y); 125953d895eSAxel Dörfler bool SetWindowTabLocation(Window* window, float location); 126953d895eSAxel Dörfler bool SetWindowDecoratorSettings(Window* window, 127b30e9021SStephan Aßmus const BMessage& settings); 12819d801a6SAxel Dörfler 129953d895eSAxel Dörfler void SetWindowWorkspaces(Window* window, 130a631158aSAxel Dörfler uint32 workspaces); 13127adb969SAxel Dörfler 132953d895eSAxel Dörfler void AddWindow(Window* window); 133953d895eSAxel Dörfler void RemoveWindow(Window* window); 13457be2866SAxel Dörfler 135953d895eSAxel Dörfler bool AddWindowToSubset(Window* subset, 136953d895eSAxel Dörfler Window* window); 137953d895eSAxel Dörfler void RemoveWindowFromSubset(Window* subset, 138953d895eSAxel Dörfler Window* window); 13934227d2cSAxel Dörfler 140953d895eSAxel Dörfler void SetWindowLook(Window* window, window_look look); 141953d895eSAxel Dörfler void SetWindowFeel(Window* window, window_feel feel); 142953d895eSAxel Dörfler void SetWindowFlags(Window* window, uint32 flags); 143953d895eSAxel Dörfler void SetWindowTitle(Window* window, const char* title); 14433bbe223SAxel Dörfler 145953d895eSAxel Dörfler Window* FocusWindow() const { return fFocus; } 146953d895eSAxel Dörfler Window* FrontWindow() const { return fFront; } 147953d895eSAxel Dörfler Window* BackWindow() const { return fBack; } 148e83820edSAxel Dörfler 149953d895eSAxel Dörfler Window* WindowAt(BPoint where); 150e83820edSAxel Dörfler 151953d895eSAxel Dörfler Window* MouseEventWindow() const { return fMouseEventWindow; } 152953d895eSAxel Dörfler void SetMouseEventWindow(Window* window); 153e83820edSAxel Dörfler 154953d895eSAxel Dörfler void SetViewUnderMouse(const Window* window, int32 viewToken); 155953d895eSAxel Dörfler int32 ViewUnderMouse(const Window* window); 1561e766d46SAxel Dörfler 157953d895eSAxel Dörfler void SetFocusWindow(Window* window = NULL); 15807dc2c69SAxel Dörfler EventTarget* KeyboardEventTarget(); 159e83820edSAxel Dörfler 160953d895eSAxel Dörfler Window* FindWindowByClientToken(int32 token, 161953d895eSAxel Dörfler team_id teamID); 1626a0a0a80SAxel Dörfler 163e83820edSAxel Dörfler #if USE_MULTI_LOCKER 16461fed21bSAxel Dörfler bool LockSingleWindow() { return fWindowLock.ReadLock(); } 16561fed21bSAxel Dörfler void UnlockSingleWindow() { fWindowLock.ReadUnlock(); } 166e83820edSAxel Dörfler 16761fed21bSAxel Dörfler bool LockAllWindows() { return fWindowLock.WriteLock(); } 16861fed21bSAxel Dörfler void UnlockAllWindows() { fWindowLock.WriteUnlock(); } 169e83820edSAxel Dörfler #else // USE_MULTI_LOCKER 17061fed21bSAxel Dörfler bool LockSingleWindow() { return fWindowLock.Lock(); } 17161fed21bSAxel Dörfler void UnlockSingleWindow() { fWindowLock.Unlock(); } 172e83820edSAxel Dörfler 17361fed21bSAxel Dörfler bool LockAllWindows() { return fWindowLock.Lock(); } 17461fed21bSAxel Dörfler void UnlockAllWindows() { fWindowLock.Unlock(); } 175e83820edSAxel Dörfler #endif // USE_MULTI_LOCKER 176e83820edSAxel Dörfler 177e83820edSAxel Dörfler void MarkDirty(BRegion& region); 178e83820edSAxel Dörfler 179e83820edSAxel Dörfler BRegion& BackgroundRegion() 180e83820edSAxel Dörfler { return fBackgroundRegion; } 18133bbe223SAxel Dörfler 1823dcbe9fcSAxel Dörfler void RedrawBackground(); 18382081c70SJérôme Duval void StoreWorkspaceConfiguration(int32 index); 1843dcbe9fcSAxel Dörfler 185953d895eSAxel Dörfler void AddWorkspacesView(WorkspacesView* view); 186953d895eSAxel Dörfler void RemoveWorkspacesView(WorkspacesView* view); 1872c184b20SAxel Dörfler 188f877af82SAxel Dörfler void MinimizeApplication(team_id team); 189f877af82SAxel Dörfler void BringApplicationToFront(team_id team); 190bfe69873SAxel Dörfler void WindowAction(int32 windowToken, int32 action); 191f877af82SAxel Dörfler 19227adb969SAxel Dörfler void WriteWindowList(team_id team, 19327adb969SAxel Dörfler BPrivate::LinkSender& sender); 19427adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 19527adb969SAxel Dörfler BPrivate::LinkSender& sender); 19633bbe223SAxel Dörfler 19733bbe223SAxel Dörfler private: 1986869c8a5SRyan Leavengood void _LaunchInputServer(); 199a17c3a48SAxel Dörfler void _SetWorkspace(int32 index); 200953d895eSAxel Dörfler void _ShowWindow(Window* window, 201e83820edSAxel Dörfler bool affectsOtherWindows = true); 202953d895eSAxel Dörfler void _HideWindow(Window* window); 203e83820edSAxel Dörfler 204953d895eSAxel Dörfler void _UpdateSubsetWorkspaces(Window* window, 20564747950SAxel Dörfler int32 previousIndex = -1, 20664747950SAxel Dörfler int32 newIndex = -1); 207953d895eSAxel Dörfler void _ChangeWindowWorkspaces(Window* window, 208a631158aSAxel Dörfler uint32 oldWorkspaces, uint32 newWorkspaces); 209e83820edSAxel Dörfler void _BringWindowsToFront(WindowList& windows, 210e83820edSAxel Dörfler int32 list, bool wereVisible); 21136deda69SAxel Dörfler status_t _ActivateApp(team_id team); 212953d895eSAxel Dörfler void _SendFakeMouseMoved(Window* window = NULL); 213e83820edSAxel Dörfler 214e83820edSAxel Dörfler void _RebuildClippingForAllWindows(BRegion& stillAvailableOnScreen); 215e83820edSAxel Dörfler void _TriggerWindowRedrawing(BRegion& newDirtyRegion); 216e83820edSAxel Dörfler void _SetBackground(BRegion& background); 217e83820edSAxel Dörfler 21834227d2cSAxel Dörfler void _UpdateFloating(int32 previousWorkspace = -1, 219d479fa7aSAxel Dörfler int32 nextWorkspace = -1, 220953d895eSAxel Dörfler Window* mouseEventWindow = NULL); 221e83820edSAxel Dörfler void _UpdateBack(); 22234227d2cSAxel Dörfler void _UpdateFront(bool updateFloating = true); 22334227d2cSAxel Dörfler void _UpdateFronts(bool updateFloating = true); 224953d895eSAxel Dörfler bool _WindowHasModal(Window* window); 225e83820edSAxel Dörfler 226953d895eSAxel Dörfler void _WindowChanged(Window* window); 227953d895eSAxel Dörfler void _WindowRemoved(Window* window); 228ce8c4d79SAxel Dörfler 22927adb969SAxel Dörfler void _GetLooperName(char* name, size_t size); 23027adb969SAxel Dörfler void _PrepareQuit(); 23127adb969SAxel Dörfler void _DispatchMessage(int32 code, 23227adb969SAxel Dörfler BPrivate::LinkReceiver &link); 2335f2edc0fSAxel Dörfler 234e83820edSAxel Dörfler WindowList& _CurrentWindows(); 23534227d2cSAxel Dörfler WindowList& _Windows(int32 index); 236e83820edSAxel Dörfler 2375f2edc0fSAxel Dörfler private: 238ef8810f2SAxel Dörfler friend class DesktopSettings; 239a17c3a48SAxel Dörfler friend class LockedDesktopSettings; 240ef8810f2SAxel Dörfler 24136deda69SAxel Dörfler uid_t fUserID; 242fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 243a17c3a48SAxel Dörfler DesktopSettingsPrivate* fSettings; 2445f2edc0fSAxel Dörfler port_id fMessagePort; 245f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 2466c17d025SAxel Dörfler port_id fInputPort; 2476d5488e1SAxel Dörfler area_id fSharedReadOnlyArea; 2486d5488e1SAxel Dörfler server_read_only_memory* fServerReadOnlyMemory; 249770c05d6SAxel Dörfler 250e83820edSAxel Dörfler BLocker fApplicationsLock; 251e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 252770c05d6SAxel Dörfler 253770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 254770c05d6SAxel Dörfler int32 fShutdownCount; 255770c05d6SAxel Dörfler 25682081c70SJérôme Duval ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 25727adb969SAxel Dörfler int32 fCurrentWorkspace; 25827adb969SAxel Dörfler 259e83820edSAxel Dörfler WindowList fAllWindows; 26034227d2cSAxel Dörfler WindowList fSubsetWindows; 261d01879e5SAxel Dörfler WindowList fFocusList; 262*d8ebe612SAxel Dörfler 263953d895eSAxel Dörfler BObjectList<WorkspacesView> fWorkspacesViews; 264*d8ebe612SAxel Dörfler BLocker fWorkspacesLock; 26533bbe223SAxel Dörfler 26633bbe223SAxel Dörfler Screen* fActiveScreen; 2673ddebe7eSMichael Lotz 2683ddebe7eSMichael Lotz CursorManager fCursorManager; 269e83820edSAxel Dörfler 270e83820edSAxel Dörfler #if USE_MULTI_LOCKER 271e83820edSAxel Dörfler MultiLocker fWindowLock; 272e83820edSAxel Dörfler #else 273e83820edSAxel Dörfler BLocker fWindowLock; 274e83820edSAxel Dörfler #endif 275e83820edSAxel Dörfler 276e83820edSAxel Dörfler BRegion fBackgroundRegion; 277e83820edSAxel Dörfler BRegion fScreenRegion; 278e83820edSAxel Dörfler 279953d895eSAxel Dörfler Window* fMouseEventWindow; 280953d895eSAxel Dörfler const Window* fWindowUnderMouse; 2811e766d46SAxel Dörfler int32 fViewUnderMouse; 2824d1c4228SStephan Aßmus BPoint fLastMousePosition; 2834d1c4228SStephan Aßmus int32 fLastMouseButtons; 2841e766d46SAxel Dörfler 285953d895eSAxel Dörfler Window* fFocus; 286953d895eSAxel Dörfler Window* fFront; 287953d895eSAxel Dörfler Window* fBack; 28833bbe223SAxel Dörfler }; 28933bbe223SAxel Dörfler 29027adb969SAxel Dörfler #endif // DESKTOP_H 291