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

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

Issue 540643002: Add WindowManager to about:gpu page on Linux/X11 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months 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
« no previous file with comments | « ui/base/x/x11_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 max_length, // max length to get 95 max_length, // max length to get
96 False, // deleted 96 False, // deleted
97 AnyPropertyType, 97 AnyPropertyType,
98 type, 98 type,
99 format, 99 format,
100 num_items, 100 num_items,
101 &remaining_bytes, 101 &remaining_bytes,
102 property); 102 property);
103 } 103 }
104 104
105 bool GetWindowManagerName(std::string* wm_name) {
106 DCHECK(wm_name);
107 int wm_window = 0;
108 if (!GetIntProperty(GetX11RootWindow(),
109 "_NET_SUPPORTING_WM_CHECK",
110 &wm_window)) {
111 return false;
112 }
113
114 // It's possible that a window manager started earlier in this X session left
115 // a stale _NET_SUPPORTING_WM_CHECK property when it was replaced by a
116 // non-EWMH window manager, so we trap errors in the following requests to
117 // avoid crashes (issue 23860).
118
119 // EWMH requires the supporting-WM window to also have a
120 // _NET_SUPPORTING_WM_CHECK property pointing to itself (to avoid a stale
121 // property referencing an ID that's been recycled for another window), so we
122 // check that too.
123 gfx::X11ErrorTracker err_tracker;
124 int wm_window_property = 0;
125 bool result = GetIntProperty(
126 wm_window, "_NET_SUPPORTING_WM_CHECK", &wm_window_property);
127 if (err_tracker.FoundNewError() || !result ||
128 wm_window_property != wm_window) {
129 return false;
130 }
131
132 result = GetStringProperty(
133 static_cast<XID>(wm_window), "_NET_WM_NAME", wm_name);
134 return !err_tracker.FoundNewError() && result;
135 }
136
105 // A process wide singleton that manages the usage of X cursors. 137 // A process wide singleton that manages the usage of X cursors.
106 class XCursorCache { 138 class XCursorCache {
107 public: 139 public:
108 XCursorCache() {} 140 XCursorCache() {}
109 ~XCursorCache() { 141 ~XCursorCache() {
110 Clear(); 142 Clear();
111 } 143 }
112 144
113 ::Cursor GetCursor(int cursor_shape) { 145 ::Cursor GetCursor(int cursor_shape) {
114 // Lookup cursor by attempting to insert a null value, which avoids 146 // Lookup cursor by attempting to insert a null value, which avoids
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 image_skia.AddRepresentation(image_rep); 1180 image_skia.AddRepresentation(image_rep);
1149 canvas->DrawImageInt(image_skia, dest_offset.x(), dest_offset.y()); 1181 canvas->DrawImageInt(image_skia, dest_offset.x(), dest_offset.y());
1150 } else { 1182 } else {
1151 NOTIMPLEMENTED() << "Unsupported bits-per-pixel " << image->bits_per_pixel; 1183 NOTIMPLEMENTED() << "Unsupported bits-per-pixel " << image->bits_per_pixel;
1152 return false; 1184 return false;
1153 } 1185 }
1154 1186
1155 return true; 1187 return true;
1156 } 1188 }
1157 1189
1158 bool GetWindowManagerName(std::string* wm_name) {
1159 DCHECK(wm_name);
1160 int wm_window = 0;
1161 if (!GetIntProperty(GetX11RootWindow(),
1162 "_NET_SUPPORTING_WM_CHECK",
1163 &wm_window)) {
1164 return false;
1165 }
1166
1167 // It's possible that a window manager started earlier in this X session left
1168 // a stale _NET_SUPPORTING_WM_CHECK property when it was replaced by a
1169 // non-EWMH window manager, so we trap errors in the following requests to
1170 // avoid crashes (issue 23860).
1171
1172 // EWMH requires the supporting-WM window to also have a
1173 // _NET_SUPPORTING_WM_CHECK property pointing to itself (to avoid a stale
1174 // property referencing an ID that's been recycled for another window), so we
1175 // check that too.
1176 gfx::X11ErrorTracker err_tracker;
1177 int wm_window_property = 0;
1178 bool result = GetIntProperty(
1179 wm_window, "_NET_SUPPORTING_WM_CHECK", &wm_window_property);
1180 if (err_tracker.FoundNewError() || !result ||
1181 wm_window_property != wm_window) {
1182 return false;
1183 }
1184
1185 result = GetStringProperty(
1186 static_cast<XID>(wm_window), "_NET_WM_NAME", wm_name);
1187 return !err_tracker.FoundNewError() && result;
1188 }
1189
1190 WindowManagerName GuessWindowManager() { 1190 WindowManagerName GuessWindowManager() {
1191 std::string name; 1191 std::string name;
1192 if (GetWindowManagerName(&name)) { 1192 if (GetWindowManagerName(&name)) {
1193 // These names are taken from the WMs' source code. 1193 // These names are taken from the WMs' source code.
1194 if (name == "Blackbox") 1194 if (name == "Blackbox")
1195 return WM_BLACKBOX; 1195 return WM_BLACKBOX;
1196 if (name == "chromeos-wm") 1196 if (name == "chromeos-wm")
1197 return WM_CHROME_OS; 1197 return WM_CHROME_OS;
1198 if (name == "Compiz" || name == "compiz") 1198 if (name == "Compiz" || name == "compiz")
1199 return WM_COMPIZ; 1199 return WM_COMPIZ;
(...skipping 12 matching lines...) Expand all
1212 if (name == "Mutter") 1212 if (name == "Mutter")
1213 return WM_MUTTER; 1213 return WM_MUTTER;
1214 if (name == "Openbox") 1214 if (name == "Openbox")
1215 return WM_OPENBOX; 1215 return WM_OPENBOX;
1216 if (name == "Xfwm4") 1216 if (name == "Xfwm4")
1217 return WM_XFWM4; 1217 return WM_XFWM4;
1218 } 1218 }
1219 return WM_UNKNOWN; 1219 return WM_UNKNOWN;
1220 } 1220 }
1221 1221
1222 std::string GuessWindowManagerName() {
1223 std::string name;
1224 if (GetWindowManagerName(&name))
1225 return name;
1226 return "Unknown";
1227 }
1228
1222 void SetDefaultX11ErrorHandlers() { 1229 void SetDefaultX11ErrorHandlers() {
1223 SetX11ErrorHandlers(NULL, NULL); 1230 SetX11ErrorHandlers(NULL, NULL);
1224 } 1231 }
1225 1232
1226 bool IsX11WindowFullScreen(XID window) { 1233 bool IsX11WindowFullScreen(XID window) {
1227 // If _NET_WM_STATE_FULLSCREEN is in _NET_SUPPORTED, use the presence or 1234 // If _NET_WM_STATE_FULLSCREEN is in _NET_SUPPORTED, use the presence or
1228 // absence of _NET_WM_STATE_FULLSCREEN in _NET_WM_STATE to determine 1235 // absence of _NET_WM_STATE_FULLSCREEN in _NET_WM_STATE to determine
1229 // whether we're fullscreen. 1236 // whether we're fullscreen.
1230 XAtom fullscreen_atom = GetAtom("_NET_WM_STATE_FULLSCREEN"); 1237 XAtom fullscreen_atom = GetAtom("_NET_WM_STATE_FULLSCREEN");
1231 if (WmSupportsHint(fullscreen_atom)) { 1238 if (WmSupportsHint(fullscreen_atom)) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 << "request_code " << static_cast<int>(error_event.request_code) << ", " 1420 << "request_code " << static_cast<int>(error_event.request_code) << ", "
1414 << "minor_code " << static_cast<int>(error_event.minor_code) 1421 << "minor_code " << static_cast<int>(error_event.minor_code)
1415 << " (" << request_str << ")"; 1422 << " (" << request_str << ")";
1416 } 1423 }
1417 1424
1418 // ---------------------------------------------------------------------------- 1425 // ----------------------------------------------------------------------------
1419 // End of x11_util_internal.h 1426 // End of x11_util_internal.h
1420 1427
1421 1428
1422 } // namespace ui 1429 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/x/x11_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698