| 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 SRC_PLATFORM_POWER_MANAGER_XIDLE_H_ | 5 #ifndef SRC_PLATFORM_POWER_MANAGER_XIDLE_H_ |
| 6 #define SRC_PLATFORM_POWER_MANAGER_XIDLE_H_ | 6 #define SRC_PLATFORM_POWER_MANAGER_XIDLE_H_ |
| 7 | 7 |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 #include <X11/extensions/sync.h> | 9 #include <X11/extensions/sync.h> |
| 10 #include <list> | 10 #include <list> |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 | 12 |
| 13 namespace power_manager { | 13 namespace power_manager { |
| 14 | 14 |
| 15 // \brief Connect to the local X Server and receive notifications when | 15 // \brief Connect to the local X Server and receive notifications when |
| 16 // the user is marked as idle, or as no longer idle. | 16 // the user is marked as idle, or as no longer idle. |
| 17 // | 17 // |
| 18 // Creating a new XIdle object connects to the local X Server. When the object | 18 // Creating a new XIdle object connects to the local X Server. When the object |
| 19 // is destroyed, the connection is also destroyed. | 19 // is destroyed, the connection is also destroyed. |
| 20 // | 20 // |
| 21 // \example | 21 // \example |
| 22 // power_manager::XIdle idle; | 22 // power_manager::XIdle idle; |
| 23 // idle.Init(); | 23 // Display* display = XOpenDisplay(NULL); |
| 24 // idle.Init(display); |
| 24 // idle.AddIdleTimeout(2000); | 25 // idle.AddIdleTimeout(2000); |
| 25 // idle.AddIdleTimeout(5000); | 26 // idle.AddIdleTimeout(5000); |
| 26 // int64 idle_time; | 27 // int64 idle_time; |
| 27 // bool is_idle; | 28 // bool is_idle; |
| 28 // while (idle.Monitor(&is_idle, &idle_time)) { | 29 // while (idle.Monitor(&is_idle, &idle_time)) { |
| 29 // if (is_idle) | 30 // if (is_idle) |
| 30 // std::cout << "User has been idle for " << idle_time << " ms\n"; | 31 // std::cout << "User has been idle for " << idle_time << " ms\n"; |
| 31 // else | 32 // else |
| 32 // std::cout << "User is active\n"; | 33 // std::cout << "User is active\n"; |
| 33 // } | 34 // } |
| 35 // XCloseDisplay(display); |
| 34 // \end_example | 36 // \end_example |
| 35 | 37 |
| 36 class XIdle { | 38 class XIdle { |
| 37 public: | 39 public: |
| 38 XIdle(); | 40 XIdle(); |
| 39 ~XIdle(); | 41 ~XIdle(); |
| 40 | 42 |
| 41 // Connect to the X server and initialize the object. | 43 // Initialize the object with the given X connection. |
| 42 // On success, return true; otherwise return false. | 44 // On success, return true; otherwise return false. |
| 43 bool Init(); | 45 bool Init(Display* display); |
| 44 | 46 |
| 45 // Add a timeout value. If the user exceeds this timeout value, | 47 // Add a timeout value. If the user exceeds this timeout value, |
| 46 // the Monitor function will return and notify us. If there are | 48 // the Monitor function will return and notify us. If there are |
| 47 // multiple idle timeouts, the Monitor function will return every | 49 // multiple idle timeouts, the Monitor function will return every |
| 48 // time each of the idle timeouts is exceeded. | 50 // time each of the idle timeouts is exceeded. |
| 49 // | 51 // |
| 50 // On success, return true; otherwise return false. | 52 // On success, return true; otherwise return false. |
| 51 bool AddIdleTimeout(int64 idle_timeout_ms); | 53 bool AddIdleTimeout(int64 idle_timeout_ms); |
| 52 | 54 |
| 53 // Monitor how long the user has been idle. The function will return | 55 // Monitor how long the user has been idle. The function will return |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // A list of the alarms. If non-empty, the negative transition alarm for | 88 // A list of the alarms. If non-empty, the negative transition alarm for |
| 87 // min_timeout_ will be the first alarm in the list. | 89 // min_timeout_ will be the first alarm in the list. |
| 88 std::list<XSyncAlarm> alarms_; | 90 std::list<XSyncAlarm> alarms_; |
| 89 | 91 |
| 90 DISALLOW_COPY_AND_ASSIGN(XIdle); | 92 DISALLOW_COPY_AND_ASSIGN(XIdle); |
| 91 }; | 93 }; |
| 92 | 94 |
| 93 } // namespace power_manager | 95 } // namespace power_manager |
| 94 | 96 |
| 95 #endif // SRC_PLATFORM_POWER_MANAGER_XIDLE_H_ | 97 #endif // SRC_PLATFORM_POWER_MANAGER_XIDLE_H_ |
| OLD | NEW |