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

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

Issue 591213004: Improve check for whether _NET_ACTIVE_WINDOW is supported (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 | « no previous file | ui/views/widget/desktop_aura/x11_desktop_handler.cc » ('j') | 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 SupportsEWMH() {
106 static bool supports_ewmh = false;
107 static bool supports_ewmh_cached = false;
Daniel Erat 2014/09/23 15:32:41 i was going to say that i'm not sure how i feel ab
108 if (!supports_ewmh_cached) {
109 supports_ewmh_cached = true;
110
111 int wm_window = 0u;
112 if (!GetIntProperty(GetX11RootWindow(),
113 "_NET_SUPPORTING_WM_CHECK",
114 &wm_window)) {
115 supports_ewmh = false;
116 return false;
117 }
118
119 // It's possible that a window manager started earlier in this X session
120 // left a stale _NET_SUPPORTING_WM_CHECK property when it was replaced by a
121 // non-EWMH window manager, so we trap errors in the following requests to
122 // avoid crashes (issue 23860).
123
124 // EWMH requires the supporting-WM window to also have a
125 // _NET_SUPPORTING_WM_CHECK property pointing to itself (to avoid a stale
126 // property referencing an ID that's been recycled for another window), so
127 // we check that too.
128 gfx::X11ErrorTracker err_tracker;
129 int wm_window_property = 0;
130 bool result = GetIntProperty(
131 wm_window, "_NET_SUPPORTING_WM_CHECK", &wm_window_property);
132 supports_ewmh = !err_tracker.FoundNewError() &&
133 result &&
134 wm_window_property == wm_window;
135 }
136
137 return supports_ewmh;
138 }
139
105 bool GetWindowManagerName(std::string* wm_name) { 140 bool GetWindowManagerName(std::string* wm_name) {
106 DCHECK(wm_name); 141 DCHECK(wm_name);
142 if (!SupportsEWMH())
143 return false;
144
107 int wm_window = 0; 145 int wm_window = 0;
108 if (!GetIntProperty(GetX11RootWindow(), 146 if (!GetIntProperty(GetX11RootWindow(),
109 "_NET_SUPPORTING_WM_CHECK", 147 "_NET_SUPPORTING_WM_CHECK",
110 &wm_window)) { 148 &wm_window)) {
111 return false; 149 return false;
112 } 150 }
113 151
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; 152 gfx::X11ErrorTracker err_tracker;
124 int wm_window_property = 0; 153 bool result = GetStringProperty(
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); 154 static_cast<XID>(wm_window), "_NET_WM_NAME", wm_name);
134 return !err_tracker.FoundNewError() && result; 155 return !err_tracker.FoundNewError() && result;
135 } 156 }
136 157
137 // A process wide singleton that manages the usage of X cursors. 158 // A process wide singleton that manages the usage of X cursors.
138 class XCursorCache { 159 class XCursorCache {
139 public: 160 public:
140 XCursorCache() {} 161 XCursorCache() {}
141 ~XCursorCache() { 162 ~XCursorCache() {
142 Clear(); 163 Clear();
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 // TODO(erg): Actually doing this correctly would require pulling out xrandr, 1292 // TODO(erg): Actually doing this correctly would require pulling out xrandr,
1272 // which we don't even do in the desktop screen yet. 1293 // which we don't even do in the desktop screen yet.
1273 ::XDisplay* display = gfx::GetXDisplay(); 1294 ::XDisplay* display = gfx::GetXDisplay();
1274 ::Screen* screen = DefaultScreenOfDisplay(display); 1295 ::Screen* screen = DefaultScreenOfDisplay(display);
1275 int width = WidthOfScreen(screen); 1296 int width = WidthOfScreen(screen);
1276 int height = HeightOfScreen(screen); 1297 int height = HeightOfScreen(screen);
1277 return window_rect.size() == gfx::Size(width, height); 1298 return window_rect.size() == gfx::Size(width, height);
1278 } 1299 }
1279 1300
1280 bool WmSupportsHint(XAtom atom) { 1301 bool WmSupportsHint(XAtom atom) {
1302 if (!SupportsEWMH())
1303 return false;
1304
1281 std::vector<XAtom> supported_atoms; 1305 std::vector<XAtom> supported_atoms;
1282 if (!GetAtomArrayProperty(GetX11RootWindow(), 1306 if (!GetAtomArrayProperty(GetX11RootWindow(),
1283 "_NET_SUPPORTED", 1307 "_NET_SUPPORTED",
1284 &supported_atoms)) { 1308 &supported_atoms)) {
1285 return false; 1309 return false;
1286 } 1310 }
1287 1311
1288 return std::find(supported_atoms.begin(), supported_atoms.end(), atom) != 1312 return std::find(supported_atoms.begin(), supported_atoms.end(), atom) !=
1289 supported_atoms.end(); 1313 supported_atoms.end();
1290 } 1314 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 << "request_code " << static_cast<int>(error_event.request_code) << ", " 1458 << "request_code " << static_cast<int>(error_event.request_code) << ", "
1435 << "minor_code " << static_cast<int>(error_event.minor_code) 1459 << "minor_code " << static_cast<int>(error_event.minor_code)
1436 << " (" << request_str << ")"; 1460 << " (" << request_str << ")";
1437 } 1461 }
1438 1462
1439 // ---------------------------------------------------------------------------- 1463 // ----------------------------------------------------------------------------
1440 // End of x11_util_internal.h 1464 // End of x11_util_internal.h
1441 1465
1442 1466
1443 } // namespace ui 1467 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/views/widget/desktop_aura/x11_desktop_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698