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 // This file defines utility functions for X11 (Linux only). This code has been | 5 // This file defines utility functions for X11 (Linux only). This code has been |
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |
7 // remains woefully incomplete. | 7 // remains woefully incomplete. |
8 | 8 |
9 #include "ui/base/x/x11_util.h" | 9 #include "ui/base/x/x11_util.h" |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "base/memory/singleton.h" | 28 #include "base/memory/singleton.h" |
29 #include "base/message_loop/message_loop.h" | 29 #include "base/message_loop/message_loop.h" |
30 #include "base/metrics/histogram.h" | 30 #include "base/metrics/histogram.h" |
31 #include "base/strings/string_number_conversions.h" | 31 #include "base/strings/string_number_conversions.h" |
32 #include "base/strings/string_util.h" | 32 #include "base/strings/string_util.h" |
33 #include "base/strings/stringprintf.h" | 33 #include "base/strings/stringprintf.h" |
34 #include "base/sys_byteorder.h" | 34 #include "base/sys_byteorder.h" |
35 #include "base/threading/thread.h" | 35 #include "base/threading/thread.h" |
36 #include "third_party/skia/include/core/SkBitmap.h" | 36 #include "third_party/skia/include/core/SkBitmap.h" |
37 #include "third_party/skia/include/core/SkPostConfig.h" | 37 #include "third_party/skia/include/core/SkPostConfig.h" |
| 38 #include "ui/base/x/x11_menu_list.h" |
38 #include "ui/base/x/x11_util_internal.h" | 39 #include "ui/base/x/x11_util_internal.h" |
39 #include "ui/events/event_utils.h" | 40 #include "ui/events/event_utils.h" |
40 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 41 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
41 #include "ui/events/x/device_data_manager.h" | 42 #include "ui/events/x/device_data_manager.h" |
42 #include "ui/events/x/touch_factory_x11.h" | 43 #include "ui/events/x/touch_factory_x11.h" |
43 #include "ui/gfx/canvas.h" | 44 #include "ui/gfx/canvas.h" |
44 #include "ui/gfx/image/image_skia.h" | 45 #include "ui/gfx/image/image_skia.h" |
45 #include "ui/gfx/image/image_skia_rep.h" | 46 #include "ui/gfx/image/image_skia_rep.h" |
46 #include "ui/gfx/point.h" | 47 #include "ui/gfx/point.h" |
47 #include "ui/gfx/point_conversions.h" | 48 #include "ui/gfx/point_conversions.h" |
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 | 1077 |
1077 XFree(prop.value); | 1078 XFree(prop.value); |
1078 return true; | 1079 return true; |
1079 } | 1080 } |
1080 | 1081 |
1081 bool EnumerateChildren(EnumerateWindowsDelegate* delegate, XID window, | 1082 bool EnumerateChildren(EnumerateWindowsDelegate* delegate, XID window, |
1082 const int max_depth, int depth) { | 1083 const int max_depth, int depth) { |
1083 if (depth > max_depth) | 1084 if (depth > max_depth) |
1084 return false; | 1085 return false; |
1085 | 1086 |
| 1087 std::vector<XID> windows; |
| 1088 std::vector<XID>::iterator iter; |
| 1089 if (depth == 0) { |
| 1090 XMenuList::GetInstance()->InsertMenuWindowXIDs(&windows); |
| 1091 // Enumerate the menus first. |
| 1092 for (iter = windows.begin(); iter != windows.end(); iter++) { |
| 1093 if (delegate->ShouldStopIterating(*iter)) |
| 1094 return true; |
| 1095 } |
| 1096 windows.clear(); |
| 1097 } |
| 1098 |
1086 XID root, parent, *children; | 1099 XID root, parent, *children; |
1087 unsigned int num_children; | 1100 unsigned int num_children; |
1088 int status = XQueryTree(gfx::GetXDisplay(), window, &root, &parent, &children, | 1101 int status = XQueryTree(gfx::GetXDisplay(), window, &root, &parent, &children, |
1089 &num_children); | 1102 &num_children); |
1090 if (status == 0) | 1103 if (status == 0) |
1091 return false; | 1104 return false; |
1092 | 1105 |
1093 std::vector<XID> windows; | |
1094 for (int i = static_cast<int>(num_children) - 1; i >= 0; i--) | 1106 for (int i = static_cast<int>(num_children) - 1; i >= 0; i--) |
1095 windows.push_back(children[i]); | 1107 windows.push_back(children[i]); |
1096 | 1108 |
1097 XFree(children); | 1109 XFree(children); |
1098 | 1110 |
1099 // XQueryTree returns the children of |window| in bottom-to-top order, so | 1111 // XQueryTree returns the children of |window| in bottom-to-top order, so |
1100 // reverse-iterate the list to check the windows from top-to-bottom. | 1112 // reverse-iterate the list to check the windows from top-to-bottom. |
1101 std::vector<XID>::iterator iter; | |
1102 for (iter = windows.begin(); iter != windows.end(); iter++) { | 1113 for (iter = windows.begin(); iter != windows.end(); iter++) { |
1103 if (IsWindowNamed(*iter) && delegate->ShouldStopIterating(*iter)) | 1114 if (IsWindowNamed(*iter) && delegate->ShouldStopIterating(*iter)) |
1104 return true; | 1115 return true; |
1105 } | 1116 } |
1106 | 1117 |
1107 // If we're at this point, we didn't find the window we're looking for at the | 1118 // If we're at this point, we didn't find the window we're looking for at the |
1108 // current level, so we need to recurse to the next level. We use a second | 1119 // current level, so we need to recurse to the next level. We use a second |
1109 // loop because the recursion and call to XQueryTree are expensive and is only | 1120 // loop because the recursion and call to XQueryTree are expensive and is only |
1110 // needed for a small number of cases. | 1121 // needed for a small number of cases. |
1111 if (++depth <= max_depth) { | 1122 if (++depth <= max_depth) { |
(...skipping 15 matching lines...) Expand all Loading... |
1127 std::vector<XID> stack; | 1138 std::vector<XID> stack; |
1128 if (!ui::GetXWindowStack(ui::GetX11RootWindow(), &stack)) { | 1139 if (!ui::GetXWindowStack(ui::GetX11RootWindow(), &stack)) { |
1129 // Window Manager doesn't support _NET_CLIENT_LIST_STACKING, so fall back | 1140 // Window Manager doesn't support _NET_CLIENT_LIST_STACKING, so fall back |
1130 // to old school enumeration of all X windows. Some WMs parent 'top-level' | 1141 // to old school enumeration of all X windows. Some WMs parent 'top-level' |
1131 // windows in unnamed actual top-level windows (ion WM), so extend the | 1142 // windows in unnamed actual top-level windows (ion WM), so extend the |
1132 // search depth to all children of top-level windows. | 1143 // search depth to all children of top-level windows. |
1133 const int kMaxSearchDepth = 1; | 1144 const int kMaxSearchDepth = 1; |
1134 ui::EnumerateAllWindows(delegate, kMaxSearchDepth); | 1145 ui::EnumerateAllWindows(delegate, kMaxSearchDepth); |
1135 return; | 1146 return; |
1136 } | 1147 } |
| 1148 XMenuList::GetInstance()->InsertMenuWindowXIDs(&stack); |
1137 | 1149 |
1138 std::vector<XID>::iterator iter; | 1150 std::vector<XID>::iterator iter; |
1139 for (iter = stack.begin(); iter != stack.end(); iter++) { | 1151 for (iter = stack.begin(); iter != stack.end(); iter++) { |
1140 if (delegate->ShouldStopIterating(*iter)) | 1152 if (delegate->ShouldStopIterating(*iter)) |
1141 return; | 1153 return; |
1142 } | 1154 } |
1143 } | 1155 } |
1144 | 1156 |
1145 bool GetXWindowStack(Window window, std::vector<XID>* windows) { | 1157 bool GetXWindowStack(Window window, std::vector<XID>* windows) { |
1146 windows->clear(); | 1158 windows->clear(); |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1617 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1606 << "minor_code " << static_cast<int>(error_event.minor_code) | 1618 << "minor_code " << static_cast<int>(error_event.minor_code) |
1607 << " (" << request_str << ")"; | 1619 << " (" << request_str << ")"; |
1608 } | 1620 } |
1609 | 1621 |
1610 // ---------------------------------------------------------------------------- | 1622 // ---------------------------------------------------------------------------- |
1611 // End of x11_util_internal.h | 1623 // End of x11_util_internal.h |
1612 | 1624 |
1613 | 1625 |
1614 } // namespace ui | 1626 } // namespace ui |
OLD | NEW |