OLD | NEW |
1 // Copyright (c) 2010 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 "app/x11_util.h" | 9 #include "ui/base/x/x11_util.h" |
10 | 10 |
11 #include <gdk/gdk.h> | 11 #include <gdk/gdk.h> |
12 #include <gdk/gdkx.h> | 12 #include <gdk/gdkx.h> |
13 #include <gtk/gtk.h> | 13 #include <gtk/gtk.h> |
14 | 14 |
15 #include <sys/ipc.h> | 15 #include <sys/ipc.h> |
16 #include <sys/shm.h> | 16 #include <sys/shm.h> |
17 | 17 |
18 #include <list> | 18 #include <list> |
19 #include <set> | 19 #include <set> |
20 | 20 |
21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
22 #include "base/logging.h" | 22 #include "base/logging.h" |
23 #include "base/stringprintf.h" | 23 #include "base/stringprintf.h" |
24 #include "base/string_number_conversions.h" | 24 #include "base/string_number_conversions.h" |
25 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
26 #include "app/x11_util_internal.h" | |
27 #include "gfx/rect.h" | 26 #include "gfx/rect.h" |
28 #include "gfx/size.h" | 27 #include "gfx/size.h" |
| 28 #include "ui/base/x/x11_util_internal.h" |
29 | 29 |
30 namespace x11_util { | 30 namespace ui { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Used to cache the XRenderPictFormat for a visual/display pair. | 34 // Used to cache the XRenderPictFormat for a visual/display pair. |
35 struct CachedPictFormat { | 35 struct CachedPictFormat { |
36 bool equals(Display* display, Visual* visual) const { | 36 bool equals(Display* display, Visual* visual) const { |
37 return display == this->display && visual == this->visual; | 37 return display == this->display && visual == this->visual; |
38 } | 38 } |
39 | 39 |
40 Display* display; | 40 Display* display; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 XID* children = NULL; | 334 XID* children = NULL; |
335 unsigned int num_children = 0; | 335 unsigned int num_children = 0; |
336 XQueryTree(GetXDisplay(), window, &root, &parent, &children, &num_children); | 336 XQueryTree(GetXDisplay(), window, &root, &parent, &children, &num_children); |
337 if (children) | 337 if (children) |
338 XFree(children); | 338 XFree(children); |
339 return parent; | 339 return parent; |
340 } | 340 } |
341 | 341 |
342 XID GetHighestAncestorWindow(XID window, XID root) { | 342 XID GetHighestAncestorWindow(XID window, XID root) { |
343 while (true) { | 343 while (true) { |
344 XID parent = x11_util::GetParentWindow(window); | 344 XID parent = GetParentWindow(window); |
345 if (parent == None) | 345 if (parent == None) |
346 return None; | 346 return None; |
347 if (parent == root) | 347 if (parent == root) |
348 return window; | 348 return window; |
349 window = parent; | 349 window = parent; |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 bool GetWindowDesktop(XID window, int* desktop) { | 353 bool GetWindowDesktop(XID window, int* desktop) { |
354 return GetIntProperty(window, "_NET_WM_DESKTOP", desktop); | 354 return GetIntProperty(window, "_NET_WM_DESKTOP", desktop); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 if (children) | 637 if (children) |
638 XFree(children); | 638 XFree(children); |
639 | 639 |
640 *parent_is_root = root_window == *parent_window; | 640 *parent_is_root = root_window == *parent_window; |
641 return true; | 641 return true; |
642 } | 642 } |
643 | 643 |
644 bool GetWindowManagerName(std::string* wm_name) { | 644 bool GetWindowManagerName(std::string* wm_name) { |
645 DCHECK(wm_name); | 645 DCHECK(wm_name); |
646 int wm_window = 0; | 646 int wm_window = 0; |
647 if (!x11_util::GetIntProperty(x11_util::GetX11RootWindow(), | 647 if (!GetIntProperty(GetX11RootWindow(), |
648 "_NET_SUPPORTING_WM_CHECK", | 648 "_NET_SUPPORTING_WM_CHECK", |
649 &wm_window)) { | 649 &wm_window)) { |
650 return false; | 650 return false; |
651 } | 651 } |
652 | 652 |
653 // It's possible that a window manager started earlier in this X session left | 653 // It's possible that a window manager started earlier in this X session left |
654 // a stale _NET_SUPPORTING_WM_CHECK property when it was replaced by a | 654 // a stale _NET_SUPPORTING_WM_CHECK property when it was replaced by a |
655 // non-EWMH window manager, so we trap errors in the following requests to | 655 // non-EWMH window manager, so we trap errors in the following requests to |
656 // avoid crashes (issue 23860). | 656 // avoid crashes (issue 23860). |
657 | 657 |
658 // EWMH requires the supporting-WM window to also have a | 658 // EWMH requires the supporting-WM window to also have a |
659 // _NET_SUPPORTING_WM_CHECK property pointing to itself (to avoid a stale | 659 // _NET_SUPPORTING_WM_CHECK property pointing to itself (to avoid a stale |
660 // property referencing an ID that's been recycled for another window), so we | 660 // property referencing an ID that's been recycled for another window), so we |
661 // check that too. | 661 // check that too. |
662 gdk_error_trap_push(); | 662 gdk_error_trap_push(); |
663 int wm_window_property = 0; | 663 int wm_window_property = 0; |
664 bool result = x11_util::GetIntProperty( | 664 bool result = GetIntProperty( |
665 wm_window, "_NET_SUPPORTING_WM_CHECK", &wm_window_property); | 665 wm_window, "_NET_SUPPORTING_WM_CHECK", &wm_window_property); |
666 gdk_flush(); | 666 gdk_flush(); |
667 bool got_error = gdk_error_trap_pop(); | 667 bool got_error = gdk_error_trap_pop(); |
668 if (got_error || !result || wm_window_property != wm_window) | 668 if (got_error || !result || wm_window_property != wm_window) |
669 return false; | 669 return false; |
670 | 670 |
671 gdk_error_trap_push(); | 671 gdk_error_trap_push(); |
672 result = x11_util::GetStringProperty( | 672 result = GetStringProperty( |
673 static_cast<XID>(wm_window), "_NET_WM_NAME", wm_name); | 673 static_cast<XID>(wm_window), "_NET_WM_NAME", wm_name); |
674 gdk_flush(); | 674 gdk_flush(); |
675 got_error = gdk_error_trap_pop(); | 675 got_error = gdk_error_trap_pop(); |
676 return !got_error && result; | 676 return !got_error && result; |
677 } | 677 } |
678 | 678 |
679 static cairo_status_t SnapshotCallback( | 679 static cairo_status_t SnapshotCallback( |
680 void *closure, const unsigned char *data, unsigned int length) { | 680 void *closure, const unsigned char *data, unsigned int length) { |
681 std::vector<unsigned char>* png_representation = | 681 std::vector<unsigned char>* png_representation = |
682 static_cast<std::vector<unsigned char>*>(closure); | 682 static_cast<std::vector<unsigned char>*>(closure); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 return base::StringPrintf( | 870 return base::StringPrintf( |
871 "X Error detected: serial %lu, error_code %u (%s), " | 871 "X Error detected: serial %lu, error_code %u (%s), " |
872 "request_code %u minor_code %u (%s)", | 872 "request_code %u minor_code %u (%s)", |
873 error_event->serial, error_event->error_code, error_str, | 873 error_event->serial, error_event->error_code, error_str, |
874 error_event->request_code, error_event->minor_code, request_str); | 874 error_event->request_code, error_event->minor_code, request_str); |
875 } | 875 } |
876 // ---------------------------------------------------------------------------- | 876 // ---------------------------------------------------------------------------- |
877 // End of x11_util_internal.h | 877 // End of x11_util_internal.h |
878 | 878 |
879 | 879 |
880 } // namespace x11_util | 880 } // namespace ui |
OLD | NEW |