OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 num_items, | 106 num_items, |
107 &remaining_bytes, | 107 &remaining_bytes, |
108 property); | 108 property); |
109 } | 109 } |
110 | 110 |
111 // A process wide singleton that manages the usage of X cursors. | 111 // A process wide singleton that manages the usage of X cursors. |
112 class XCursorCache { | 112 class XCursorCache { |
113 public: | 113 public: |
114 XCursorCache() {} | 114 XCursorCache() {} |
115 ~XCursorCache() { | 115 ~XCursorCache() { |
116 Display* display = base::MessagePumpForUI::GetDefaultXDisplay(); | 116 Clear(); |
117 for (std::map<int, Cursor>::iterator it = | |
118 cache_.begin(); it != cache_.end(); ++it) { | |
119 XFreeCursor(display, it->second); | |
120 } | |
121 cache_.clear(); | |
122 } | 117 } |
123 | 118 |
124 Cursor GetCursor(int cursor_shape) { | 119 Cursor GetCursor(int cursor_shape) { |
125 // Lookup cursor by attempting to insert a null value, which avoids | 120 // Lookup cursor by attempting to insert a null value, which avoids |
126 // a second pass through the map after a cache miss. | 121 // a second pass through the map after a cache miss. |
127 std::pair<std::map<int, Cursor>::iterator, bool> it = cache_.insert( | 122 std::pair<std::map<int, Cursor>::iterator, bool> it = cache_.insert( |
128 std::make_pair(cursor_shape, 0)); | 123 std::make_pair(cursor_shape, 0)); |
129 if (it.second) { | 124 if (it.second) { |
130 Display* display = base::MessagePumpForUI::GetDefaultXDisplay(); | 125 Display* display = base::MessagePumpForUI::GetDefaultXDisplay(); |
131 it.first->second = XCreateFontCursor(display, cursor_shape); | 126 it.first->second = XCreateFontCursor(display, cursor_shape); |
132 } | 127 } |
133 return it.first->second; | 128 return it.first->second; |
134 } | 129 } |
135 | 130 |
| 131 void Clear() { |
| 132 Display* display = base::MessagePumpForUI::GetDefaultXDisplay(); |
| 133 for (std::map<int, Cursor>::iterator it = |
| 134 cache_.begin(); it != cache_.end(); ++it) { |
| 135 XFreeCursor(display, it->second); |
| 136 } |
| 137 cache_.clear(); |
| 138 } |
| 139 |
136 private: | 140 private: |
137 // Maps X11 font cursor shapes to Cursor IDs. | 141 // Maps X11 font cursor shapes to Cursor IDs. |
138 std::map<int, Cursor> cache_; | 142 std::map<int, Cursor> cache_; |
139 | 143 |
140 DISALLOW_COPY_AND_ASSIGN(XCursorCache); | 144 DISALLOW_COPY_AND_ASSIGN(XCursorCache); |
141 }; | 145 }; |
142 | 146 |
143 } // namespace | 147 } // namespace |
144 | 148 |
145 bool XDisplayExists() { | 149 bool XDisplayExists() { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 214 |
211 return render_supported; | 215 return render_supported; |
212 } | 216 } |
213 | 217 |
214 int GetDefaultScreen(Display* display) { | 218 int GetDefaultScreen(Display* display) { |
215 return XDefaultScreen(display); | 219 return XDefaultScreen(display); |
216 } | 220 } |
217 | 221 |
218 Cursor GetXCursor(int cursor_shape) { | 222 Cursor GetXCursor(int cursor_shape) { |
219 static XCursorCache cache; | 223 static XCursorCache cache; |
| 224 |
| 225 if (cursor_shape == kCursorClearXCursorCache) { |
| 226 cache.Clear(); |
| 227 return NULL; |
| 228 } |
| 229 |
220 return cache.GetCursor(cursor_shape); | 230 return cache.GetCursor(cursor_shape); |
221 } | 231 } |
222 | 232 |
223 XID GetX11RootWindow() { | 233 XID GetX11RootWindow() { |
224 return DefaultRootWindow(GetXDisplay()); | 234 return DefaultRootWindow(GetXDisplay()); |
225 } | 235 } |
226 | 236 |
227 bool GetCurrentDesktop(int* desktop) { | 237 bool GetCurrentDesktop(int* desktop) { |
228 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); | 238 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); |
229 } | 239 } |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 903 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
894 << "minor_code " << static_cast<int>(error_event.minor_code) | 904 << "minor_code " << static_cast<int>(error_event.minor_code) |
895 << " (" << request_str << ")"; | 905 << " (" << request_str << ")"; |
896 } | 906 } |
897 | 907 |
898 // ---------------------------------------------------------------------------- | 908 // ---------------------------------------------------------------------------- |
899 // End of x11_util_internal.h | 909 // End of x11_util_internal.h |
900 | 910 |
901 | 911 |
902 } // namespace ui | 912 } // namespace ui |
OLD | NEW |