| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 base::Bind(&LogErrorEventDescription, d, *e)); | 73 base::Bind(&LogErrorEventDescription, d, *e)); |
| 74 return 0; | 74 return 0; |
| 75 } | 75 } |
| 76 | 76 |
| 77 int DefaultX11IOErrorHandler(Display* d) { | 77 int DefaultX11IOErrorHandler(Display* d) { |
| 78 // If there's an IO error it likely means the X server has gone away | 78 // If there's an IO error it likely means the X server has gone away |
| 79 LOG(ERROR) << "X IO Error detected"; | 79 LOG(ERROR) << "X IO Error detected"; |
| 80 _exit(1); | 80 _exit(1); |
| 81 } | 81 } |
| 82 | 82 |
| 83 Atom GetAtom(const char* name) { | |
| 84 #if defined(TOOLKIT_USES_GTK) | |
| 85 return gdk_x11_get_xatom_by_name_for_display( | |
| 86 gdk_display_get_default(), name); | |
| 87 #else | |
| 88 return XInternAtom(GetXDisplay(), name, false); | |
| 89 #endif | |
| 90 } | |
| 91 | |
| 92 // Note: The caller should free the resulting value data. | 83 // Note: The caller should free the resulting value data. |
| 93 bool GetProperty(XID window, const std::string& property_name, long max_length, | 84 bool GetProperty(XID window, const std::string& property_name, long max_length, |
| 94 Atom* type, int* format, unsigned long* num_items, | 85 Atom* type, int* format, unsigned long* num_items, |
| 95 unsigned char** property) { | 86 unsigned char** property) { |
| 96 Atom property_atom = GetAtom(property_name.c_str()); | 87 Atom property_atom = GetAtom(property_name.c_str()); |
| 97 unsigned long remaining_bytes = 0; | 88 unsigned long remaining_bytes = 0; |
| 98 return XGetWindowProperty(GetXDisplay(), | 89 return XGetWindowProperty(GetXDisplay(), |
| 99 window, | 90 window, |
| 100 property_atom, | 91 property_atom, |
| 101 0, // offset into property data to read | 92 0, // offset into property data to read |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 if (format != 8) { | 413 if (format != 8) { |
| 423 XFree(property); | 414 XFree(property); |
| 424 return false; | 415 return false; |
| 425 } | 416 } |
| 426 | 417 |
| 427 value->assign(reinterpret_cast<char*>(property), num_items); | 418 value->assign(reinterpret_cast<char*>(property), num_items); |
| 428 XFree(property); | 419 XFree(property); |
| 429 return true; | 420 return true; |
| 430 } | 421 } |
| 431 | 422 |
| 423 Atom GetAtom(const char* name) { |
| 424 #if defined(TOOLKIT_USES_GTK) |
| 425 return gdk_x11_get_xatom_by_name_for_display( |
| 426 gdk_display_get_default(), name); |
| 427 #else |
| 428 return XInternAtom(GetXDisplay(), name, false); |
| 429 #endif |
| 430 } |
| 431 |
| 432 XID GetParentWindow(XID window) { | 432 XID GetParentWindow(XID window) { |
| 433 XID root = None; | 433 XID root = None; |
| 434 XID parent = None; | 434 XID parent = None; |
| 435 XID* children = NULL; | 435 XID* children = NULL; |
| 436 unsigned int num_children = 0; | 436 unsigned int num_children = 0; |
| 437 XQueryTree(GetXDisplay(), window, &root, &parent, &children, &num_children); | 437 XQueryTree(GetXDisplay(), window, &root, &parent, &children, &num_children); |
| 438 if (children) | 438 if (children) |
| 439 XFree(children); | 439 XFree(children); |
| 440 return parent; | 440 return parent; |
| 441 } | 441 } |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 932 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
| 933 << "minor_code " << static_cast<int>(error_event.minor_code) | 933 << "minor_code " << static_cast<int>(error_event.minor_code) |
| 934 << " (" << request_str << ")"; | 934 << " (" << request_str << ")"; |
| 935 } | 935 } |
| 936 | 936 |
| 937 // ---------------------------------------------------------------------------- | 937 // ---------------------------------------------------------------------------- |
| 938 // End of x11_util_internal.h | 938 // End of x11_util_internal.h |
| 939 | 939 |
| 940 | 940 |
| 941 } // namespace ui | 941 } // namespace ui |
| OLD | NEW |