| OLD | NEW |
| 1 // Copyright (c) 2009 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 #ifndef MONITOR_RECONFIGURE_MONITOR_RECONFIGURE_MAIN_H_ | 5 #ifndef MONITOR_RECONFIGURE_MONITOR_RECONFIGURE_MAIN_H_ |
| 6 #define MONITOR_RECONFIGURE_MONITOR_RECONFIGURE_MAIN_H_ | 6 #define MONITOR_RECONFIGURE_MONITOR_RECONFIGURE_MAIN_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include <X11/Xlib.h> | 12 #include <X11/Xlib.h> |
| 13 #include <X11/extensions/Xrandr.h> | 13 #include <X11/extensions/Xrandr.h> |
| 14 | 14 |
| 15 #include "monitor_reconfig/resolution_selector.h" |
| 16 |
| 15 namespace monitor_reconfig { | 17 namespace monitor_reconfig { |
| 16 | 18 |
| 17 // MonitorReconfigureMain is the class responsible for setting the external | 19 // MonitorReconfigureMain is the class responsible for setting the external |
| 18 // monitor to the max resolution based on the modes supported by the native | 20 // monitor to the max resolution based on the modes supported by the native |
| 19 // monitor and the external monitor | 21 // monitor and the external monitor |
| 20 class MonitorReconfigureMain { | 22 class MonitorReconfigureMain { |
| 21 public: | 23 public: |
| 22 MonitorReconfigureMain(Display* display, XRRScreenResources* screen_info); | 24 MonitorReconfigureMain(Display* display, XRRScreenResources* screen_info); |
| 23 virtual ~MonitorReconfigureMain() {} | 25 virtual ~MonitorReconfigureMain() {} |
| 24 | 26 |
| 25 // Main entry point | 27 // Main entry point |
| 26 void Run(); | 28 void Run(); |
| 27 | 29 |
| 28 private: | 30 private: |
| 29 // Initializes the |lcd_output_| and |external_output_| members. | 31 // Initializes the |lcd_output_| and |external_output_| members. |
| 30 void DetermineOutputs(); | 32 void DetermineOutputs(); |
| 31 | 33 |
| 32 // Returns whether an external monitor is connected | 34 // Returns whether an external monitor is connected |
| 33 bool IsExternalMonitorConnected(); | 35 bool IsExternalMonitorConnected(); |
| 34 | 36 |
| 35 // Comparator used by SortModeByResolution(). | |
| 36 // Returns true if |mode_a| has more pixels than |mode_b| and false otherwise. | |
| 37 class ModeResolutionComparator { | |
| 38 public: | |
| 39 bool operator()(XRRModeInfo* mode_a, XRRModeInfo* mode_b) const { | |
| 40 return mode_a->width * mode_a->height > mode_b->width * mode_b->height; | |
| 41 } | |
| 42 }; | |
| 43 | |
| 44 // Sorts |output_info|'s modes by decreasing number of pixels, storing the | 37 // Sorts |output_info|'s modes by decreasing number of pixels, storing the |
| 45 // results in |modes_out|. | 38 // results in |modes_out|. |
| 46 void SortModesByResolution(const XRROutputInfo& output_info, | 39 void SortModesByResolution(const XRROutputInfo& output_info, |
| 47 std::vector<XRRModeInfo*>* modes_out); | 40 std::vector<ResolutionSelector::Mode>* modes_out); |
| 48 | |
| 49 // Find resolutions to use. | |
| 50 bool FindBestResolutions( | |
| 51 std::string* lcd_resolution, | |
| 52 std::string* external_resolution, | |
| 53 std::string* screen_resolution); | |
| 54 | |
| 55 // Find resolutions to use that are reasonably close together. | |
| 56 // |larger_device_modes| and |smaller_device_modes| should be sorted by | |
| 57 // descending resolution. We choose the highest resolution from | |
| 58 // |smaller_device_modes| and the lowest resolution from |larger_device_modes| | |
| 59 // that's at least as high as the resolution from the smaller device. | |
| 60 // |screen_resolution| gets set to |smaller_resolution| to avoid clipping. | |
| 61 bool FindNearestResolutions( | |
| 62 const std::vector<XRRModeInfo*>& larger_device_modes, | |
| 63 const std::vector<XRRModeInfo*>& smaller_device_modes, | |
| 64 std::string* larger_resolution, | |
| 65 std::string* smaller_resolution, | |
| 66 std::string* screen_resolution); | |
| 67 | 41 |
| 68 // Set the resolution for a particular display or for the screen. | 42 // Set the resolution for a particular display or for the screen. |
| 69 bool SetDeviceResolution(const std::string& device_name, | 43 bool SetDeviceResolution(const std::string& device_name, |
| 70 const std::string& resolution); | 44 const std::string& resolution); |
| 71 bool SetScreenResolution(const std::string& resolution); | 45 bool SetScreenResolution(const std::string& resolution); |
| 72 | 46 |
| 73 // Mapping between mode XIDs and mode information structures. | 47 // Mapping between mode XIDs and mode information structures. |
| 74 std::map<int, XRRModeInfo*> mode_map_; | 48 std::map<int, XRRModeInfo*> mode_map_; |
| 75 | 49 |
| 76 // X Resources needed between functions | 50 // X Resources needed between functions |
| 77 Display* display_; | 51 Display* display_; |
| 78 XRRScreenResources* screen_info_; | 52 XRRScreenResources* screen_info_; |
| 79 XRROutputInfo* lcd_output_; | 53 XRROutputInfo* lcd_output_; |
| 80 XRROutputInfo* external_output_; | 54 XRROutputInfo* external_output_; |
| 81 }; | 55 }; |
| 82 | 56 |
| 83 } // namespace monitor_reconfig | 57 } // namespace monitor_reconfig |
| 84 | 58 |
| 85 #endif // MONITOR_RECONFIGURE_MONITOR_RECONFIGURE_MAIN_H_ | 59 #endif // MONITOR_RECONFIGURE_MONITOR_RECONFIGURE_MAIN_H_ |
| OLD | NEW |