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/powerd.h" | 5 #include "power_manager/powerd.h" |
6 | 6 |
7 #include <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <X11/extensions/dpms.h> | 9 #include <X11/extensions/dpms.h> |
10 #include <X11/keysym.h> | 10 #include <X11/keysym.h> |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 } | 327 } |
328 GenerateMetricsOnIdleEvent(is_idle, idle_time_ms); | 328 GenerateMetricsOnIdleEvent(is_idle, idle_time_ms); |
329 SetIdleState(idle_time_ms); | 329 SetIdleState(idle_time_ms); |
330 if (!is_idle && offset_ms_ != 0) | 330 if (!is_idle && offset_ms_ != 0) |
331 SetIdleOffset(0, kIdleNormal); | 331 SetIdleOffset(0, kIdleNormal); |
332 } | 332 } |
333 | 333 |
334 void Daemon::SetIdleState(int64 idle_time_ms) { | 334 void Daemon::SetIdleState(int64 idle_time_ms) { |
335 bool changed_brightness = false; | 335 bool changed_brightness = false; |
336 if (idle_time_ms >= suspend_ms_) { | 336 if (idle_time_ms >= suspend_ms_) { |
337 LOG(INFO) << "state = kIdleSuspend"; | |
338 // Note: currently this state doesn't do anything. But it can be possibly | 337 // Note: currently this state doesn't do anything. But it can be possibly |
339 // useful in future development. For example, if we want to implement fade | 338 // useful in future development. For example, if we want to implement fade |
340 // from suspend, we would want to have this state to make sure the backlight | 339 // from suspend, we would want to have this state to make sure the backlight |
341 // is set to zero when suspended. | 340 // is set to zero when suspended. |
342 changed_brightness = | 341 if (backlight_controller_->SetPowerState(BACKLIGHT_SUSPENDED)) { |
343 backlight_controller_->SetPowerState(BACKLIGHT_SUSPENDED); | 342 idle_state_ = kIdleSuspend; |
344 idle_state_ = kIdleSuspend; | 343 LOG(INFO) << "state = kIdleSuspend"; |
345 Suspend(); | 344 changed_brightness = true; |
| 345 Suspend(); |
| 346 } |
346 } else if (idle_time_ms >= off_ms_) { | 347 } else if (idle_time_ms >= off_ms_) { |
347 LOG(INFO) << "state = kIdleScreenOff"; | 348 if (backlight_controller_->SetPowerState(BACKLIGHT_IDLE_OFF)) { |
348 changed_brightness = | 349 idle_state_ = kIdleScreenOff; |
349 backlight_controller_->SetPowerState(BACKLIGHT_IDLE_OFF); | 350 LOG(INFO) << "state = kIdleScreenOff"; |
350 idle_state_ = kIdleScreenOff; | 351 changed_brightness = true; |
| 352 } |
351 } else if (idle_time_ms >= dim_ms_) { | 353 } else if (idle_time_ms >= dim_ms_) { |
352 LOG(INFO) << "state = kIdleDim"; | 354 if (backlight_controller_->SetPowerState(BACKLIGHT_DIM)) { |
353 changed_brightness = backlight_controller_->SetPowerState(BACKLIGHT_DIM); | 355 idle_state_ = kIdleDim; |
354 idle_state_ = kIdleDim; | 356 LOG(INFO) << "state = kIdleDim"; |
| 357 changed_brightness = true; |
| 358 } |
355 } else if (idle_state_ != kIdleNormal) { | 359 } else if (idle_state_ != kIdleNormal) { |
356 LOG(INFO) << "state = kIdleNormal"; | 360 if (backlight_controller_->SetPowerState(BACKLIGHT_ACTIVE_ON)) { |
357 changed_brightness = | 361 if (idle_state_ == kIdleSuspend) { |
358 backlight_controller_->SetPowerState(BACKLIGHT_ACTIVE_ON); | 362 util::CreateStatusFile(FilePath(run_dir_) |
359 if (idle_state_ == kIdleSuspend) { | 363 .Append(util::kUserActiveFile)); |
360 util::CreateStatusFile(FilePath(run_dir_).Append(util::kUserActiveFile)); | 364 suspender_.CancelSuspend(); |
361 suspender_.CancelSuspend(); | 365 } |
| 366 idle_state_ = kIdleNormal; |
| 367 LOG(INFO) << "state = kIdleNormal"; |
| 368 changed_brightness = true; |
362 } | 369 } |
363 idle_state_ = kIdleNormal; | |
364 } | 370 } |
365 if (idle_time_ms >= lock_ms_ && util::LoggedIn() && | 371 if (idle_time_ms >= lock_ms_ && util::LoggedIn() && |
366 idle_state_ != kIdleSuspend) { | 372 idle_state_ != kIdleSuspend) { |
367 locker_.LockScreen(); | 373 locker_.LockScreen(); |
368 } | 374 } |
369 | 375 |
370 if (changed_brightness) | 376 if (changed_brightness) |
371 SendBrightnessChangedSignal(false); // user_initiated=false | 377 SendBrightnessChangedSignal(false); // user_initiated=false |
372 } | 378 } |
373 | 379 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 dbus_g_proxy_send(proxy.gproxy(), signal, NULL); | 690 dbus_g_proxy_send(proxy.gproxy(), signal, NULL); |
685 dbus_message_unref(signal); | 691 dbus_message_unref(signal); |
686 } | 692 } |
687 | 693 |
688 void Daemon::HandleResume() { | 694 void Daemon::HandleResume() { |
689 file_tagger_.HandleResumeEvent(); | 695 file_tagger_.HandleResumeEvent(); |
690 backlight_controller_->SetPowerState(BACKLIGHT_ACTIVE_ON); | 696 backlight_controller_->SetPowerState(BACKLIGHT_ACTIVE_ON); |
691 } | 697 } |
692 | 698 |
693 } // namespace power_manager | 699 } // namespace power_manager |
OLD | NEW |