Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3160)

Unified Diff: chrome/browser/idle_linux.cc

Issue 6359008: Do not show notifications when in fullscreen or screensaver mode.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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)

Powered by Google App Engine
This is Rietveld 408576698