Revised named configurations a bit:
* Named settings are only overwritten if they were an exact match (ie. it's the very same monitor). * The unnamed settings retrieval now has two passes, on the first it will now ignore named settings. It will also only remove unnamed settings now. * Added some TODO commments. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22632 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -140,7 +140,7 @@ VirtualScreen::AddScreen(Screen* screen)
|
|||||||
|
|
||||||
status_t status = B_ERROR;
|
status_t status = B_ERROR;
|
||||||
BMessage settings;
|
BMessage settings;
|
||||||
if (_FindConfiguration(screen, settings) == B_OK) {
|
if (_GetConfiguration(screen, settings) == B_OK) {
|
||||||
// we found settings for this screen, and try to apply them now
|
// we found settings for this screen, and try to apply them now
|
||||||
int32 width, height, colorSpace;
|
int32 width, height, colorSpace;
|
||||||
const display_timing* timing;
|
const display_timing* timing;
|
||||||
@@ -152,6 +152,7 @@ VirtualScreen::AddScreen(Screen* screen)
|
|||||||
&size) == B_OK
|
&size) == B_OK
|
||||||
&& size == sizeof(display_timing))
|
&& size == sizeof(display_timing))
|
||||||
status = screen->SetMode(width, height, colorSpace, *timing, true);
|
status = screen->SetMode(width, height, colorSpace, *timing, true);
|
||||||
|
// TODO: named settings will get lost if setting the mode failed!
|
||||||
}
|
}
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
// TODO: more intelligent standard mode (monitor preference, desktop default, ...)
|
// TODO: more intelligent standard mode (monitor preference, desktop default, ...)
|
||||||
@@ -240,32 +241,39 @@ VirtualScreen::CountScreens() const
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
VirtualScreen::_FindConfiguration(Screen* screen, BMessage& settings)
|
VirtualScreen::_GetConfiguration(Screen* screen, BMessage& settings)
|
||||||
{
|
{
|
||||||
monitor_info info;
|
monitor_info info;
|
||||||
bool hasInfo = screen->GetMonitorInfo(info) == B_OK;
|
bool hasInfo = screen->GetMonitorInfo(info) == B_OK;
|
||||||
if (!hasInfo) {
|
if (!hasInfo) {
|
||||||
// only look for a matching ID - this is all we have
|
// only look for a matching ID - this is all we have
|
||||||
|
for (uint32 k = 0; k < 2; k++) {
|
||||||
for (uint32 i = 0; fSettings.FindMessage("screen", i,
|
for (uint32 i = 0; fSettings.FindMessage("screen", i,
|
||||||
&settings) == B_OK; i++) {
|
&settings) == B_OK; i++) {
|
||||||
int32 id;
|
int32 id;
|
||||||
if (settings.FindInt32("id", &id) != B_OK
|
if (k == 0 && settings.HasString("name")
|
||||||
|
|| settings.FindInt32("id", &id) != B_OK
|
||||||
|| screen->ID() != id)
|
|| screen->ID() != id)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// we found our match
|
// we found our match, only remove unnamed settings
|
||||||
|
if (k == 0)
|
||||||
fSettings.RemoveData("screen", i);
|
fSettings.RemoveData("screen", i);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return B_NAME_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
// look for a monitor configuration that matches ours
|
// look for a monitor configuration that matches ours
|
||||||
|
|
||||||
|
bool exactMatch = false;
|
||||||
int32 bestScore = 0;
|
int32 bestScore = 0;
|
||||||
int32 bestIndex = -1;
|
int32 bestIndex = -1;
|
||||||
BMessage stored;
|
BMessage stored;
|
||||||
for (uint32 i = 0; fSettings.FindMessage("screen", i, &stored) == B_OK;
|
for (uint32 i = 0; fSettings.FindMessage("screen", i, &stored) == B_OK;
|
||||||
i++) {
|
i++) {
|
||||||
|
// TODO: should we ignore unnamed settings here completely?
|
||||||
int32 score = 0;
|
int32 score = 0;
|
||||||
int32 id;
|
int32 id;
|
||||||
if (stored.FindInt32("id", &id) == B_OK && screen->ID() == id)
|
if (stored.FindInt32("id", &id) == B_OK && screen->ID() == id)
|
||||||
@@ -286,8 +294,10 @@ VirtualScreen::_FindConfiguration(Screen* screen, BMessage& settings)
|
|||||||
&& !strcasecmp(name, info.name)
|
&& !strcasecmp(name, info.name)
|
||||||
&& productID == info.product_id) {
|
&& productID == info.product_id) {
|
||||||
score += 2;
|
score += 2;
|
||||||
if (!strcmp(serial, info.serial_number))
|
if (!strcmp(serial, info.serial_number)) {
|
||||||
|
exactMatch = true;
|
||||||
score += 2;
|
score += 2;
|
||||||
|
}
|
||||||
if (info.produced.year == year && info.produced.week == week)
|
if (info.produced.year == year && info.produced.week == week)
|
||||||
score++;
|
score++;
|
||||||
} else
|
} else
|
||||||
@@ -302,6 +312,7 @@ VirtualScreen::_FindConfiguration(Screen* screen, BMessage& settings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bestIndex >= 0) {
|
if (bestIndex >= 0) {
|
||||||
|
if (exactMatch)
|
||||||
fSettings.RemoveData("screen", bestIndex);
|
fSettings.RemoveData("screen", bestIndex);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class VirtualScreen {
|
|||||||
int32 CountScreens() const;
|
int32 CountScreens() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _FindConfiguration(Screen* screen,
|
status_t _GetConfiguration(Screen* screen,
|
||||||
BMessage& settings);
|
BMessage& settings);
|
||||||
void _Reset();
|
void _Reset();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user