| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium 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 "chrome/browser/idle.h" | 5 #include "chrome/browser/idle.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 bool ScreensaverWindowExists() { | 58 bool ScreensaverWindowExists() { |
| 59 ScreensaverWindowFinder finder; | 59 ScreensaverWindowFinder finder; |
| 60 gtk_util::EnumerateTopLevelWindows(&finder); | 60 gtk_util::EnumerateTopLevelWindows(&finder); |
| 61 return finder.exists(); | 61 return finder.exists(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 } | 64 } |
| 65 | 65 |
| 66 void CalculateIdleState(unsigned int idle_threshold, IdleCallback notify) { | 66 void CalculateIdleState(unsigned int idle_threshold, IdleCallback notify) { |
| 67 // Usually the screensaver is used to lock the screen, so we do not need to | 67 if (IsWorkstationInLockedState()) { |
| 68 // check if the workstation is locked. | |
| 69 gdk_error_trap_push(); | |
| 70 bool result = ScreensaverWindowExists(); | |
| 71 bool got_error = gdk_error_trap_pop(); | |
| 72 if (result && !got_error) { | |
| 73 notify.Run(IDLE_STATE_LOCKED); | 68 notify.Run(IDLE_STATE_LOCKED); |
| 74 return; | 69 return; |
| 75 } | 70 } |
| 76 | |
| 77 browser::IdleQueryLinux idle_query; | 71 browser::IdleQueryLinux idle_query; |
| 78 unsigned int idle_time = idle_query.IdleTime(); | 72 unsigned int idle_time = idle_query.IdleTime(); |
| 79 if (idle_time >= idle_threshold) | 73 if (idle_time >= idle_threshold) |
| 80 notify.Run(IDLE_STATE_IDLE); | 74 notify.Run(IDLE_STATE_IDLE); |
| 81 else | 75 else |
| 82 notify.Run(IDLE_STATE_ACTIVE); | 76 notify.Run(IDLE_STATE_ACTIVE); |
| 83 } | 77 } |
| 78 |
| 79 bool IsWorkstationInLockedState() { |
| 80 // Usually the screensaver is used to lock the screen, so we do not need to |
| 81 // check if the workstation is locked. |
| 82 gdk_error_trap_push(); |
| 83 bool result = ScreensaverWindowExists(); |
| 84 bool got_error = gdk_error_trap_pop(); |
| 85 return result && !got_error; |
| 86 } |
| OLD | NEW |