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