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