|
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/fullscreen.h" | |
6 | |
7 #include <gdk/gdk.h> | |
8 #include <gdk/gdkx.h> | |
9 | |
10 #include <algorithm> | |
11 #include <vector> | |
12 | |
13 #include "base/basictypes.h" | |
14 #include "gfx/rect.h" | |
15 #include "ui/base/x/x11_util.h" | |
16 | |
17 namespace { | |
18 | |
19 XID FindTopMostWindow(XID window) { | |
20 XID root, parent, *children; | |
21 unsigned int num_children; | |
22 if (!XQueryTree(ui::GetXDisplay(), | |
23 window, | |
24 &root, | |
25 &parent, | |
26 &children, | |
27 &num_children)) | |
28 return None; | |
29 | |
30 // XQueryTree returns the children of |window| in bottom-to-top order. So | |
31 // we build the list from top to bottom. | |
32 std::vector<XID> windows; | |
33 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.
| |
34 windows.push_back(children[i]); | |
35 | |
36 XFree(children); | |
37 | |
38 for (std::vector<XID>::iterator iter = windows.begin(); | |
39 iter != windows.end(); ++iter) { | |
40 XID window = *iter; | |
41 | |
42 // Skip the invisible window. | |
43 if (!ui::IsWindowVisible(window)) | |
44 continue; | |
45 | |
46 // Check if the window is managed by the window manager. | |
47 if (ui::ExistsProperty(window, "WM_STATE")) | |
48 return window; | |
49 | |
50 // Otherwise, try to check its child windows. | |
51 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.
| |
52 if (topmost_window) | |
53 return topmost_window; | |
54 } | |
55 | |
56 return None; | |
57 } | |
58 | |
59 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.
| |
60 // Find the topmost window. | |
61 XID topmost_window = FindTopMostWindow(ui::GetX11RootWindow()); | |
62 if (topmost_window == None) | |
63 return false; | |
64 | |
65 // Make sure it is not the desktop window. | |
66 Atom atom = gdk_x11_get_xatom_by_name_for_display( | |
67 gdk_display_get_default(), "_NET_WM_WINDOW_TYPE_DESKTOP"); | |
68 | |
69 std::vector<Atom> atom_properties; | |
70 if (ui::GetAtomArrayProperty(topmost_window, | |
71 "_NET_WM_WINDOW_TYPE", | |
72 &atom_properties) && | |
73 std::find(atom_properties.begin(), atom_properties.end(), atom) | |
74 != atom_properties.end()) | |
75 return false; | |
76 | |
77 // If it is a GDK window, check it using gdk function. | |
78 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
| |
79 if (gwindow && topmost_window != GDK_ROOT_WINDOW()) | |
80 return gdk_window_get_state(gwindow) == GDK_WINDOW_STATE_FULLSCREEN; | |
81 | |
82 // Otherwise, do the check via xlib function. | |
83 return IsX11WindowFullScreen(topmost_window); | |
84 } | |
85 | |
86 } | |
87 | |
88 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.
| |
89 // First check if _NET_WM_STATE property contains _NET_WM_STATE_FULLSCREEN. | |
90 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.
| |
91 gdk_display_get_default(), "_NET_WM_STATE_FULLSCREEN"); | |
92 | |
93 std::vector<Atom> atom_properties; | |
94 if (ui::GetAtomArrayProperty(window, | |
95 "_NET_WM_STATE", | |
Daniel Erat
2011/01/21 01:28:17
fix indenting
jianli
2011/01/21 20:21:00
Done.
| |
96 &atom_properties) && | |
97 std::find(atom_properties.begin(), atom_properties.end(), atom) | |
98 != atom_properties.end()) | |
99 return true; | |
100 | |
101 // As the last resort, check if the window size is as large as the main | |
102 // screen. | |
103 GdkRectangle monitor_rect; | |
104 gdk_screen_get_monitor_geometry(gdk_screen_get_default(), 0, &monitor_rect); | |
105 | |
106 gfx::Rect window_rect; | |
107 if (!ui::GetWindowRect(window, &window_rect)) | |
108 return false; | |
109 | |
110 return monitor_rect.x == window_rect.x() && | |
111 monitor_rect.y == window_rect.y() && | |
112 monitor_rect.width == window_rect.width() && | |
113 monitor_rect.height == window_rect.height(); | |
114 } | |
115 | |
116 bool IsFullScreenMode() { | |
117 gdk_error_trap_push(); | |
118 bool is_fullscreen = DoFullScreenCheck(); | |
119 bool got_error = gdk_error_trap_pop(); | |
120 return is_fullscreen && !got_error; | |
121 } | |
OLD | NEW |