Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: ui/base/x/x11_util.cc

Issue 8387043: [Aura] Support always-on-top top level window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win_aura bot Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 render_supported = XRenderQueryExtension(dpy, &dummy, &dummy); 212 render_supported = XRenderQueryExtension(dpy, &dummy, &dummy);
209 render_supported_cached = true; 213 render_supported_cached = true;
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
222 const int kCursorClearXCursorCache = -1;
218 Cursor GetXCursor(int cursor_shape) { 223 Cursor GetXCursor(int cursor_shape) {
219 static XCursorCache cache; 224 static XCursorCache cache;
225
226 if (cursor_shape == kCursorClearXCursorCache) {
227 cache.Clear();
228 return NULL;
229 }
230
220 return cache.GetCursor(cursor_shape); 231 return cache.GetCursor(cursor_shape);
221 } 232 }
222 233
223 XID GetX11RootWindow() { 234 XID GetX11RootWindow() {
224 return DefaultRootWindow(GetXDisplay()); 235 return DefaultRootWindow(GetXDisplay());
225 } 236 }
226 237
227 bool GetCurrentDesktop(int* desktop) { 238 bool GetCurrentDesktop(int* desktop) {
228 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); 239 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop);
229 } 240 }
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 << "request_code " << static_cast<int>(error_event.request_code) << ", " 904 << "request_code " << static_cast<int>(error_event.request_code) << ", "
894 << "minor_code " << static_cast<int>(error_event.minor_code) 905 << "minor_code " << static_cast<int>(error_event.minor_code)
895 << " (" << request_str << ")"; 906 << " (" << request_str << ")";
896 } 907 }
897 908
898 // ---------------------------------------------------------------------------- 909 // ----------------------------------------------------------------------------
899 // End of x11_util_internal.h 910 // End of x11_util_internal.h
900 911
901 912
902 } // namespace ui 913 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698