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 37*ef831a1dSPhilippe Houdoin #include "LinearSpec.h" 380eed9183SAxel Dörfler 3939c9925fSStephan Aßmus #define USE_MULTI_LOCKER 1 40e83820edSAxel Dörfler 41e83820edSAxel Dörfler #if USE_MULTI_LOCKER 42e83820edSAxel Dörfler # include "MultiLocker.h" 43e83820edSAxel Dörfler #else 44e83820edSAxel Dörfler # include <Locker.h> 45e83820edSAxel Dörfler #endif 4633bbe223SAxel Dörfler 470eed9183SAxel Dörfler 483dcb3b07SStephan Aßmus class BMessage; 496a0a0a80SAxel Dörfler 5058468dfeSStephan Aßmus class DrawingEngine; 513dcb3b07SStephan Aßmus class HWInterface; 52e83820edSAxel Dörfler class ServerApp; 53953d895eSAxel Dörfler class Window; 54953d895eSAxel Dörfler class WorkspacesView; 556d5488e1SAxel Dörfler struct server_read_only_memory; 5633bbe223SAxel Dörfler 576a0a0a80SAxel Dörfler namespace BPrivate { 586a0a0a80SAxel Dörfler class LinkSender; 596a0a0a80SAxel Dörfler }; 606a0a0a80SAxel Dörfler 610eed9183SAxel Dörfler 625f2edc0fSAxel Dörfler class Desktop : public MessageLooper, public ScreenOwner { 6333bbe223SAxel Dörfler public: 6468667bf4SMichael Lotz Desktop(uid_t userID, const char* targetScreen); 653dcb3b07SStephan Aßmus virtual ~Desktop(); 663dcb3b07SStephan Aßmus 676d5488e1SAxel Dörfler status_t Init(); 6836deda69SAxel Dörfler 6936deda69SAxel Dörfler uid_t UserID() const { return fUserID; } 7068667bf4SMichael Lotz const char* TargetScreen() { return fTargetScreen; } 71770c05d6SAxel Dörfler virtual port_id MessagePort() const { return fMessagePort; } 729dbce7a4SAxel Dörfler area_id SharedReadOnlyArea() const 739dbce7a4SAxel Dörfler { return fSharedReadOnlyArea; } 74770c05d6SAxel Dörfler 75f7598223SAxel Dörfler ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 766c17d025SAxel Dörfler 77770c05d6SAxel Dörfler void BroadcastToAllApps(int32 code); 780a3f410fSAxel Dörfler void BroadcastToAllWindows(int32 code); 7933bbe223SAxel Dörfler 80cc93fbbbSAxel Dörfler // Locking 81cc93fbbbSAxel Dörfler #if USE_MULTI_LOCKER 82cc93fbbbSAxel Dörfler bool LockSingleWindow() 83cc93fbbbSAxel Dörfler { return fWindowLock.ReadLock(); } 84cc93fbbbSAxel Dörfler void UnlockSingleWindow() 85cc93fbbbSAxel Dörfler { fWindowLock.ReadUnlock(); } 86cc93fbbbSAxel Dörfler 87cc93fbbbSAxel Dörfler bool LockAllWindows() 88cc93fbbbSAxel Dörfler { return fWindowLock.WriteLock(); } 89cc93fbbbSAxel Dörfler void UnlockAllWindows() 90cc93fbbbSAxel Dörfler { fWindowLock.WriteUnlock(); } 91cc93fbbbSAxel Dörfler 9278ca6157SAxel Dörfler const MultiLocker& WindowLocker() { return fWindowLock; } 93cc93fbbbSAxel Dörfler #else // USE_MULTI_LOCKER 94cc93fbbbSAxel Dörfler bool LockSingleWindow() 95cc93fbbbSAxel Dörfler { return fWindowLock.Lock(); } 96cc93fbbbSAxel Dörfler void UnlockSingleWindow() 97cc93fbbbSAxel Dörfler { fWindowLock.Unlock(); } 98cc93fbbbSAxel Dörfler 99cc93fbbbSAxel Dörfler bool LockAllWindows() 100cc93fbbbSAxel Dörfler { return fWindowLock.Lock(); } 101cc93fbbbSAxel Dörfler void UnlockAllWindows() 102cc93fbbbSAxel Dörfler { fWindowLock.Unlock(); } 103cc93fbbbSAxel Dörfler #endif // USE_MULTI_LOCKER 104cc93fbbbSAxel Dörfler 1050eed9183SAxel Dörfler // Mouse and cursor methods 10633bbe223SAxel Dörfler 107195e980eSAxel Dörfler void SetCursor(ServerCursor* cursor); 108ace2d5eeSStephan Aßmus ServerCursorReference Cursor() const; 1094d1c4228SStephan Aßmus void SetLastMouseState(const BPoint& position, 11021b40eddSStephan Aßmus int32 buttons, Window* windowUnderMouse); 1114d1c4228SStephan Aßmus // for use by the mouse filter only 1124d1c4228SStephan Aßmus // both mouse position calls require 1134d1c4228SStephan Aßmus // the Desktop object to be locked 1144d1c4228SStephan Aßmus // already 1154d1c4228SStephan Aßmus void GetLastMouseState(BPoint* position, 1164d1c4228SStephan Aßmus int32* buttons) const; 1174d1c4228SStephan Aßmus // for use by ServerWindow 1180eed9183SAxel Dörfler 1190eed9183SAxel Dörfler CursorManager& GetCursorManager() { return fCursorManager; } 1200eed9183SAxel Dörfler 121fe7f167dSAxel Dörfler // Screen and drawing related methods 122fe7f167dSAxel Dörfler 1230eed9183SAxel Dörfler status_t SetScreenMode(int32 workspace, int32 id, 1240eed9183SAxel Dörfler const display_mode& mode, bool makeDefault); 1250eed9183SAxel Dörfler status_t GetScreenMode(int32 workspace, int32 id, 1260eed9183SAxel Dörfler display_mode& mode); 127e18224cdSAxel Dörfler status_t GetScreenFrame(int32 workspace, int32 id, 128e18224cdSAxel Dörfler BRect& frame); 1295e3f4c41SAxel Dörfler void RevertScreenModes(uint32 workspaces); 1300eed9183SAxel Dörfler 13178ca6157SAxel Dörfler MultiLocker& ScreenLocker() { return fScreenLock; } 13278ca6157SAxel Dörfler 1339fe35223SAxel Dörfler status_t LockDirectScreen(team_id team); 1349fe35223SAxel Dörfler status_t UnlockDirectScreen(team_id team); 1359fe35223SAxel Dörfler 1365e3f4c41SAxel Dörfler const ::VirtualScreen& VirtualScreen() const 1375e3f4c41SAxel Dörfler { return fVirtualScreen; } 13827adb969SAxel Dörfler DrawingEngine* GetDrawingEngine() const 13958468dfeSStephan Aßmus { return fVirtualScreen.DrawingEngine(); } 14027adb969SAxel Dörfler ::HWInterface* HWInterface() const 141fd5bec1eSAxel Dörfler { return fVirtualScreen.HWInterface(); } 14294fa2bd2SAdi Oanca 1430eed9183SAxel Dörfler // ScreenOwner implementation 1445e3f4c41SAxel Dörfler virtual void ScreenRemoved(Screen* screen) {} 1455e3f4c41SAxel Dörfler virtual void ScreenAdded(Screen* screen) {} 1465e3f4c41SAxel Dörfler virtual bool ReleaseScreen(Screen* screen) { return false; } 1470eed9183SAxel Dörfler 14827adb969SAxel Dörfler // Workspace methods 14927adb969SAxel Dörfler 1504d1c4228SStephan Aßmus void SetWorkspaceAsync(int32 index); 15127adb969SAxel Dörfler void SetWorkspace(int32 index); 15227adb969SAxel Dörfler int32 CurrentWorkspace() 15327adb969SAxel Dörfler { return fCurrentWorkspace; } 1545ca8477eSAxel Dörfler Workspace::Private& WorkspaceAt(int32 index) 15527adb969SAxel Dörfler { return fWorkspaces[index]; } 15669f9a367SAxel Dörfler status_t SetWorkspacesLayout(int32 columns, int32 rows); 15727c43a2dSRene Gollent BRect WorkspaceFrame(int32 index) const; 15827adb969SAxel Dörfler 159cc93fbbbSAxel Dörfler void StoreWorkspaceConfiguration(int32 index); 160cc93fbbbSAxel Dörfler 161cc93fbbbSAxel Dörfler void AddWorkspacesView(WorkspacesView* view); 162cc93fbbbSAxel Dörfler void RemoveWorkspacesView(WorkspacesView* view); 163cc93fbbbSAxel Dörfler 164953d895eSAxel Dörfler // Window methods 16527adb969SAxel Dörfler 166926e63c8SBrecht Machiels void SelectWindow(Window* window); 167953d895eSAxel Dörfler void ActivateWindow(Window* window); 168953d895eSAxel Dörfler void SendWindowBehind(Window* window, 169953d895eSAxel Dörfler Window* behindOf = NULL); 17027adb969SAxel Dörfler 171953d895eSAxel Dörfler void ShowWindow(Window* window); 172953d895eSAxel Dörfler void HideWindow(Window* window); 17315918e4fSAxel Dörfler 174953d895eSAxel Dörfler void MoveWindowBy(Window* window, float x, float y, 17514fe11cfSAxel Dörfler int32 workspace = -1); 1769dbce7a4SAxel Dörfler void ResizeWindowBy(Window* window, float x, 1779dbce7a4SAxel Dörfler float y); 1789dbce7a4SAxel Dörfler bool SetWindowTabLocation(Window* window, 1799dbce7a4SAxel Dörfler float location); 180953d895eSAxel Dörfler bool SetWindowDecoratorSettings(Window* window, 181b30e9021SStephan Aßmus const BMessage& settings); 18219d801a6SAxel Dörfler 183953d895eSAxel Dörfler void SetWindowWorkspaces(Window* window, 184a631158aSAxel Dörfler uint32 workspaces); 18527adb969SAxel Dörfler 186953d895eSAxel Dörfler void AddWindow(Window* window); 187953d895eSAxel Dörfler void RemoveWindow(Window* window); 18857be2866SAxel Dörfler 189953d895eSAxel Dörfler bool AddWindowToSubset(Window* subset, 190953d895eSAxel Dörfler Window* window); 191953d895eSAxel Dörfler void RemoveWindowFromSubset(Window* subset, 192953d895eSAxel Dörfler Window* window); 19334227d2cSAxel Dörfler 1940a3f410fSAxel Dörfler void FontsChanged(Window* window); 1950a3f410fSAxel Dörfler 196953d895eSAxel Dörfler void SetWindowLook(Window* window, window_look look); 197953d895eSAxel Dörfler void SetWindowFeel(Window* window, window_feel feel); 198953d895eSAxel Dörfler void SetWindowFlags(Window* window, uint32 flags); 1999dbce7a4SAxel Dörfler void SetWindowTitle(Window* window, 2009dbce7a4SAxel Dörfler const char* title); 20133bbe223SAxel Dörfler 202953d895eSAxel Dörfler Window* FocusWindow() const { return fFocus; } 203953d895eSAxel Dörfler Window* FrontWindow() const { return fFront; } 204953d895eSAxel Dörfler Window* BackWindow() const { return fBack; } 205e83820edSAxel Dörfler 206953d895eSAxel Dörfler Window* WindowAt(BPoint where); 207e83820edSAxel Dörfler 2089dbce7a4SAxel Dörfler Window* MouseEventWindow() const 2099dbce7a4SAxel Dörfler { return fMouseEventWindow; } 210953d895eSAxel Dörfler void SetMouseEventWindow(Window* window); 211e83820edSAxel Dörfler 2129dbce7a4SAxel Dörfler void SetViewUnderMouse(const Window* window, 2139dbce7a4SAxel Dörfler int32 viewToken); 214953d895eSAxel Dörfler int32 ViewUnderMouse(const Window* window); 2151e766d46SAxel Dörfler 21607dc2c69SAxel Dörfler EventTarget* KeyboardEventTarget(); 217cc93fbbbSAxel Dörfler 218cc93fbbbSAxel Dörfler void SetFocusWindow(Window* window = NULL); 21921b40eddSStephan Aßmus void SetFocusLocked(const Window* window); 220e83820edSAxel Dörfler 221953d895eSAxel Dörfler Window* FindWindowByClientToken(int32 token, 222953d895eSAxel Dörfler team_id teamID); 22395530739SAxel Dörfler EventTarget* FindTarget(BMessenger& messenger); 2246a0a0a80SAxel Dörfler 225e83820edSAxel Dörfler void MarkDirty(BRegion& region); 226b09e2f6fSStephan Aßmus void Redraw(); 227cc93fbbbSAxel Dörfler void RedrawBackground(); 228e83820edSAxel Dörfler 229e83820edSAxel Dörfler BRegion& BackgroundRegion() 230e83820edSAxel Dörfler { return fBackgroundRegion; } 23133bbe223SAxel Dörfler 232f877af82SAxel Dörfler void MinimizeApplication(team_id team); 233f877af82SAxel Dörfler void BringApplicationToFront(team_id team); 234bfe69873SAxel Dörfler void WindowAction(int32 windowToken, int32 action); 235f877af82SAxel Dörfler 23627adb969SAxel Dörfler void WriteWindowList(team_id team, 23727adb969SAxel Dörfler BPrivate::LinkSender& sender); 23827adb969SAxel Dörfler void WriteWindowInfo(int32 serverToken, 23927adb969SAxel Dörfler BPrivate::LinkSender& sender); 240ae0606beSAxel Dörfler void WriteApplicationOrder(int32 workspace, 241ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 242ae0606beSAxel Dörfler void WriteWindowOrder(int32 workspace, 243ae0606beSAxel Dörfler BPrivate::LinkSender& sender); 24433bbe223SAxel Dörfler 245*ef831a1dSPhilippe Houdoin WindowList& GetWindows(); 246*ef831a1dSPhilippe Houdoin bool HighlightTab(Window* window, bool active); 247*ef831a1dSPhilippe Houdoin bool HighlightBorders(Window* window, bool active); 248*ef831a1dSPhilippe Houdoin void FinishStackingAndSnapping(); 249*ef831a1dSPhilippe Houdoin Window* FindWindow(int32 windowId); 250*ef831a1dSPhilippe Houdoin 251*ef831a1dSPhilippe Houdoin bool fIsStackingAndSnapping; 252*ef831a1dSPhilippe Houdoin LinearSpec* fStackAndTileSpec; 253*ef831a1dSPhilippe Houdoin 25433bbe223SAxel Dörfler private: 2556869c8a5SRyan Leavengood void _LaunchInputServer(); 256cc93fbbbSAxel Dörfler void _GetLooperName(char* name, size_t size); 257cc93fbbbSAxel Dörfler void _PrepareQuit(); 258cc93fbbbSAxel Dörfler void _DispatchMessage(int32 code, 259cc93fbbbSAxel Dörfler BPrivate::LinkReceiver &link); 260e83820edSAxel Dörfler 261cc93fbbbSAxel Dörfler WindowList& _CurrentWindows(); 262cc93fbbbSAxel Dörfler WindowList& _Windows(int32 index); 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(); 305cc93fbbbSAxel Dörfler void _SetWorkspace(int32 index); 306e83820edSAxel Dörfler 307*ef831a1dSPhilippe Houdoin bool _AddWindowsByIdsToList(BList* windowIdsToAdd, 308*ef831a1dSPhilippe Houdoin BList* windows); 309*ef831a1dSPhilippe Houdoin 3105f2edc0fSAxel Dörfler private: 311ef8810f2SAxel Dörfler friend class DesktopSettings; 312a17c3a48SAxel Dörfler friend class LockedDesktopSettings; 313ef8810f2SAxel Dörfler 31436deda69SAxel Dörfler uid_t fUserID; 31568667bf4SMichael Lotz const char* fTargetScreen; 316fd5bec1eSAxel Dörfler ::VirtualScreen fVirtualScreen; 317a17c3a48SAxel Dörfler DesktopSettingsPrivate* fSettings; 3185f2edc0fSAxel Dörfler port_id fMessagePort; 319f7598223SAxel Dörfler ::EventDispatcher fEventDispatcher; 3206c17d025SAxel Dörfler port_id fInputPort; 3216d5488e1SAxel Dörfler area_id fSharedReadOnlyArea; 3226d5488e1SAxel Dörfler server_read_only_memory* fServerReadOnlyMemory; 323770c05d6SAxel Dörfler 324e83820edSAxel Dörfler BLocker fApplicationsLock; 325e83820edSAxel Dörfler BObjectList<ServerApp> fApplications; 326770c05d6SAxel Dörfler 327770c05d6SAxel Dörfler sem_id fShutdownSemaphore; 328770c05d6SAxel Dörfler int32 fShutdownCount; 329770c05d6SAxel Dörfler 33082081c70SJérôme Duval ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 33178ca6157SAxel Dörfler MultiLocker fScreenLock; 3329fe35223SAxel Dörfler BLocker fDirectScreenLock; 3339fe35223SAxel Dörfler team_id fDirectScreenTeam; 33427adb969SAxel Dörfler int32 fCurrentWorkspace; 3354932bc5eSAxel Dörfler int32 fPreviousWorkspace; 33627adb969SAxel Dörfler 337e83820edSAxel Dörfler WindowList fAllWindows; 33834227d2cSAxel Dörfler WindowList fSubsetWindows; 339d01879e5SAxel Dörfler WindowList fFocusList; 340d8ebe612SAxel Dörfler 341953d895eSAxel Dörfler BObjectList<WorkspacesView> fWorkspacesViews; 342d8ebe612SAxel Dörfler BLocker fWorkspacesLock; 34333bbe223SAxel Dörfler 3443ddebe7eSMichael Lotz CursorManager fCursorManager; 345e83820edSAxel Dörfler 346e83820edSAxel Dörfler #if USE_MULTI_LOCKER 347e83820edSAxel Dörfler MultiLocker fWindowLock; 348e83820edSAxel Dörfler #else 349e83820edSAxel Dörfler BLocker fWindowLock; 350e83820edSAxel Dörfler #endif 351e83820edSAxel Dörfler 352e83820edSAxel Dörfler BRegion fBackgroundRegion; 353e83820edSAxel Dörfler BRegion fScreenRegion; 354e83820edSAxel Dörfler 355953d895eSAxel Dörfler Window* fMouseEventWindow; 356953d895eSAxel Dörfler const Window* fWindowUnderMouse; 35721b40eddSStephan Aßmus const Window* fLockedFocusWindow; 3581e766d46SAxel Dörfler int32 fViewUnderMouse; 3594d1c4228SStephan Aßmus BPoint fLastMousePosition; 3604d1c4228SStephan Aßmus int32 fLastMouseButtons; 3611e766d46SAxel Dörfler 362953d895eSAxel Dörfler Window* fFocus; 363953d895eSAxel Dörfler Window* fFront; 364953d895eSAxel Dörfler Window* fBack; 36533bbe223SAxel Dörfler }; 36633bbe223SAxel Dörfler 36727adb969SAxel Dörfler #endif // DESKTOP_H 368