| Index: monitor_reconfigure_main.cc
|
| diff --git a/monitor_reconfigure_main.cc b/monitor_reconfigure_main.cc
|
| index 4a8b0114911100ac47486c94bebc660b1c9efae5..7d96cfb8b9dbd1fce2eed23f64dec95131e8a118 100644
|
| --- a/monitor_reconfigure_main.cc
|
| +++ b/monitor_reconfigure_main.cc
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
|
| +// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -18,6 +18,8 @@ using std::vector;
|
|
|
| namespace monitor_reconfig {
|
|
|
| +static const char kLcdOutputName[] = "LVDS1";
|
| +
|
| MonitorReconfigureMain::MonitorReconfigureMain(Display* display,
|
| XRRScreenResources* screen_info)
|
| : display_(display),
|
| @@ -31,13 +33,38 @@ MonitorReconfigureMain::MonitorReconfigureMain(Display* display,
|
| DetermineOutputs();
|
| }
|
|
|
| +void MonitorReconfigureMain::Run() {
|
| + vector<ResolutionSelector::Mode> lcd_modes;
|
| + SortModesByResolution(*lcd_output_, &lcd_modes);
|
| + DCHECK(!lcd_modes.empty());
|
| +
|
| + vector<ResolutionSelector::Mode> external_modes;
|
| + if (IsExternalMonitorConnected()) {
|
| + SortModesByResolution(*external_output_, &external_modes);
|
| + DCHECK(!external_modes.empty());
|
| + }
|
| +
|
| + ResolutionSelector selector;
|
| + string lcd_resolution, external_resolution, screen_resolution;
|
| + CHECK(selector.FindBestResolutions(lcd_modes,
|
| + external_modes,
|
| + &lcd_resolution,
|
| + &external_resolution,
|
| + &screen_resolution));
|
| +
|
| + SetDeviceResolution(lcd_output_->name, lcd_resolution);
|
| + if (IsExternalMonitorConnected())
|
| + SetDeviceResolution(external_output_->name, external_resolution);
|
| + SetScreenResolution(screen_resolution);
|
| +}
|
| +
|
| void MonitorReconfigureMain::DetermineOutputs() {
|
| + CHECK(screen_info_->noutput > 1) << "Expected at least two outputs";
|
| XRROutputInfo* first_output =
|
| XRRGetOutputInfo(display_, screen_info_, screen_info_->outputs[0]);
|
| XRROutputInfo* second_output =
|
| XRRGetOutputInfo(display_, screen_info_, screen_info_->outputs[1]);
|
|
|
| - static const char* kLcdOutputName = "LVDS1";
|
| if (strcmp(first_output->name, kLcdOutputName) == 0) {
|
| lcd_output_ = first_output;
|
| external_output_ = second_output;
|
| @@ -64,67 +91,19 @@ bool MonitorReconfigureMain::IsExternalMonitorConnected() {
|
| }
|
|
|
| void MonitorReconfigureMain::SortModesByResolution(
|
| - const XRROutputInfo& output_info, vector<XRRModeInfo*>* modes_out) {
|
| + const XRROutputInfo& output_info,
|
| + vector<ResolutionSelector::Mode>* modes_out) {
|
| modes_out->clear();
|
| - for (int i = 0; i < output_info.nmode; ++i)
|
| - modes_out->push_back(mode_map_[output_info.modes[i]]);
|
| - sort(modes_out->begin(), modes_out->end(), ModeResolutionComparator());
|
| -}
|
|
|
| -bool MonitorReconfigureMain::FindBestResolutions(
|
| - string* lcd_resolution,
|
| - string* external_resolution,
|
| - string* screen_resolution) {
|
| - DCHECK(lcd_resolution);
|
| - DCHECK(external_resolution);
|
| - DCHECK(screen_resolution);
|
| -
|
| - vector<XRRModeInfo*> lcd_modes, external_modes;
|
| - SortModesByResolution(*lcd_output_, &lcd_modes);
|
| - SortModesByResolution(*external_output_, &external_modes);
|
| - DCHECK(!lcd_modes.empty());
|
| - DCHECK(!external_modes.empty());
|
| -
|
| - if ((lcd_modes[0]->width * lcd_modes[0]->height) >=
|
| - (external_modes[0]->width * external_modes[0]->height)) {
|
| - return FindNearestResolutions(
|
| - lcd_modes, external_modes,
|
| - lcd_resolution, external_resolution, screen_resolution);
|
| - } else {
|
| - return FindNearestResolutions(
|
| - external_modes, lcd_modes,
|
| - external_resolution, lcd_resolution, screen_resolution);
|
| - }
|
| -}
|
| -
|
| -bool MonitorReconfigureMain::FindNearestResolutions(
|
| - const vector<XRRModeInfo*>& larger_device_modes,
|
| - const vector<XRRModeInfo*>& smaller_device_modes,
|
| - string* larger_resolution,
|
| - string* smaller_resolution,
|
| - string* screen_resolution) {
|
| - DCHECK(larger_resolution);
|
| - DCHECK(smaller_resolution);
|
| -
|
| - // Start with the best that the smaller device has to offer.
|
| - smaller_resolution->assign(smaller_device_modes[0]->name);
|
| - *screen_resolution = *smaller_resolution;
|
| - int smaller_width = smaller_device_modes[0]->width;
|
| - int smaller_height = smaller_device_modes[0]->height;
|
| -
|
| - for (vector<XRRModeInfo*>::const_reverse_iterator it =
|
| - larger_device_modes.rbegin();
|
| - it != larger_device_modes.rend(); ++it) {
|
| - if ((*it)->width >= smaller_width && (*it)->height >= smaller_height) {
|
| - larger_resolution->assign((*it)->name);
|
| - return true;
|
| - }
|
| + for (int i = 0; i < output_info.nmode; ++i) {
|
| + const XRRModeInfo* mode = mode_map_[output_info.modes[i]];
|
| + DCHECK(mode);
|
| + modes_out->push_back(
|
| + ResolutionSelector::Mode(mode->width, mode->height, mode->name));
|
| }
|
|
|
| - LOG(WARNING) << "Failed to find a resolution from larger device "
|
| - << "exceeding chosen resolution from smaller device ("
|
| - << *smaller_resolution << ")";
|
| - return false;
|
| + sort(modes_out->begin(), modes_out->end(),
|
| + ResolutionSelector::ModeResolutionComparator());
|
| }
|
|
|
| bool MonitorReconfigureMain::SetDeviceResolution(
|
| @@ -142,28 +121,6 @@ bool MonitorReconfigureMain::SetScreenResolution(
|
| return system(command.c_str()) == 0;
|
| }
|
|
|
| -void MonitorReconfigureMain::Run() {
|
| - // If there's no external monitor connected, just use the highest resolution
|
| - // supported by the LCD.
|
| - if (!IsExternalMonitorConnected()) {
|
| - LOG(INFO) << "No external monitor connected; using max LCD resolution";
|
| - vector<XRRModeInfo*> lcd_modes;
|
| - SortModesByResolution(*lcd_output_, &lcd_modes);
|
| - CHECK(!lcd_modes.empty());
|
| - SetDeviceResolution(lcd_output_->name, lcd_modes[0]->name);
|
| - SetScreenResolution(lcd_modes[0]->name);
|
| - return;
|
| - }
|
| -
|
| - string lcd_resolution, external_resolution, screen_resolution;
|
| - CHECK(FindBestResolutions(&lcd_resolution,
|
| - &external_resolution,
|
| - &screen_resolution));
|
| - SetDeviceResolution(lcd_output_->name, lcd_resolution);
|
| - SetDeviceResolution(external_output_->name, external_resolution);
|
| - SetScreenResolution(screen_resolution);
|
| -}
|
| -
|
| } // end namespace monitor_reconfig
|
|
|
| int main(int argc, char** argv) {
|
| @@ -177,7 +134,6 @@ int main(int argc, char** argv) {
|
| Window window = RootWindow(display, DefaultScreen(display));
|
| XRRScreenResources* screen_info = XRRGetScreenResources(display, window);
|
| monitor_reconfig::MonitorReconfigureMain main_app(display, screen_info);
|
| -
|
| main_app.Run();
|
| return 0;
|
| }
|
|
|