Index: chrome/browser/fullscreen_linux.cc |
=================================================================== |
--- chrome/browser/fullscreen_linux.cc (revision 0) |
+++ chrome/browser/fullscreen_linux.cc (revision 0) |
@@ -0,0 +1,121 @@ |
+// Copyright (c) 2011 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/fullscreen.h" |
+ |
+#include <gdk/gdk.h> |
+#include <gdk/gdkx.h> |
+ |
+#include <algorithm> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "gfx/rect.h" |
+#include "ui/base/x/x11_util.h" |
+ |
+namespace { |
+ |
+XID FindTopMostWindow(XID window) { |
+ XID root, parent, *children; |
+ unsigned int num_children; |
+ if (!XQueryTree(ui::GetXDisplay(), |
+ window, |
+ &root, |
+ &parent, |
+ &children, |
+ &num_children)) |
+ return None; |
+ |
+ // XQueryTree returns the children of |window| in bottom-to-top order. So |
+ // we build the list from top to bottom. |
+ std::vector<XID> windows; |
+ for (int i = static_cast<int>(num_children - 1); i >= 0; --i) |
evanm
2011/01/21 00:43:07
One more minor comment:
static_cast<int>(num_chil
jianli
2011/01/21 20:21:00
Done.
|
+ windows.push_back(children[i]); |
+ |
+ XFree(children); |
+ |
+ for (std::vector<XID>::iterator iter = windows.begin(); |
+ iter != windows.end(); ++iter) { |
+ XID window = *iter; |
+ |
+ // Skip the invisible window. |
+ if (!ui::IsWindowVisible(window)) |
+ continue; |
+ |
+ // Check if the window is managed by the window manager. |
+ if (ui::ExistsProperty(window, "WM_STATE")) |
+ return window; |
+ |
+ // Otherwise, try to check its child windows. |
+ XID topmost_window = FindTopMostWindow(window); |
Daniel Erat
2011/01/21 01:28:17
This seems wrong. It looks like it gets called re
jianli
2011/01/21 20:21:00
Done.
|
+ if (topmost_window) |
+ return topmost_window; |
+ } |
+ |
+ return None; |
+} |
+ |
+bool DoFullScreenCheck() { |
Daniel Erat
2011/01/21 01:28:17
Please give this function a more-descriptive name;
jianli
2011/01/21 20:21:00
Done.
|
+ // Find the topmost window. |
+ XID topmost_window = FindTopMostWindow(ui::GetX11RootWindow()); |
+ if (topmost_window == None) |
+ return false; |
+ |
+ // Make sure it is not the desktop window. |
+ Atom atom = gdk_x11_get_xatom_by_name_for_display( |
+ gdk_display_get_default(), "_NET_WM_WINDOW_TYPE_DESKTOP"); |
+ |
+ std::vector<Atom> atom_properties; |
+ if (ui::GetAtomArrayProperty(topmost_window, |
+ "_NET_WM_WINDOW_TYPE", |
+ &atom_properties) && |
+ std::find(atom_properties.begin(), atom_properties.end(), atom) |
+ != atom_properties.end()) |
+ return false; |
+ |
+ // If it is a GDK window, check it using gdk function. |
+ GdkWindow* gwindow = gdk_window_lookup(topmost_window); |
Daniel Erat
2011/01/21 01:28:17
The docs for gdk_window_lookup() are vague: will i
jianli
2011/01/21 20:21:00
I am not sure either. But I think it would be nice
|
+ if (gwindow && topmost_window != GDK_ROOT_WINDOW()) |
+ return gdk_window_get_state(gwindow) == GDK_WINDOW_STATE_FULLSCREEN; |
+ |
+ // Otherwise, do the check via xlib function. |
+ return IsX11WindowFullScreen(topmost_window); |
+} |
+ |
+} |
+ |
+bool IsX11WindowFullScreen(XID window) { |
Daniel Erat
2011/01/21 01:28:17
If you want to call this from other places (it loo
jianli
2011/01/21 20:21:00
Done.
|
+ // First check if _NET_WM_STATE property contains _NET_WM_STATE_FULLSCREEN. |
+ Atom atom = gdk_x11_get_xatom_by_name_for_display( |
Daniel Erat
2011/01/21 01:28:17
It'd be good to cache this so you don't need to do
jianli
2011/01/21 20:21:00
Done.
|
+ gdk_display_get_default(), "_NET_WM_STATE_FULLSCREEN"); |
+ |
+ std::vector<Atom> atom_properties; |
+ if (ui::GetAtomArrayProperty(window, |
+ "_NET_WM_STATE", |
Daniel Erat
2011/01/21 01:28:17
fix indenting
jianli
2011/01/21 20:21:00
Done.
|
+ &atom_properties) && |
+ std::find(atom_properties.begin(), atom_properties.end(), atom) |
+ != atom_properties.end()) |
+ return true; |
+ |
+ // As the last resort, check if the window size is as large as the main |
+ // screen. |
+ GdkRectangle monitor_rect; |
+ gdk_screen_get_monitor_geometry(gdk_screen_get_default(), 0, &monitor_rect); |
+ |
+ gfx::Rect window_rect; |
+ if (!ui::GetWindowRect(window, &window_rect)) |
+ return false; |
+ |
+ return monitor_rect.x == window_rect.x() && |
+ monitor_rect.y == window_rect.y() && |
+ monitor_rect.width == window_rect.width() && |
+ monitor_rect.height == window_rect.height(); |
+} |
+ |
+bool IsFullScreenMode() { |
+ gdk_error_trap_push(); |
+ bool is_fullscreen = DoFullScreenCheck(); |
+ bool got_error = gdk_error_trap_pop(); |
+ return is_fullscreen && !got_error; |
+} |
Property changes on: chrome\browser\fullscreen_linux.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |