2005-07-15 16:45:23 +04:00
|
|
|
/*
|
2006-02-06 16:36:46 +03:00
|
|
|
* Copyright 2005-2006, Haiku.
|
2005-07-15 16:45:23 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "VirtualScreen.h"
|
|
|
|
|
2005-10-29 20:27:43 +04:00
|
|
|
#include "HWInterface.h"
|
|
|
|
#include "Desktop.h"
|
2005-07-15 16:45:23 +04:00
|
|
|
|
|
|
|
#include <new>
|
|
|
|
|
2005-11-13 02:27:14 +03:00
|
|
|
using std::nothrow;
|
|
|
|
|
2005-07-15 16:45:23 +04:00
|
|
|
|
|
|
|
VirtualScreen::VirtualScreen()
|
|
|
|
:
|
|
|
|
fScreenList(4, true),
|
2005-11-04 18:23:54 +03:00
|
|
|
fDrawingEngine(NULL),
|
2005-07-15 16:45:23 +04:00
|
|
|
fHWInterface(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VirtualScreen::~VirtualScreen()
|
|
|
|
{
|
2005-07-17 20:25:48 +04:00
|
|
|
_Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
VirtualScreen::_Reset()
|
|
|
|
{
|
|
|
|
ScreenList list;
|
|
|
|
for (int32 i = 0; i < fScreenList.CountItems(); i++) {
|
|
|
|
screen_item* item = fScreenList.ItemAt(i);
|
|
|
|
|
|
|
|
list.AddItem(item->screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
gScreenManager->ReleaseScreens(list);
|
|
|
|
fScreenList.MakeEmpty();
|
|
|
|
fSettings.MakeEmpty();
|
|
|
|
|
|
|
|
fFrame.Set(0, 0, 0, 0);
|
2005-11-04 18:23:54 +03:00
|
|
|
fDrawingEngine = NULL;
|
2005-07-17 20:25:48 +04:00
|
|
|
fHWInterface = NULL;
|
2005-07-15 16:45:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
2005-07-17 20:25:48 +04:00
|
|
|
VirtualScreen::RestoreConfiguration(Desktop& desktop, const BMessage* settings)
|
2005-07-15 16:45:23 +04:00
|
|
|
{
|
2005-07-17 20:25:48 +04:00
|
|
|
_Reset();
|
|
|
|
|
|
|
|
// Copy current Desktop workspace settings
|
|
|
|
if (settings)
|
|
|
|
fSettings = *settings;
|
2005-07-15 16:45:23 +04:00
|
|
|
|
|
|
|
ScreenList list;
|
|
|
|
status_t status = gScreenManager->AcquireScreens(&desktop, NULL, 0, false, list);
|
|
|
|
if (status < B_OK) {
|
|
|
|
// TODO: we would try again here with force == true
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int32 i = 0; i < list.CountItems(); i++) {
|
|
|
|
Screen* screen = list.ItemAt(i);
|
|
|
|
|
|
|
|
AddScreen(screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
VirtualScreen::StoreConfiguration(BMessage& settings)
|
|
|
|
{
|
2006-02-06 16:36:46 +03:00
|
|
|
for (int32 i = 0; i < fScreenList.CountItems(); i++) {
|
|
|
|
screen_item* item = fScreenList.ItemAt(i);
|
|
|
|
Screen* screen = item->screen;
|
|
|
|
if (!screen->IsDefaultMode())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BMessage screenSettings;
|
|
|
|
screenSettings.AddInt32("id", screen->ID());
|
|
|
|
//screenSettings.AddString("name", "-");
|
|
|
|
screenSettings.AddRect("frame", item->frame);
|
|
|
|
|
|
|
|
// TODO: or just store a display_mode completely?
|
|
|
|
uint16 width, height;
|
|
|
|
uint32 colorSpace;
|
|
|
|
float frequency;
|
|
|
|
screen->GetMode(width, height, colorSpace, frequency);
|
|
|
|
|
|
|
|
screenSettings.AddInt32("width", width);
|
|
|
|
screenSettings.AddInt32("height", height);
|
|
|
|
screenSettings.AddInt32("color space", colorSpace);
|
|
|
|
screenSettings.AddFloat("frequency", frequency);
|
|
|
|
|
|
|
|
settings.AddMessage("screen", &screenSettings);
|
|
|
|
}
|
|
|
|
|
2005-07-15 16:45:23 +04:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
VirtualScreen::AddScreen(Screen* screen)
|
|
|
|
{
|
|
|
|
screen_item* item = new(nothrow) screen_item;
|
|
|
|
if (item == NULL)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
|
|
|
|
item->screen = screen;
|
|
|
|
|
2006-02-06 16:36:46 +03:00
|
|
|
status_t status = B_ERROR;
|
2005-07-15 16:45:23 +04:00
|
|
|
BMessage settings;
|
|
|
|
if (_FindConfiguration(screen, settings) == B_OK) {
|
2006-02-06 16:36:46 +03:00
|
|
|
// we found settings for this screen, and try to apply them now
|
|
|
|
int32 width, height, colorSpace;
|
|
|
|
float frequency;
|
|
|
|
if (settings.FindInt32("width", &width) == B_OK
|
|
|
|
&& settings.FindInt32("height", &height) == B_OK
|
|
|
|
&& settings.FindInt32("color space", &colorSpace) == B_OK
|
|
|
|
&& settings.FindFloat("frequency", &frequency) == B_OK)
|
|
|
|
status = screen->SetMode(width, height, colorSpace, frequency, true);
|
|
|
|
}
|
|
|
|
if (status < B_OK) {
|
2005-07-15 16:45:23 +04:00
|
|
|
// TODO: more intelligent standard mode (monitor preference, desktop default, ...)
|
2006-02-06 16:36:46 +03:00
|
|
|
screen->SetMode(800, 600, B_RGB32, 60.f, false);
|
2005-07-15 16:45:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: this works only for single screen configurations
|
2005-11-04 18:23:54 +03:00
|
|
|
fDrawingEngine = screen->GetDrawingEngine();
|
2005-11-18 15:26:20 +03:00
|
|
|
fHWInterface = screen->HWInterface();
|
2005-07-15 16:45:23 +04:00
|
|
|
fFrame = screen->Frame();
|
|
|
|
|
|
|
|
fScreenList.AddItem(item);
|
|
|
|
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
VirtualScreen::RemoveScreen(Screen* screen)
|
|
|
|
{
|
|
|
|
// not implemented yet (config changes when running)
|
|
|
|
return B_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the smallest frame that spans over all screens
|
|
|
|
*/
|
|
|
|
BRect
|
|
|
|
VirtualScreen::Frame() const
|
|
|
|
{
|
|
|
|
return fFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Screen*
|
|
|
|
VirtualScreen::ScreenAt(int32 index) const
|
|
|
|
{
|
|
|
|
screen_item* item = fScreenList.ItemAt(index);
|
|
|
|
if (item != NULL)
|
|
|
|
return item->screen;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BRect
|
|
|
|
VirtualScreen::ScreenFrameAt(int32 index) const
|
|
|
|
{
|
|
|
|
screen_item* item = fScreenList.ItemAt(index);
|
|
|
|
if (item != NULL)
|
|
|
|
return item->frame;
|
|
|
|
|
|
|
|
return BRect(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32
|
|
|
|
VirtualScreen::CountScreens() const
|
|
|
|
{
|
|
|
|
return fScreenList.CountItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
VirtualScreen::_FindConfiguration(Screen* screen, BMessage& settings)
|
|
|
|
{
|
|
|
|
// TODO: we probably want to identify the resolution by connected monitor,
|
|
|
|
// and not the display driver used...
|
2006-02-06 16:36:46 +03:00
|
|
|
// For now, we just use the screen ID, which is almost nothing, anyway...
|
|
|
|
|
|
|
|
uint32 i = 0;
|
|
|
|
while (fSettings.FindMessage("screen", i++, &settings) == B_OK) {
|
|
|
|
int32 id;
|
|
|
|
if (settings.FindInt32("id", &id) != B_OK
|
|
|
|
|| screen->ID() != id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// we found our match
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return B_NAME_NOT_FOUND;
|
2005-07-15 16:45:23 +04:00
|
|
|
}
|
|
|
|
|