summaryrefslogtreecommitdiffstats
path: root/chrome/browser/screensaver_window_finder_x11.cc
blob: 66382117b85f535c950c80a263fcc7c6bd1457ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/screensaver_window_finder_x11.h"

#include "base/basictypes.h"
#include "base/x11/x11_error_tracker.h"
#include "ui/base/x/x11_util.h"

ScreensaverWindowFinder::ScreensaverWindowFinder()
    : exists_(false) {
}

bool ScreensaverWindowFinder::ScreensaverWindowExists() {
  base::X11ErrorTracker err_tracker;
  ScreensaverWindowFinder finder;
  ui::EnumerateTopLevelWindows(&finder);
  return finder.exists_ && !err_tracker.FoundNewError();
}

bool ScreensaverWindowFinder::ShouldStopIterating(XID window) {
  if (!ui::IsWindowVisible(window) || !IsScreensaverWindow(window))
    return false;
  exists_ = true;
  return true;
}

bool ScreensaverWindowFinder::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;
}