monitor_reconfig: Disable external output to avoid error.

If we're using 1920x1200 on an external output and then
unplug it and try to switch back to 1366x768, xrandr gives
us an error like:

xrandr: specified screen 1366x768 not large enough for
output VGA1 (1920x1200+0+0)

when trying to set the screen size.  I think that this is
harmless, but it's easy enough to disable the external
output first in this case before adjusting the screen size.

Change-Id: I344f5af66657cb935b33d4398ec8a94befcf2ead

BUG=none
TEST=plugged and unplugged VGA and ran monitor_reconfigure a bunch

Review URL: http://codereview.chromium.org/3410019
diff --git a/monitor_reconfigure_main.cc b/monitor_reconfigure_main.cc
index b73e7ea..64c7058 100644
--- a/monitor_reconfigure_main.cc
+++ b/monitor_reconfigure_main.cc
@@ -54,8 +54,16 @@
                                      &screen_resolution));
 
   SetDeviceResolution(lcd_output_->name, lcd_resolution);
+
+  // If there's no external output connected, disable the device before we try
+  // to set the screen resolution; otherwise xrandr will complain if we're
+  // trying to set the screen to a smaller size than what the now-unplugged
+  // device was using.
   if (IsExternalMonitorConnected())
     SetDeviceResolution(external_output_->name, external_resolution);
+  else
+    DisableDevice(external_output_->name);
+
   SetScreenResolution(screen_resolution);
 }
 
@@ -122,6 +130,13 @@
   return system(command.c_str()) == 0;
 }
 
+bool MonitorReconfigureMain::DisableDevice(const std::string& device_name) {
+  string command = StringPrintf("xrandr --output %s --off",
+                                device_name.c_str());
+  LOG(INFO) << "Running " << command.c_str();
+  return system(command.c_str()) == 0;
+}
+
 }  // end namespace monitor_reconfig
 
 int main(int argc, char** argv) {
diff --git a/monitor_reconfigure_main.h b/monitor_reconfigure_main.h
index aeac10f..d639fb1 100644
--- a/monitor_reconfigure_main.h
+++ b/monitor_reconfigure_main.h
@@ -39,11 +39,14 @@
   void SortModesByResolution(const XRROutputInfo& output_info,
                              std::vector<ResolutionSelector::Mode>* modes_out);
 
-  // Set the resolution for a particular display or for the screen.
+  // Set the resolution for a particular device or for the screen.
   bool SetDeviceResolution(const std::string& device_name,
                            const std::string& resolution);
   bool SetScreenResolution(const std::string& resolution);
 
+  // Disable output to a device.
+  bool DisableDevice(const std::string& device_name);
+
   // Mapping between mode XIDs and mode information structures.
   std::map<int, XRRModeInfo*> mode_map_;