Chromium Code Reviews| Index: chrome/browser/idle_linux.cc |
| =================================================================== |
| --- chrome/browser/idle_linux.cc (revision 72185) |
| +++ chrome/browser/idle_linux.cc (working copy) |
| @@ -4,9 +4,85 @@ |
| #include "chrome/browser/idle.h" |
| +#include <gdk/gdk.h> |
| +#include <gdk/gdkx.h> |
| + |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| #include "chrome/browser/sync/engine/idle_query_linux.h" |
| +#include "chrome/browser/ui/gtk/gtk_util.h" |
| +#include "ui/base/x/x11_util.h" |
| +namespace { |
| + |
| +class ScreensaverWindowFinder : public ui::EnumerateWindowsDelegate { |
| + public: |
| + ScreensaverWindowFinder() |
| + : exists_(false) {} |
| + |
| + bool exists() const { return exists_; } |
| + |
| + protected: |
| + virtual bool ShouldStopIterating(XID window) { |
| + if (!ui::IsWindowVisible(window) || !isScreensaverWindow(window)) |
| + return false; |
| + exists_ = true; |
| + return true; |
| + } |
| + |
| + private: |
| + bool isScreensaverWindow(XID window) const { |
|
Daniel Erat
2011/01/24 19:54:57
should be "IsScreensaverWindow"
jianli
2011/01/24 23:36:26
Done.
|
| + // It should occupy full screen. |
|
Daniel Erat
2011/01/24 19:54:57
s/occupy full/occupy the full/
jianli
2011/01/24 23:36:26
Done.
|
| + if (!ui::IsX11WindowFullScreen(window)) |
| + return false; |
| + |
| + // For xscreensaver, the window should have _SCREENSAVER_VERSION property. |
| + if (ui::PropertyExists(window, "_SCREENSAVER_VERSION")) |
| + return true; |
| + |
| + // For all others, like gnome-screensaver, the window's WM_CLASS property |
| + // should contains "screensaver". |
|
Daniel Erat
2011/01/24 19:54:57
s/contains/contain/
jianli
2011/01/24 23:36:26
Done.
|
| + std::string value; |
| + if (ui::GetStringProperty(window, "WM_CLASS", &value)) { |
| + size_t pos = 0, len = value.length(); |
|
Daniel Erat
2011/01/24 19:54:57
I don't understand why you're stepping through the
jianli
2011/01/24 23:36:26
WM_CLASS property (per http://tronche.com/gui/x/ic
|
| + while (pos < len) { |
| + std::string str(value.c_str() + pos); |
| + if (str.find("screensaver") != std::string::npos) |
| + return true; |
| + pos += str.length() + 1; |
|
Daniel Erat
2011/01/24 19:54:57
Additionally, isn't this wrong? str.length() shou
jianli
2011/01/24 23:36:26
Removed. See last comment.
|
| + } |
| + } |
| + |
| + return false; |
| + } |
| + |
| + bool exists_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScreensaverWindowFinder); |
| +}; |
| + |
| +bool ExistsScreensaverWindow() { |
|
Daniel Erat
2011/01/24 19:54:57
nit: rename to ScreensaverWindowExists() (but sinc
jianli
2011/01/24 23:36:26
Done.
Daniel Erat
2011/01/25 00:34:32
Is it? I still see the old name.
|
| + ScreensaverWindowFinder finder; |
| + gtk_util::EnumerateTopLevelWindows(&finder); |
| + return finder.exists(); |
| +} |
| + |
| +bool IsScreensaverRunning() { |
| + gdk_error_trap_push(); |
| + bool result = ExistsScreensaverWindow(); |
| + bool got_error = gdk_error_trap_pop(); |
| + return result && !got_error; |
| +} |
| + |
| +} |
| + |
| IdleState CalculateIdleState(unsigned int idle_threshold) { |
| + // Usually screensaver is used to lock the screen. So we do not need to check |
|
Daniel Erat
2011/01/24 19:54:57
minor grammatical nits:
s/Usually screensaver/Usu
jianli
2011/01/24 23:36:26
Done.
|
| + // if the workstation is locked. |
| + if (IsScreensaverRunning()) |
| + return IDLE_STATE_LOCKED; |
| + |
| browser_sync::IdleQueryLinux idle_query; |
| unsigned int idle_time = idle_query.IdleTime(); |
| if (idle_time >= idle_threshold) |