summaryrefslogtreecommitdiffstats
path: root/chrome/browser/idle_linux.cc
diff options
context:
space:
mode:
authorjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-25 20:54:06 +0000
committerjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-25 20:54:06 +0000
commit3c64537927e5a31388c8fac8e04e575a12f6ff81 (patch)
treeadc23145813263daad9d696f2ffb3648dafa8bd5 /chrome/browser/idle_linux.cc
parent34ce848a57340642bb708d44bf1e6fa4ea3a07b5 (diff)
downloadchromium_src-3c64537927e5a31388c8fac8e04e575a12f6ff81.zip
chromium_src-3c64537927e5a31388c8fac8e04e575a12f6ff81.tar.gz
chromium_src-3c64537927e5a31388c8fac8e04e575a12f6ff81.tar.bz2
Do not show notifications when in fullscreen or screensaver mode.
I add full-screen/presentation mode detection for all 3 platforms. I also add screensaver detection for MacOSX and Linux since it is missing in these 2 platforms. BUG=25061 TEST=Manual test Review URL: http://codereview.chromium.org/6359008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72539 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/idle_linux.cc')
-rw-r--r--chrome/browser/idle_linux.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/chrome/browser/idle_linux.cc b/chrome/browser/idle_linux.cc
index 0da7f72..e1cdac2 100644
--- a/chrome/browser/idle_linux.cc
+++ b/chrome/browser/idle_linux.cc
@@ -4,9 +4,74 @@
#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 {
+ // It should occupy the full screen.
+ 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 contain "screensaver".
+ std::string value;
+ if (!ui::GetStringProperty(window, "WM_CLASS", &value))
+ return false;
+
+ return value.find("screensaver") != std::string::npos;
+ }
+
+ bool exists_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScreensaverWindowFinder);
+};
+
+bool ScreensaverWindowExists() {
+ ScreensaverWindowFinder finder;
+ gtk_util::EnumerateTopLevelWindows(&finder);
+ return finder.exists();
+}
+
+}
IdleState CalculateIdleState(unsigned int idle_threshold) {
+ // Usually the screensaver is used to lock the screen, so we do not need to
+ // check if the workstation is locked.
+ gdk_error_trap_push();
+ bool result = ScreensaverWindowExists();
+ bool got_error = gdk_error_trap_pop();
+ if (result && !got_error)
+ return IDLE_STATE_LOCKED;
+
browser_sync::IdleQueryLinux idle_query;
unsigned int idle_time = idle_query.IdleTime();
if (idle_time >= idle_threshold)