1 /* 2 * Copyright 2005, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 10 #include "VirtualScreen.h" 11 12 #include "HWInterface.h" 13 #include "Desktop.h" 14 15 #include <new> 16 17 using std::nothrow; 18 19 20 VirtualScreen::VirtualScreen() 21 : 22 fScreenList(4, true), 23 fDrawingEngine(NULL), 24 fHWInterface(NULL) 25 { 26 } 27 28 29 VirtualScreen::~VirtualScreen() 30 { 31 _Reset(); 32 } 33 34 35 void 36 VirtualScreen::_Reset() 37 { 38 ScreenList list; 39 for (int32 i = 0; i < fScreenList.CountItems(); i++) { 40 screen_item* item = fScreenList.ItemAt(i); 41 42 list.AddItem(item->screen); 43 } 44 45 gScreenManager->ReleaseScreens(list); 46 fScreenList.MakeEmpty(); 47 fSettings.MakeEmpty(); 48 49 fFrame.Set(0, 0, 0, 0); 50 fDrawingEngine = NULL; 51 fHWInterface = NULL; 52 } 53 54 55 status_t 56 VirtualScreen::RestoreConfiguration(Desktop& desktop, const BMessage* settings) 57 { 58 _Reset(); 59 60 // Copy current Desktop workspace settings 61 if (settings) 62 fSettings = *settings; 63 64 ScreenList list; 65 status_t status = gScreenManager->AcquireScreens(&desktop, NULL, 0, false, list); 66 if (status < B_OK) { 67 // TODO: we would try again here with force == true 68 return status; 69 } 70 71 for (int32 i = 0; i < list.CountItems(); i++) { 72 Screen* screen = list.ItemAt(i); 73 74 AddScreen(screen); 75 } 76 77 return B_OK; 78 } 79 80 81 status_t 82 VirtualScreen::StoreConfiguration(BMessage& settings) 83 { 84 // TODO: implement me 85 return B_OK; 86 } 87 88 89 status_t 90 VirtualScreen::AddScreen(Screen* screen) 91 { 92 screen_item* item = new(nothrow) screen_item; 93 if (item == NULL) 94 return B_NO_MEMORY; 95 96 item->screen = screen; 97 98 BMessage settings; 99 if (_FindConfiguration(screen, settings) == B_OK) { 100 // TODO: read from settings! 101 } else { 102 // TODO: more intelligent standard mode (monitor preference, desktop default, ...) 103 screen->SetMode(800, 600, B_RGB32, 60.f); 104 } 105 106 // TODO: this works only for single screen configurations 107 fDrawingEngine = screen->GetDrawingEngine(); 108 fHWInterface = screen->HWInterface(); 109 fFrame = screen->Frame(); 110 111 fScreenList.AddItem(item); 112 113 return B_OK; 114 } 115 116 117 status_t 118 VirtualScreen::RemoveScreen(Screen* screen) 119 { 120 // not implemented yet (config changes when running) 121 return B_ERROR; 122 } 123 124 125 /*! 126 Returns the smallest frame that spans over all screens 127 */ 128 BRect 129 VirtualScreen::Frame() const 130 { 131 return fFrame; 132 } 133 134 135 Screen* 136 VirtualScreen::ScreenAt(int32 index) const 137 { 138 screen_item* item = fScreenList.ItemAt(index); 139 if (item != NULL) 140 return item->screen; 141 142 return NULL; 143 } 144 145 146 BRect 147 VirtualScreen::ScreenFrameAt(int32 index) const 148 { 149 screen_item* item = fScreenList.ItemAt(index); 150 if (item != NULL) 151 return item->frame; 152 153 return BRect(0, 0, 0, 0); 154 } 155 156 157 int32 158 VirtualScreen::CountScreens() const 159 { 160 return fScreenList.CountItems(); 161 } 162 163 164 status_t 165 VirtualScreen::_FindConfiguration(Screen* screen, BMessage& settings) 166 { 167 // TODO: we probably want to identify the resolution by connected monitor, 168 // and not the display driver used... 169 return B_ERROR; 170 } 171 172