1 /* 2 * Copyright 2001-2010, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Adrian Oanca <adioanca@cotty.iren.ro> 7 * Stephan Aßmus <superstippi@gmx.de> 8 * Axel Dörfler <axeld@pinc-software.de> 9 * Andrej Spielmann, <andrej.spielmann@seh.ox.ac.uk> 10 * Brecht Machiels <brecht@mos6581.org> 11 * Clemens Zeidler <haiku@clemens-zeidler.de> 12 */ 13 #ifndef DESKTOP_H 14 #define DESKTOP_H 15 16 17 #include <Autolock.h> 18 #include <InterfaceDefs.h> 19 #include <List.h> 20 #include <Menu.h> 21 #include <ObjectList.h> 22 #include <Region.h> 23 #include <Window.h> 24 25 #include "CursorManager.h" 26 #include "DesktopListener.h" 27 #include "DesktopSettings.h" 28 #include "EventDispatcher.h" 29 #include "MessageLooper.h" 30 #include "MultiLocker.h" 31 #include "Screen.h" 32 #include "ScreenManager.h" 33 #include "ServerCursor.h" 34 #include "VirtualScreen.h" 35 #include "WindowList.h" 36 #include "Workspace.h" 37 #include "WorkspacePrivate.h" 38 39 40 class BMessage; 41 42 class DrawingEngine; 43 class HWInterface; 44 class ServerApp; 45 class Window; 46 class WorkspacesView; 47 struct server_read_only_memory; 48 49 namespace BPrivate { 50 class LinkSender; 51 }; 52 53 54 class Desktop : public DesktopObservable, public MessageLooper, 55 public ScreenOwner { 56 public: 57 Desktop(uid_t userID, const char* targetScreen); 58 virtual ~Desktop(); 59 60 void RegisterListener(DesktopListener* listener); 61 62 status_t Init(); 63 64 uid_t UserID() const { return fUserID; } 65 const char* TargetScreen() { return fTargetScreen; } 66 virtual port_id MessagePort() const { return fMessagePort; } 67 area_id SharedReadOnlyArea() const 68 { return fSharedReadOnlyArea; } 69 70 ::EventDispatcher& EventDispatcher() { return fEventDispatcher; } 71 72 void BroadcastToAllApps(int32 code); 73 void BroadcastToAllWindows(int32 code); 74 75 filter_result KeyEvent(uint32 what, int32 key, 76 int32 modifiers); 77 // Locking 78 bool LockSingleWindow() 79 { return fWindowLock.ReadLock(); } 80 void UnlockSingleWindow() 81 { fWindowLock.ReadUnlock(); } 82 83 bool LockAllWindows() 84 { return fWindowLock.WriteLock(); } 85 void UnlockAllWindows() 86 { fWindowLock.WriteUnlock(); } 87 88 const MultiLocker& WindowLocker() { return fWindowLock; } 89 90 // Mouse and cursor methods 91 92 void SetCursor(ServerCursor* cursor); 93 ServerCursorReference Cursor() const; 94 void SetManagementCursor(ServerCursor* newCursor); 95 96 void SetLastMouseState(const BPoint& position, 97 int32 buttons, Window* windowUnderMouse); 98 // for use by the mouse filter only 99 // both mouse position calls require 100 // the Desktop object to be locked 101 // already 102 void GetLastMouseState(BPoint* position, 103 int32* buttons) const; 104 // for use by ServerWindow 105 106 CursorManager& GetCursorManager() { return fCursorManager; } 107 108 // Screen and drawing related methods 109 110 status_t SetScreenMode(int32 workspace, int32 id, 111 const display_mode& mode, bool makeDefault); 112 status_t GetScreenMode(int32 workspace, int32 id, 113 display_mode& mode); 114 status_t GetScreenFrame(int32 workspace, int32 id, 115 BRect& frame); 116 void RevertScreenModes(uint32 workspaces); 117 118 MultiLocker& ScreenLocker() { return fScreenLock; } 119 120 status_t LockDirectScreen(team_id team); 121 status_t UnlockDirectScreen(team_id team); 122 123 const ::VirtualScreen& VirtualScreen() const 124 { return fVirtualScreen; } 125 DrawingEngine* GetDrawingEngine() const 126 { return fVirtualScreen.DrawingEngine(); } 127 ::HWInterface* HWInterface() const 128 { return fVirtualScreen.HWInterface(); } 129 130 void RebuildAndRedrawAfterWindowChange( 131 Window* window, BRegion& dirty); 132 // the window lock must be held when calling 133 // this function 134 135 // ScreenOwner implementation 136 virtual void ScreenRemoved(Screen* screen) {} 137 virtual void ScreenAdded(Screen* screen) {} 138 virtual bool ReleaseScreen(Screen* screen) { return false; } 139 140 // Workspace methods 141 142 void SetWorkspaceAsync(int32 index, 143 bool moveFocusWindow = false); 144 void SetWorkspace(int32 index, 145 bool moveFocusWindow = false); 146 int32 CurrentWorkspace() 147 { return fCurrentWorkspace; } 148 Workspace::Private& WorkspaceAt(int32 index) 149 { return fWorkspaces[index]; } 150 status_t SetWorkspacesLayout(int32 columns, int32 rows); 151 BRect WorkspaceFrame(int32 index) const; 152 153 void StoreWorkspaceConfiguration(int32 index); 154 155 void AddWorkspacesView(WorkspacesView* view); 156 void RemoveWorkspacesView(WorkspacesView* view); 157 158 // Window methods 159 160 void SelectWindow(Window* window); 161 void ActivateWindow(Window* window); 162 void SendWindowBehind(Window* window, 163 Window* behindOf = NULL); 164 165 void ShowWindow(Window* window); 166 void HideWindow(Window* window); 167 void MinimizeWindow(Window* window, bool minimize); 168 169 void MoveWindowBy(Window* window, float x, float y, 170 int32 workspace = -1); 171 void ResizeWindowBy(Window* window, float x, 172 float y); 173 bool SetWindowTabLocation(Window* window, 174 float location); 175 bool SetWindowDecoratorSettings(Window* window, 176 const BMessage& settings); 177 178 void SetWindowWorkspaces(Window* window, 179 uint32 workspaces); 180 181 void AddWindow(Window* window); 182 void RemoveWindow(Window* window); 183 184 bool AddWindowToSubset(Window* subset, 185 Window* window); 186 void RemoveWindowFromSubset(Window* subset, 187 Window* window); 188 189 void FontsChanged(Window* window); 190 191 void SetWindowLook(Window* window, window_look look); 192 void SetWindowFeel(Window* window, window_feel feel); 193 void SetWindowFlags(Window* window, uint32 flags); 194 void SetWindowTitle(Window* window, 195 const char* title); 196 197 Window* FocusWindow() const { return fFocus; } 198 Window* FrontWindow() const { return fFront; } 199 Window* BackWindow() const { return fBack; } 200 201 Window* WindowAt(BPoint where); 202 203 Window* MouseEventWindow() const 204 { return fMouseEventWindow; } 205 void SetMouseEventWindow(Window* window); 206 207 void SetViewUnderMouse(const Window* window, 208 int32 viewToken); 209 int32 ViewUnderMouse(const Window* window); 210 211 EventTarget* KeyboardEventTarget(); 212 213 void SetFocusWindow(Window* window = NULL); 214 void SetFocusLocked(const Window* window); 215 216 Window* FindWindowByClientToken(int32 token, 217 team_id teamID); 218 EventTarget* FindTarget(BMessenger& messenger); 219 220 void MarkDirty(BRegion& region); 221 void Redraw(); 222 void RedrawBackground(); 223 224 bool ReloadDecor(); 225 226 BRegion& BackgroundRegion() 227 { return fBackgroundRegion; } 228 229 void MinimizeApplication(team_id team); 230 void BringApplicationToFront(team_id team); 231 void WindowAction(int32 windowToken, int32 action); 232 233 void WriteWindowList(team_id team, 234 BPrivate::LinkSender& sender); 235 void WriteWindowInfo(int32 serverToken, 236 BPrivate::LinkSender& sender); 237 void WriteApplicationOrder(int32 workspace, 238 BPrivate::LinkSender& sender); 239 void WriteWindowOrder(int32 workspace, 240 BPrivate::LinkSender& sender); 241 242 //! The window lock must be held when accessing a window list! 243 WindowList& CurrentWindows(); 244 WindowList& AllWindows(); 245 246 Window* WindowForClientLooperPort(port_id port); 247 248 private: 249 WindowList& _Windows(int32 index); 250 251 void _LaunchInputServer(); 252 void _GetLooperName(char* name, size_t size); 253 void _PrepareQuit(); 254 void _DispatchMessage(int32 code, 255 BPrivate::LinkReceiver &link); 256 257 void _UpdateFloating(int32 previousWorkspace = -1, 258 int32 nextWorkspace = -1, 259 Window* mouseEventWindow = NULL); 260 void _UpdateBack(); 261 void _UpdateFront(bool updateFloating = true); 262 void _UpdateFronts(bool updateFloating = true); 263 bool _WindowHasModal(Window* window); 264 265 void _WindowChanged(Window* window); 266 void _WindowRemoved(Window* window); 267 268 void _ShowWindow(Window* window, 269 bool affectsOtherWindows = true); 270 void _HideWindow(Window* window); 271 272 void _UpdateSubsetWorkspaces(Window* window, 273 int32 previousIndex = -1, 274 int32 newIndex = -1); 275 void _ChangeWindowWorkspaces(Window* window, 276 uint32 oldWorkspaces, uint32 newWorkspaces); 277 void _BringWindowsToFront(WindowList& windows, 278 int32 list, bool wereVisible); 279 Window* _LastFocusSubsetWindow(Window* window); 280 void _SendFakeMouseMoved(Window* window = NULL); 281 282 Screen* _DetermineScreenFor(BRect frame); 283 void _RebuildClippingForAllWindows( 284 BRegion& stillAvailableOnScreen); 285 void _TriggerWindowRedrawing( 286 BRegion& newDirtyRegion); 287 void _SetBackground(BRegion& background); 288 289 status_t _ActivateApp(team_id team); 290 291 void _SuspendDirectFrameBufferAccess(); 292 void _ResumeDirectFrameBufferAccess(); 293 294 void _ScreenChanged(Screen* screen); 295 void _SetCurrentWorkspaceConfiguration(); 296 void _SetWorkspace(int32 index, 297 bool moveFocusWindow = false); 298 299 private: 300 friend class DesktopSettings; 301 friend class LockedDesktopSettings; 302 303 uid_t fUserID; 304 char* fTargetScreen; 305 ::VirtualScreen fVirtualScreen; 306 DesktopSettingsPrivate* fSettings; 307 port_id fMessagePort; 308 ::EventDispatcher fEventDispatcher; 309 area_id fSharedReadOnlyArea; 310 server_read_only_memory* fServerReadOnlyMemory; 311 312 BLocker fApplicationsLock; 313 BObjectList<ServerApp> fApplications; 314 315 sem_id fShutdownSemaphore; 316 int32 fShutdownCount; 317 318 ::Workspace::Private fWorkspaces[kMaxWorkspaces]; 319 MultiLocker fScreenLock; 320 BLocker fDirectScreenLock; 321 team_id fDirectScreenTeam; 322 int32 fCurrentWorkspace; 323 int32 fPreviousWorkspace; 324 325 WindowList fAllWindows; 326 WindowList fSubsetWindows; 327 WindowList fFocusList; 328 Window* fLastWorkspaceFocus[kMaxWorkspaces]; 329 330 BObjectList<WorkspacesView> fWorkspacesViews; 331 BLocker fWorkspacesLock; 332 333 CursorManager fCursorManager; 334 ServerCursorReference fCursor; 335 ServerCursorReference fManagementCursor; 336 337 MultiLocker fWindowLock; 338 339 BRegion fBackgroundRegion; 340 BRegion fScreenRegion; 341 342 Window* fMouseEventWindow; 343 const Window* fWindowUnderMouse; 344 const Window* fLockedFocusWindow; 345 int32 fViewUnderMouse; 346 BPoint fLastMousePosition; 347 int32 fLastMouseButtons; 348 349 Window* fFocus; 350 Window* fFront; 351 Window* fBack; 352 }; 353 354 #endif // DESKTOP_H 355