Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: monitor_reconfigure_main.cc

Issue 3410019: monitor_reconfig: Disable external output to avoid error. (Closed) Base URL: http://git.chromium.org/git/monitor_reconfig.git
Patch Set: Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « monitor_reconfigure_main.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "monitor_reconfig/monitor_reconfigure_main.h" 5 #include "monitor_reconfig/monitor_reconfigure_main.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstdio> 8 #include <cstdio>
9 #include <cstdlib> 9 #include <cstdlib>
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 ResolutionSelector selector; 48 ResolutionSelector selector;
49 string lcd_resolution, external_resolution, screen_resolution; 49 string lcd_resolution, external_resolution, screen_resolution;
50 CHECK(selector.FindBestResolutions(lcd_modes, 50 CHECK(selector.FindBestResolutions(lcd_modes,
51 external_modes, 51 external_modes,
52 &lcd_resolution, 52 &lcd_resolution,
53 &external_resolution, 53 &external_resolution,
54 &screen_resolution)); 54 &screen_resolution));
55 55
56 SetDeviceResolution(lcd_output_->name, lcd_resolution); 56 SetDeviceResolution(lcd_output_->name, lcd_resolution);
57
58 // If there's no external output connected, disable the device before we try
59 // to set the screen resolution; otherwise xrandr will complain if we're
60 // trying to set the screen to a smaller size than what the now-unplugged
61 // device was using.
57 if (IsExternalMonitorConnected()) 62 if (IsExternalMonitorConnected())
58 SetDeviceResolution(external_output_->name, external_resolution); 63 SetDeviceResolution(external_output_->name, external_resolution);
64 else
65 DisableDevice(external_output_->name);
66
59 SetScreenResolution(screen_resolution); 67 SetScreenResolution(screen_resolution);
60 } 68 }
61 69
62 void MonitorReconfigureMain::DetermineOutputs() { 70 void MonitorReconfigureMain::DetermineOutputs() {
63 CHECK(screen_info_->noutput > 1) << "Expected at least two outputs"; 71 CHECK(screen_info_->noutput > 1) << "Expected at least two outputs";
64 XRROutputInfo* first_output = 72 XRROutputInfo* first_output =
65 XRRGetOutputInfo(display_, screen_info_, screen_info_->outputs[0]); 73 XRRGetOutputInfo(display_, screen_info_, screen_info_->outputs[0]);
66 XRROutputInfo* second_output = 74 XRROutputInfo* second_output =
67 XRRGetOutputInfo(display_, screen_info_, screen_info_->outputs[1]); 75 XRRGetOutputInfo(display_, screen_info_, screen_info_->outputs[1]);
68 76
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return system(command.c_str()) == 0; 123 return system(command.c_str()) == 0;
116 } 124 }
117 125
118 bool MonitorReconfigureMain::SetScreenResolution( 126 bool MonitorReconfigureMain::SetScreenResolution(
119 const std::string& resolution) { 127 const std::string& resolution) {
120 string command = StringPrintf("xrandr --fb %s", resolution.c_str()); 128 string command = StringPrintf("xrandr --fb %s", resolution.c_str());
121 LOG(INFO) << "Running " << command.c_str(); 129 LOG(INFO) << "Running " << command.c_str();
122 return system(command.c_str()) == 0; 130 return system(command.c_str()) == 0;
123 } 131 }
124 132
133 bool MonitorReconfigureMain::DisableDevice(const std::string& device_name) {
134 string command = StringPrintf("xrandr --output %s --off",
135 device_name.c_str());
136 LOG(INFO) << "Running " << command.c_str();
137 return system(command.c_str()) == 0;
138 }
139
125 } // end namespace monitor_reconfig 140 } // end namespace monitor_reconfig
126 141
127 int main(int argc, char** argv) { 142 int main(int argc, char** argv) {
128 CommandLine::Init(argc, argv); 143 CommandLine::Init(argc, argv);
129 logging::InitLogging(NULL, 144 logging::InitLogging(NULL,
130 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, 145 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
131 logging::DONT_LOCK_LOG_FILE, 146 logging::DONT_LOCK_LOG_FILE,
132 logging::APPEND_TO_OLD_LOG_FILE); 147 logging::APPEND_TO_OLD_LOG_FILE);
133 Display* display = XOpenDisplay(NULL); 148 Display* display = XOpenDisplay(NULL);
134 CHECK(display) << "Could not open display"; 149 CHECK(display) << "Could not open display";
135 150
136 Window window = RootWindow(display, DefaultScreen(display)); 151 Window window = RootWindow(display, DefaultScreen(display));
137 XRRScreenResources* screen_info = XRRGetScreenResources(display, window); 152 XRRScreenResources* screen_info = XRRGetScreenResources(display, window);
138 monitor_reconfig::MonitorReconfigureMain main_app(display, screen_info); 153 monitor_reconfig::MonitorReconfigureMain main_app(display, screen_info);
139 main_app.Run(); 154 main_app.Run();
140 return 0; 155 return 0;
141 } 156 }
OLDNEW
« no previous file with comments | « monitor_reconfigure_main.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698