| Index: chrome/browser/idle_linux.cc
|
| ===================================================================
|
| --- chrome/browser/idle_linux.cc (revision 72012)
|
| +++ chrome/browser/idle_linux.cc (working copy)
|
| @@ -4,9 +4,81 @@
|
|
|
| #include "chrome/browser/idle.h"
|
|
|
| +#include <gdk/gdk.h>
|
| +#include <gdk/gdkx.h>
|
| +
|
| +#include <vector>
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "chrome/browser/fullscreen.h"
|
| #include "chrome/browser/sync/engine/idle_query_linux.h"
|
| +#include "ui/base/x/x11_util.h"
|
|
|
| +namespace {
|
| +
|
| +bool DoScreensaverCheck() {
|
| + XID root, parent, *children;
|
| + unsigned int num_children;
|
| + if (!XQueryTree(ui::GetXDisplay(),
|
| + ui::GetX11RootWindow(),
|
| + &root,
|
| + &parent,
|
| + &children,
|
| + &num_children))
|
| + return false;
|
| +
|
| + // XQueryTree returns the children of |window| in bottom-to-top order. So
|
| + // we build the list from top to bottom.
|
| + std::vector<XID> windows;
|
| + for (int i = static_cast<int>(num_children - 1); i >= 0; --i)
|
| + windows.push_back(children[i]);
|
| +
|
| + XFree(children);
|
| +
|
| + for (std::vector<XID>::iterator iter = windows.begin();
|
| + iter != windows.end(); ++iter) {
|
| + XID window = *iter;
|
| +
|
| + // The screensaver window should be visible and full-screen.
|
| + if (!ui::IsWindowVisible(window) || !IsX11WindowFullScreen(window))
|
| + continue;
|
| +
|
| + // For xscreensaver, the window should have _SCREENSAVER_VERSION property.
|
| + if (ui::ExistsProperty(window, "_SCREENSAVER_VERSION"))
|
| + return true;
|
| +
|
| + // For all others, like gnome-screensaver, the window's WM_CLASS property
|
| + // should contains "screensaver".
|
| + std::string value;
|
| + if (ui::GetStringProperty(window, "WM_CLASS", &value)) {
|
| + size_t pos = 0, len = value.length();
|
| + while (pos < len) {
|
| + std::string str(value.c_str() + pos);
|
| + if (str.find("screensaver") != std::string::npos)
|
| + return true;
|
| + pos += str.length() + 1;
|
| + }
|
| + }
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| +bool IsScreensaverRunning() {
|
| + gdk_error_trap_push();
|
| + bool is_screensaver_running = DoScreensaverCheck();
|
| + bool got_error = gdk_error_trap_pop();
|
| + return is_screensaver_running && !got_error;
|
| +}
|
| +
|
| +}
|
| +
|
| IdleState CalculateIdleState(unsigned int idle_threshold) {
|
| + // Usually screensaver is used to lock the screen. So we do not need to check
|
| + // 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)
|
|
|