| // Copyright (c) 2009 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. |
| |
| #ifndef MONITOR_RECONFIGURE_MONITOR_RECONFIGURE_MAIN_H_ |
| #define MONITOR_RECONFIGURE_MONITOR_RECONFIGURE_MAIN_H_ |
| |
| #include <map> |
| #include <string> |
| #include <vector> |
| |
| #include <X11/Xlib.h> |
| #include <X11/extensions/Xrandr.h> |
| |
| namespace monitor_reconfig { |
| |
| // MonitorReconfigureMain is the class responsible for setting the external |
| // monitor to the max resolution based on the modes supported by the native |
| // monitor and the external monitor |
| class MonitorReconfigureMain { |
| public: |
| MonitorReconfigureMain(Display* display, XRRScreenResources* screen_info); |
| virtual ~MonitorReconfigureMain() {} |
| |
| // Main entry point |
| void Run(); |
| |
| private: |
| // Initializes the |lcd_output_| and |external_output_| members. |
| void DetermineOutputs(); |
| |
| // Returns whether an external monitor is connected |
| bool IsExternalMonitorConnected(); |
| |
| // Comparator used by SortModeByResolution(). |
| // Returns true if |mode_a| has more pixels than |mode_b| and false otherwise. |
| class ModeResolutionComparator { |
| public: |
| bool operator()(XRRModeInfo* mode_a, XRRModeInfo* mode_b) const { |
| return mode_a->width * mode_a->height > mode_b->width * mode_b->height; |
| } |
| }; |
| |
| // Sorts |output_info|'s modes by decreasing number of pixels, storing the |
| // results in |modes_out|. |
| void SortModesByResolution(const XRROutputInfo& output_info, |
| std::vector<XRRModeInfo*>* modes_out); |
| |
| // Find resolutions to use. |
| bool FindBestResolutions( |
| std::string* lcd_resolution, |
| std::string* external_resolution, |
| std::string* screen_resolution); |
| |
| // Find resolutions to use that are reasonably close together. |
| // |larger_device_modes| and |smaller_device_modes| should be sorted by |
| // descending resolution. We choose the highest resolution from |
| // |smaller_device_modes| and the lowest resolution from |larger_device_modes| |
| // that's at least as high as the resolution from the smaller device. |
| // |screen_resolution| gets set to |smaller_resolution| to avoid clipping. |
| bool FindNearestResolutions( |
| const std::vector<XRRModeInfo*>& larger_device_modes, |
| const std::vector<XRRModeInfo*>& smaller_device_modes, |
| std::string* larger_resolution, |
| std::string* smaller_resolution, |
| std::string* screen_resolution); |
| |
| // Set the resolution for a particular display or for the screen. |
| bool SetDeviceResolution(const std::string& device_name, |
| const std::string& resolution); |
| bool SetScreenResolution(const std::string& resolution); |
| |
| // Mapping between mode XIDs and mode information structures. |
| std::map<int, XRRModeInfo*> mode_map_; |
| |
| // X Resources needed between functions |
| Display* display_; |
| XRRScreenResources* screen_info_; |
| XRROutputInfo* lcd_output_; |
| XRROutputInfo* external_output_; |
| }; |
| |
| } // namespace monitor_reconfig |
| |
| #endif // MONITOR_RECONFIGURE_MONITOR_RECONFIGURE_MAIN_H_ |