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