Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / base / idle / screensaver_window_finder_x11.cc
blobb6e3be2890739f4854d6c17df57bde36e81ad050
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/base/idle/screensaver_window_finder_x11.h"
7 #include "base/basictypes.h"
8 #include "ui/base/x/x11_util.h"
9 #include "ui/gfx/x/x11_error_tracker.h"
11 namespace ui {
13 ScreensaverWindowFinder::ScreensaverWindowFinder()
14 : exists_(false) {
17 bool ScreensaverWindowFinder::ScreensaverWindowExists() {
18 gfx::X11ErrorTracker err_tracker;
19 ScreensaverWindowFinder finder;
20 ui::EnumerateTopLevelWindows(&finder);
21 return finder.exists_ && !err_tracker.FoundNewError();
24 bool ScreensaverWindowFinder::ShouldStopIterating(XID window) {
25 if (!ui::IsWindowVisible(window) || !IsScreensaverWindow(window))
26 return false;
27 exists_ = true;
28 return true;
31 bool ScreensaverWindowFinder::IsScreensaverWindow(XID window) const {
32 // It should occupy the full screen.
33 if (!ui::IsX11WindowFullScreen(window))
34 return false;
36 // For xscreensaver, the window should have _SCREENSAVER_VERSION property.
37 if (ui::PropertyExists(window, "_SCREENSAVER_VERSION"))
38 return true;
40 // For all others, like gnome-screensaver, the window's WM_CLASS property
41 // should contain "screensaver".
42 std::string value;
43 if (!ui::GetStringProperty(window, "WM_CLASS", &value))
44 return false;
46 return value.find("screensaver") != std::string::npos;
49 } // namespace ui