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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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>
8 #include <gdk/gdkx.h>
9
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "chrome/browser/fullscreen.h"
7 #include "chrome/browser/sync/engine/idle_query_linux.h" 14 #include "chrome/browser/sync/engine/idle_query_linux.h"
15 #include "ui/base/x/x11_util.h"
16
17 namespace {
18
19 bool DoScreensaverCheck() {
20 XID root, parent, *children;
21 unsigned int num_children;
22 if (!XQueryTree(ui::GetXDisplay(),
23 ui::GetX11RootWindow(),
24 &root,
25 &parent,
26 &children,
27 &num_children))
28 return false;
29
30 // XQueryTree returns the children of |window| in bottom-to-top order. So
31 // we build the list from top to bottom.
32 std::vector<XID> windows;
33 for (int i = static_cast<int>(num_children - 1); i >= 0; --i)
34 windows.push_back(children[i]);
35
36 XFree(children);
37
38 for (std::vector<XID>::iterator iter = windows.begin();
39 iter != windows.end(); ++iter) {
40 XID window = *iter;
41
42 // The screensaver window should be visible and full-screen.
43 if (!ui::IsWindowVisible(window) || !IsX11WindowFullScreen(window))
44 continue;
45
46 // For xscreensaver, the window should have _SCREENSAVER_VERSION property.
47 if (ui::ExistsProperty(window, "_SCREENSAVER_VERSION"))
48 return true;
49
50 // For all others, like gnome-screensaver, the window's WM_CLASS property
51 // should contains "screensaver".
52 std::string value;
53 if (ui::GetStringProperty(window, "WM_CLASS", &value)) {
54 size_t pos = 0, len = value.length();
55 while (pos < len) {
56 std::string str(value.c_str() + pos);
57 if (str.find("screensaver") != std::string::npos)
58 return true;
59 pos += str.length() + 1;
60 }
61 }
62 }
63
64 return false;
65 }
66
67 bool IsScreensaverRunning() {
68 gdk_error_trap_push();
69 bool is_screensaver_running = DoScreensaverCheck();
70 bool got_error = gdk_error_trap_pop();
71 return is_screensaver_running && !got_error;
72 }
73
74 }
8 75
9 IdleState CalculateIdleState(unsigned int idle_threshold) { 76 IdleState CalculateIdleState(unsigned int idle_threshold) {
77 // Usually screensaver is used to lock the screen. So we do not need to check
78 // if the workstation is locked.
79 if (IsScreensaverRunning())
80 return IDLE_STATE_LOCKED;
81
10 browser_sync::IdleQueryLinux idle_query; 82 browser_sync::IdleQueryLinux idle_query;
11 unsigned int idle_time = idle_query.IdleTime(); 83 unsigned int idle_time = idle_query.IdleTime();
12 if (idle_time >= idle_threshold) 84 if (idle_time >= idle_threshold)
13 return IDLE_STATE_IDLE; 85 return IDLE_STATE_IDLE;
14 return IDLE_STATE_ACTIVE; 86 return IDLE_STATE_ACTIVE;
15 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698