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

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"
7 #include "chrome/browser/sync/engine/idle_query_linux.h" 13 #include "chrome/browser/sync/engine/idle_query_linux.h"
14 #include "chrome/browser/ui/gtk/gtk_util.h"
15 #include "ui/base/x/x11_util.h"
16
17 namespace {
18
19 class ScreensaverWindowFinder : public ui::EnumerateWindowsDelegate {
20 public:
21 ScreensaverWindowFinder()
22 : exists_(false) {}
23
24 bool exists() const { return exists_; }
25
26 protected:
27 virtual bool ShouldStopIterating(XID window) {
28 if (!ui::IsWindowVisible(window) || !isScreensaverWindow(window))
29 return false;
30 exists_ = true;
31 return true;
32 }
33
34 private:
35 bool isScreensaverWindow(XID window) const {
Daniel Erat 2011/01/24 19:54:57 should be "IsScreensaverWindow"
jianli 2011/01/24 23:36:26 Done.
36 // 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.
37 if (!ui::IsX11WindowFullScreen(window))
38 return false;
39
40 // For xscreensaver, the window should have _SCREENSAVER_VERSION property.
41 if (ui::PropertyExists(window, "_SCREENSAVER_VERSION"))
42 return true;
43
44 // For all others, like gnome-screensaver, the window's WM_CLASS property
45 // should contains "screensaver".
Daniel Erat 2011/01/24 19:54:57 s/contains/contain/
jianli 2011/01/24 23:36:26 Done.
46 std::string value;
47 if (ui::GetStringProperty(window, "WM_CLASS", &value)) {
48 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
49 while (pos < len) {
50 std::string str(value.c_str() + pos);
51 if (str.find("screensaver") != std::string::npos)
52 return true;
53 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.
54 }
55 }
56
57 return false;
58 }
59
60 bool exists_;
61
62 DISALLOW_COPY_AND_ASSIGN(ScreensaverWindowFinder);
63 };
64
65 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.
66 ScreensaverWindowFinder finder;
67 gtk_util::EnumerateTopLevelWindows(&finder);
68 return finder.exists();
69 }
70
71 bool IsScreensaverRunning() {
72 gdk_error_trap_push();
73 bool result = ExistsScreensaverWindow();
74 bool got_error = gdk_error_trap_pop();
75 return result && !got_error;
76 }
77
78 }
8 79
9 IdleState CalculateIdleState(unsigned int idle_threshold) { 80 IdleState CalculateIdleState(unsigned int idle_threshold) {
81 // 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.
82 // if the workstation is locked.
83 if (IsScreensaverRunning())
84 return IDLE_STATE_LOCKED;
85
10 browser_sync::IdleQueryLinux idle_query; 86 browser_sync::IdleQueryLinux idle_query;
11 unsigned int idle_time = idle_query.IdleTime(); 87 unsigned int idle_time = idle_query.IdleTime();
12 if (idle_time >= idle_threshold) 88 if (idle_time >= idle_threshold)
13 return IDLE_STATE_IDLE; 89 return IDLE_STATE_IDLE;
14 return IDLE_STATE_ACTIVE; 90 return IDLE_STATE_ACTIVE;
15 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698