OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef POWER_MANAGER_MONITOR_RECONFIGURE_MAIN_H_ |
| 6 #define POWER_MANAGER_MONITOR_RECONFIGURE_MAIN_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include <X11/Xlib.h> |
| 13 #include <X11/extensions/Xrandr.h> |
| 14 |
| 15 #include "power_manager/backlight_controller.h" |
| 16 #include "power_manager/resolution_selector.h" |
| 17 #include "power_manager/udev_listener.h" |
| 18 |
| 19 namespace power_manager { |
| 20 |
| 21 class MonitorReconfigureMain; |
| 22 |
| 23 // Callback class for udev events. |
| 24 class MonitorReconfigureCallback : public UdevCallback { |
| 25 public: |
| 26 MonitorReconfigureCallback(MonitorReconfigureMain* monitor_reconfigure) |
| 27 : monitor_reconfigure_(monitor_reconfigure) {} |
| 28 |
| 29 void Run(GIOChannel* source, GIOCondition condition); |
| 30 private: |
| 31 MonitorReconfigureMain* monitor_reconfigure_; |
| 32 }; |
| 33 |
| 34 // MonitorReconfigureMain is the class responsible for setting the external |
| 35 // monitor to the max resolution based on the modes supported by the native |
| 36 // monitor and the external monitor. |
| 37 class MonitorReconfigureMain { |
| 38 public: |
| 39 // |window| is the root window. |
| 40 MonitorReconfigureMain(BacklightController* backlight_ctl); |
| 41 ~MonitorReconfigureMain(); |
| 42 |
| 43 // Initialization. |
| 44 bool Init(); |
| 45 |
| 46 // Main entry point. |
| 47 void Run(); |
| 48 |
| 49 private: |
| 50 // Initializes the |lcd_output_| and |external_output_| members. |
| 51 void DetermineOutputs(); |
| 52 |
| 53 // Returns whether an external monitor is connected. |
| 54 bool IsExternalMonitorConnected(); |
| 55 |
| 56 // Sorts |output_info|'s modes by decreasing number of pixels, storing the |
| 57 // results in |modes_out|. |
| 58 void SortModesByResolution(RROutput output, |
| 59 std::vector<ResolutionSelector::Mode>* modes_out); |
| 60 |
| 61 // Set the resolution for a particular device or for the screen. |
| 62 bool SetDeviceResolution(RROutput output, |
| 63 const XRROutputInfo* output_info, |
| 64 const ResolutionSelector::Mode& resolution); |
| 65 bool SetScreenResolution(const ResolutionSelector::Mode& resolution); |
| 66 |
| 67 // Disable output to a device. |
| 68 bool DisableDevice(const XRROutputInfo* output_info); |
| 69 |
| 70 // Mapping between mode XIDs and mode information structures. |
| 71 std::map<int, XRRModeInfo*> mode_map_; |
| 72 |
| 73 // X Resources needed between functions. |
| 74 Display* display_; |
| 75 Window window_; |
| 76 XRRScreenResources* screen_info_; |
| 77 |
| 78 RROutput lcd_output_; |
| 79 XRROutputInfo* lcd_output_info_; |
| 80 |
| 81 RROutput external_output_; |
| 82 XRROutputInfo* external_output_info_; |
| 83 |
| 84 // Not owned. |
| 85 BacklightController* backlight_ctl_; |
| 86 |
| 87 // Callback for the Udev listener. |
| 88 MonitorReconfigureCallback* callback_; |
| 89 |
| 90 // Udev linstener. |
| 91 UdevListener* listener_; |
| 92 |
| 93 }; |
| 94 |
| 95 } // namespace power_manager |
| 96 |
| 97 #endif // POWER_MANAGER_MONITOR_RECONFIGURE_MAIN_H_ |
OLD | NEW |