| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 #include "chrome/browser/screensaver_window_finder_linux.h" | |
| 6 | |
| 7 #include <gdk/gdk.h> | |
| 8 #include <gdk/gdkx.h> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "chrome/browser/ui/gtk/gtk_util.h" | |
| 12 #include "ui/base/x/x11_util.h" | |
| 13 | |
| 14 | |
| 15 ScreensaverWindowFinder::ScreensaverWindowFinder() | |
| 16 : exists_(false) { | |
| 17 } | |
| 18 | |
| 19 bool ScreensaverWindowFinder::ScreensaverWindowExists() { | |
| 20 #if defined(USE_AURA) | |
| 21 return false; | |
| 22 #else | |
| 23 gdk_error_trap_push(); | |
| 24 ScreensaverWindowFinder finder; | |
| 25 gtk_util::EnumerateTopLevelWindows(&finder); | |
| 26 bool got_error = gdk_error_trap_pop(); | |
| 27 return finder.exists_ && !got_error; | |
| 28 #endif | |
| 29 } | |
| 30 | |
| 31 bool ScreensaverWindowFinder::ShouldStopIterating(XID window) { | |
| 32 if (!ui::IsWindowVisible(window) || !IsScreensaverWindow(window)) | |
| 33 return false; | |
| 34 exists_ = true; | |
| 35 return true; | |
| 36 } | |
| 37 | |
| 38 bool ScreensaverWindowFinder::IsScreensaverWindow(XID window) const { | |
| 39 // It should occupy the full screen. | |
| 40 if (!ui::IsX11WindowFullScreen(window)) | |
| 41 return false; | |
| 42 | |
| 43 // For xscreensaver, the window should have _SCREENSAVER_VERSION property. | |
| 44 if (ui::PropertyExists(window, "_SCREENSAVER_VERSION")) | |
| 45 return true; | |
| 46 | |
| 47 // For all others, like gnome-screensaver, the window's WM_CLASS property | |
| 48 // should contain "screensaver". | |
| 49 std::string value; | |
| 50 if (!ui::GetStringProperty(window, "WM_CLASS", &value)) | |
| 51 return false; | |
| 52 | |
| 53 return value.find("screensaver") != std::string::npos; | |
| 54 } | |
| OLD | NEW |