|
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 "chrome/browser/ui/gtk/gtk_util.h" | |
15 #include "gfx/rect.h" | |
16 #include "ui/base/x/x11_util.h" | |
17 | |
18 namespace { | |
19 | |
20 // TODO (jianli): Merge with gtk_util::EnumerateTopLevelWindows. | |
21 void EnumerateAllChildWindows(ui::EnumerateWindowsDelegate* delegate, | |
22 XID window) { | |
23 std::vector<XID> windows; | |
24 | |
25 if (!ui::GetXWindowStack(window, &windows)) { | |
26 // Window Manager doesn't support _NET_CLIENT_LIST_STACKING, so fall back | |
27 // to old school enumeration of all X windows. | |
28 XID root, parent, *children; | |
29 unsigned int num_children; | |
30 int status = XQueryTree(GetXDisplay(), window, &root, &parent, &children, | |
31 &num_children); | |
32 if (status) { | |
33 for (long i = static_cast<long>(num_children) - 1; i >= 0; i--) | |
34 windows.push_back(children[i]); | |
35 XFree(children); | |
36 } | |
37 } | |
38 | |
39 std::vector<XID>::iterator iter; | |
40 for (iter = windows.begin(); iter != windows.end(); iter++) { | |
41 if (delegate->ShouldStopIterating(*iter)) | |
42 return; | |
43 } | |
44 } | |
45 | |
46 // To find the top-most window: | |
47 // 1) Enumerate all top-level windows from the top to the bottom. | |
48 // 2) For each window: | |
49 // 2.1) If it is hidden, continue the iteration. | |
50 // 2.2) Enumerate all its child windows. If there is a child window that is | |
51 // managed by the Window Manager (has a WM_STATE property). Return this | |
52 // child window as the top-most window. | |
53 // 2.3) Otherwise, continue the iteration. | |
54 | |
55 class WindowManagerWindowFinder : public ui::EnumerateWindowsDelegate { | |
56 public: | |
57 WindowManagerWindowFinder() : window_(None) { } | |
58 | |
59 XID window() const { return window_; } | |
60 | |
61 protected: | |
62 virtual bool ShouldStopIterating(XID window) { | |
63 if (ui::PropertyExists(window, "WM_STATE")) { | |
64 window_ = window; | |
65 return true; | |
66 } | |
67 return false; | |
68 } | |
69 | |
70 private: | |
71 XID window_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(WindowManagerWindowFinder); | |
74 }; | |
75 | |
76 class TopMostWindowFinder : public ui::EnumerateWindowsDelegate { | |
77 public: | |
78 TopMostWindowFinder() | |
79 : top_most_window_(None), index(0) {} | |
80 | |
81 XID top_most_window() const { return top_most_window_; } | |
82 | |
83 protected: | |
84 virtual bool ShouldStopIterating(XID window) { | |
85 if (!ui::IsWindowVisible(window)) | |
86 return false; | |
87 WindowManagerWindowFinder child_finder; | |
88 ui::EnumerateAllChildWindows(&child_finder, window); | |
89 XID child_window = child_finder.window(); | |
90 if (child_window == None) | |
91 return false; | |
92 top_most_window_ = child_window; | |
93 return true; | |
94 } | |
95 | |
96 private: | |
97 XID top_most_window_; | |
98 int index; | |
Daniel Erat
2011/01/24 19:54:57
doesn't look like you're using this
jianli
2011/01/24 23:36:26
Leftover from debugging. Removed.
| |
99 | |
100 DISALLOW_COPY_AND_ASSIGN(TopMostWindowFinder); | |
101 }; | |
102 | |
103 bool IsTopMostWindowFullScreen() { | |
104 // Find the topmost window. | |
105 TopMostWindowFinder finder; | |
106 EnumerateAllChildWindows(&finder, ui::GetX11RootWindow()); | |
107 XID window = finder.top_most_window(); | |
108 if (window == None) | |
109 return false; | |
110 | |
111 // Make sure it is not the desktop window. | |
112 static Atom atom = gdk_x11_get_xatom_by_name_for_display( | |
Daniel Erat
2011/01/24 19:54:57
nit: rename to something like 'desktop_atom'
jianli
2011/01/24 23:36:26
Done.
| |
113 gdk_display_get_default(), "_NET_WM_WINDOW_TYPE_DESKTOP"); | |
114 | |
115 std::vector<Atom> atom_properties; | |
116 if (ui::GetAtomArrayProperty(window, | |
117 "_NET_WM_WINDOW_TYPE", | |
118 &atom_properties) && | |
119 std::find(atom_properties.begin(), atom_properties.end(), atom) | |
120 != atom_properties.end()) | |
121 return false; | |
122 | |
123 // If it is a GDK window, check it using gdk function. | |
124 GdkWindow* gwindow = gdk_window_lookup(window); | |
125 if (gwindow && window != GDK_ROOT_WINDOW()) | |
126 return gdk_window_get_state(gwindow) == GDK_WINDOW_STATE_FULLSCREEN; | |
127 | |
128 // Otherwise, do the check via xlib function. | |
129 return ui::IsX11WindowFullScreen(window); | |
130 } | |
131 | |
132 } | |
133 | |
134 bool IsFullScreenMode() { | |
135 gdk_error_trap_push(); | |
136 bool result = IsTopMostWindowFullScreen(); | |
137 bool got_error = gdk_error_trap_pop(); | |
138 return result && !got_error; | |
139 } | |
OLD | NEW |