| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 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> |
| 10 #include <vector> |
| 9 | 11 |
| 10 #include <X11/Xlib.h> | 12 #include <X11/Xlib.h> |
| 11 #include <X11/extensions/Xrandr.h> | 13 #include <X11/extensions/Xrandr.h> |
| 12 | 14 |
| 13 namespace monitor_reconfig { | 15 namespace monitor_reconfig { |
| 14 | 16 |
| 15 // MonitorReconfigureMain is the class responsible for setting the external | 17 // MonitorReconfigureMain is the class responsible for setting the external |
| 16 // monitor to the max resolution based on the modes supported by the native | 18 // monitor to the max resolution based on the modes supported by the native |
| 17 // monitor and the external monitor | 19 // monitor and the external monitor |
| 18 class MonitorReconfigureMain { | 20 class MonitorReconfigureMain { |
| 19 public: | 21 public: |
| 20 MonitorReconfigureMain(Display* display, XRRScreenResources* screen_info); | 22 MonitorReconfigureMain(Display* display, XRRScreenResources* screen_info); |
| 21 virtual ~MonitorReconfigureMain() {} | 23 virtual ~MonitorReconfigureMain() {} |
| 22 | 24 |
| 23 // Main entry point | 25 // Main entry point |
| 24 void Run(); | 26 void Run(); |
| 25 | 27 |
| 28 private: |
| 29 // Initializes the |lcd_output_| and |external_output_| members. |
| 30 void DetermineOutputs(); |
| 31 |
| 26 // Returns whether an external monitor is connected | 32 // Returns whether an external monitor is connected |
| 27 bool IsExternalMonitorConnected(); | 33 bool IsExternalMonitorConnected(); |
| 28 | 34 |
| 29 private: | 35 // Comparator used by SortModeByResolution(). |
| 30 // Finds the max resolution mode for the given |output| | 36 // Returns true if |mode_a| has more pixels than |mode_b| and false otherwise. |
| 31 XRRModeInfo* FindMaxResolution(XRROutputInfo* output); | 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 }; |
| 32 | 43 |
| 33 // Finds the best matching resolution as compared to the |matching_mode| | 44 // Sorts |output_info|'s modes by decreasing number of pixels, storing the |
| 34 XRRModeInfo* FindBestMatchingResolution(XRRModeInfo* matching_mode); | 45 // results in |modes_out|. |
| 46 void SortModesByResolution(const XRROutputInfo& output_info, |
| 47 std::vector<XRRModeInfo*>* modes_out); |
| 35 | 48 |
| 36 // Initializes the |notebook_output_| and |external_output_| fields | 49 // Find resolutions to use. |
| 37 void DetermineOutputs(); | 50 bool FindBestResolutions( |
| 51 std::string* lcd_resolution, |
| 52 std::string* external_resolution, |
| 53 std::string* screen_resolution); |
| 38 | 54 |
| 39 // Sets the resolution of the notebook's screen, the external monitor's | 55 // Find resolutions to use that are reasonably close together. |
| 40 // screen, and the overall virtual screen to the given size. | 56 // |larger_device_modes| and |smaller_device_modes| should be sorted by |
| 41 void SetResolutions(XRRModeInfo* notebook_mode, | 57 // descending resolution. We choose the highest resolution from |
| 42 XRRModeInfo* external_mode, | 58 // |smaller_device_modes| and the lowest resolution from |larger_device_modes| |
| 43 XRRModeInfo* overall_screen_size); | 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); |
| 44 | 67 |
| 45 // Inline helper functions for FindBestMatchingResolution | 68 // Set the resolution for a particular display or for the screen. |
| 46 inline bool IsEqual(XRRModeInfo*, XRRModeInfo*); | 69 bool SetDeviceResolution(const std::string& device_name, |
| 47 inline bool IsBiggerOrEqual(XRRModeInfo*, XRRModeInfo*); | 70 const std::string& resolution); |
| 48 inline bool IsBetterMatching(XRRModeInfo* target, XRRModeInfo* to_match, | 71 bool SetScreenResolution(const std::string& resolution); |
| 49 XRRModeInfo* previous_best); | |
| 50 | 72 |
| 51 // Mapping between mode XID's and mode information structures | 73 // Mapping between mode XIDs and mode information structures. |
| 52 std::map<int, XRRModeInfo*> mode_map_; | 74 std::map<int, XRRModeInfo*> mode_map_; |
| 53 | 75 |
| 54 // X Resources needed between functions | 76 // X Resources needed between functions |
| 55 Display* display_; | 77 Display* display_; |
| 56 XRRScreenResources* screen_info_; | 78 XRRScreenResources* screen_info_; |
| 57 XRROutputInfo* notebook_output_; | 79 XRROutputInfo* lcd_output_; |
| 58 XRROutputInfo* external_output_; | 80 XRROutputInfo* external_output_; |
| 59 }; | 81 }; |
| 60 | 82 |
| 61 } // namespace monitor_reconfig | 83 } // namespace monitor_reconfig |
| 62 | 84 |
| 63 #endif // MONITOR_RECONFIGURE_MONITOR_RECONFIGURE_MAIN_H_ | 85 #endif // MONITOR_RECONFIGURE_MONITOR_RECONFIGURE_MAIN_H_ |
| OLD | NEW |