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 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 int result = XSendEvent(GetXDisplay(), GetX11RootWindow(), False, | 1302 int result = XSendEvent(GetXDisplay(), GetX11RootWindow(), False, |
1303 SubstructureNotifyMask, &event); | 1303 SubstructureNotifyMask, &event); |
1304 return result == Success; | 1304 return result == Success; |
1305 } | 1305 } |
1306 | 1306 |
1307 void SetDefaultX11ErrorHandlers() { | 1307 void SetDefaultX11ErrorHandlers() { |
1308 SetX11ErrorHandlers(NULL, NULL); | 1308 SetX11ErrorHandlers(NULL, NULL); |
1309 } | 1309 } |
1310 | 1310 |
1311 bool IsX11WindowFullScreen(XID window) { | 1311 bool IsX11WindowFullScreen(XID window) { |
1312 // First check if _NET_WM_STATE property contains _NET_WM_STATE_FULLSCREEN. | 1312 // If _NET_WM_STATE_FULLSCREEN is in _NET_SUPPORTED, use the presence or |
1313 static Atom atom = GetAtom("_NET_WM_STATE_FULLSCREEN"); | 1313 // absence of _NET_WM_STATE_FULLSCREEN in _NET_WM_STATE to determine |
| 1314 // whether we're fullscreen. |
| 1315 std::vector<Atom> supported_atoms; |
| 1316 if (GetAtomArrayProperty(GetX11RootWindow(), |
| 1317 "_NET_SUPPORTED", |
| 1318 &supported_atoms)) { |
| 1319 Atom atom = GetAtom("_NET_WM_STATE_FULLSCREEN"); |
1314 | 1320 |
1315 std::vector<Atom> atom_properties; | 1321 if (std::find(supported_atoms.begin(), supported_atoms.end(), atom) |
1316 if (GetAtomArrayProperty(window, | 1322 != supported_atoms.end()) { |
1317 "_NET_WM_STATE", | 1323 std::vector<Atom> atom_properties; |
1318 &atom_properties) && | 1324 if (GetAtomArrayProperty(window, |
1319 std::find(atom_properties.begin(), atom_properties.end(), atom) | 1325 "_NET_WM_STATE", |
1320 != atom_properties.end()) | 1326 &atom_properties)) { |
1321 return true; | 1327 return std::find(atom_properties.begin(), atom_properties.end(), atom) |
| 1328 != atom_properties.end(); |
| 1329 } |
| 1330 } |
| 1331 } |
| 1332 |
| 1333 gfx::Rect window_rect; |
| 1334 if (!ui::GetWindowRect(window, &window_rect)) |
| 1335 return false; |
1322 | 1336 |
1323 #if defined(TOOLKIT_GTK) | 1337 #if defined(TOOLKIT_GTK) |
1324 // As the last resort, check if the window size is as large as the main | 1338 // As the last resort, check if the window size is as large as the main |
1325 // screen. | 1339 // screen. |
1326 GdkRectangle monitor_rect; | 1340 GdkRectangle monitor_rect; |
1327 gdk_screen_get_monitor_geometry(gdk_screen_get_default(), 0, &monitor_rect); | 1341 gdk_screen_get_monitor_geometry(gdk_screen_get_default(), 0, &monitor_rect); |
1328 | 1342 |
1329 gfx::Rect window_rect; | |
1330 if (!ui::GetWindowRect(window, &window_rect)) | |
1331 return false; | |
1332 | |
1333 return monitor_rect.x == window_rect.x() && | 1343 return monitor_rect.x == window_rect.x() && |
1334 monitor_rect.y == window_rect.y() && | 1344 monitor_rect.y == window_rect.y() && |
1335 monitor_rect.width == window_rect.width() && | 1345 monitor_rect.width == window_rect.width() && |
1336 monitor_rect.height == window_rect.height(); | 1346 monitor_rect.height == window_rect.height(); |
1337 #else | 1347 #else |
1338 NOTIMPLEMENTED(); | 1348 // We can't use gfx::Screen here because we don't have an aura::Window. So |
1339 return false; | 1349 // instead just look at the size of the default display. |
| 1350 // |
| 1351 // TODO(erg): Actually doing this correctly would require pulling out xrandr, |
| 1352 // which we don't even do in the desktop screen yet. |
| 1353 ::Display* display = ui::GetXDisplay(); |
| 1354 ::Screen* screen = DefaultScreenOfDisplay(display); |
| 1355 int width = WidthOfScreen(screen); |
| 1356 int height = HeightOfScreen(screen); |
| 1357 return window_rect.size() == gfx::Size(width, height); |
1340 #endif | 1358 #endif |
1341 } | 1359 } |
1342 | 1360 |
1343 bool IsMotionEvent(XEvent* event) { | 1361 bool IsMotionEvent(XEvent* event) { |
1344 int type = event->type; | 1362 int type = event->type; |
1345 if (type == GenericEvent) | 1363 if (type == GenericEvent) |
1346 type = event->xgeneric.evtype; | 1364 type = event->xgeneric.evtype; |
1347 return type == MotionNotify; | 1365 return type == MotionNotify; |
1348 } | 1366 } |
1349 | 1367 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1540 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1558 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1541 << "minor_code " << static_cast<int>(error_event.minor_code) | 1559 << "minor_code " << static_cast<int>(error_event.minor_code) |
1542 << " (" << request_str << ")"; | 1560 << " (" << request_str << ")"; |
1543 } | 1561 } |
1544 | 1562 |
1545 // ---------------------------------------------------------------------------- | 1563 // ---------------------------------------------------------------------------- |
1546 // End of x11_util_internal.h | 1564 // End of x11_util_internal.h |
1547 | 1565 |
1548 | 1566 |
1549 } // namespace ui | 1567 } // namespace ui |
OLD | NEW |