OLD | NEW |
1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 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 | 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 "power_manager/backlight_controller.h" | 5 #include "power_manager/backlight_controller.h" |
6 | 6 |
7 #include <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
8 #include <math.h> | 8 #include <math.h> |
9 #include <X11/extensions/dpms.h> | 9 #include <X11/extensions/dpms.h> |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 system_brightness_(0), | 60 system_brightness_(0), |
61 min_(0), | 61 min_(0), |
62 max_(-1), | 62 max_(-1), |
63 is_initialized_(false) {} | 63 is_initialized_(false) {} |
64 | 64 |
65 bool BacklightController::Init() { | 65 bool BacklightController::Init() { |
66 int64 level; | 66 int64 level; |
67 if (backlight_->GetBrightness(&level, &max_)) { | 67 if (backlight_->GetBrightness(&level, &max_)) { |
68 ReadPrefs(); | 68 ReadPrefs(); |
69 is_initialized_ = true; | 69 is_initialized_ = true; |
| 70 backlight_->SetScreenOffFunc(TurnScreenOffThunk, this); |
70 return true; | 71 return true; |
71 } | 72 } |
72 return false; | 73 return false; |
73 } | 74 } |
74 | 75 |
75 bool BacklightController::GetBrightness(int64* level) { | 76 bool BacklightController::GetBrightness(int64* level) { |
76 int64 raw_level; | 77 int64 raw_level; |
77 if (!backlight_->GetBrightness(&raw_level, &max_)) | 78 if (!backlight_->GetBrightness(&raw_level, &max_)) |
78 return false; | 79 return false; |
79 *level = lround(100. * raw_level / max_); | 80 *level = lround(100. * raw_level / max_); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if (light_sensor_) | 143 if (light_sensor_) |
143 light_sensor_->EnableOrDisableSensor(state_); | 144 light_sensor_->EnableOrDisableSensor(state_); |
144 | 145 |
145 if (GDK_DISPLAY() == NULL) | 146 if (GDK_DISPLAY() == NULL) |
146 return changed_brightness; | 147 return changed_brightness; |
147 if (!DPMSCapable(GDK_DISPLAY())) { | 148 if (!DPMSCapable(GDK_DISPLAY())) { |
148 LOG(WARNING) << "X Server is not DPMS capable"; | 149 LOG(WARNING) << "X Server is not DPMS capable"; |
149 } else { | 150 } else { |
150 CHECK(DPMSEnable(GDK_DISPLAY())); | 151 CHECK(DPMSEnable(GDK_DISPLAY())); |
151 if (state == BACKLIGHT_IDLE_OFF) { | 152 if (state == BACKLIGHT_IDLE_OFF) { |
152 g_timeout_add(kDisplayOffDelayMS, DisplayOffWhenBacklightOffThunk, this); | |
153 SetBrightnessToZero(); | 153 SetBrightnessToZero(); |
154 } else if (state == BACKLIGHT_ACTIVE_ON) { | 154 } else if (state == BACKLIGHT_ACTIVE_ON) { |
155 CHECK(DPMSForceLevel(GDK_DISPLAY(), DPMSModeOn)); | 155 CHECK(DPMSForceLevel(GDK_DISPLAY(), DPMSModeOn)); |
156 } | 156 } |
157 } | 157 } |
158 return changed_brightness; | 158 return changed_brightness; |
159 } | 159 } |
160 | 160 |
161 bool BacklightController::OnPlugEvent(bool is_plugged) { | 161 bool BacklightController::OnPlugEvent(bool is_plugged) { |
162 if ((brightness_offset_ && is_plugged == plugged_state_) || !is_initialized_) | 162 if ((brightness_offset_ && is_plugged == plugged_state_) || !is_initialized_) |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 292 } |
293 | 293 |
294 void BacklightController::SetBrightnessToZero() { | 294 void BacklightController::SetBrightnessToZero() { |
295 if (!is_initialized_) | 295 if (!is_initialized_) |
296 return; | 296 return; |
297 system_brightness_ = 0; | 297 system_brightness_ = 0; |
298 if (backlight_->SetBrightness(0)) | 298 if (backlight_->SetBrightness(0)) |
299 WritePrefs(); | 299 WritePrefs(); |
300 } | 300 } |
301 | 301 |
302 gboolean BacklightController::DisplayOffWhenBacklightOff() { | 302 void BacklightController::TurnScreenOff() { |
303 int64 brightness = 0; | 303 if (state_ == BACKLIGHT_IDLE_OFF && GDK_DISPLAY() != NULL) |
304 CHECK(GetBrightness(&brightness)); | |
305 if (brightness == 0) { | |
306 CHECK(DPMSForceLevel(GDK_DISPLAY(), DPMSModeOff)); | 304 CHECK(DPMSForceLevel(GDK_DISPLAY(), DPMSModeOff)); |
307 return false; | |
308 } else { | |
309 // If the brightness has not been set all the way down, keep polling it | |
310 // until it reaches zero. | |
311 return true; | |
312 } | |
313 } | 305 } |
314 | 306 |
| 307 |
315 } // namespace power_manager | 308 } // namespace power_manager |
OLD | NEW |