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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 FROM_HERE, NewRunnableFunction(LogErrorEventDescription, d, *e)); | 61 FROM_HERE, NewRunnableFunction(LogErrorEventDescription, d, *e)); |
62 return 0; | 62 return 0; |
63 } | 63 } |
64 | 64 |
65 int DefaultX11IOErrorHandler(Display* d) { | 65 int DefaultX11IOErrorHandler(Display* d) { |
66 // If there's an IO error it likely means the X server has gone away | 66 // If there's an IO error it likely means the X server has gone away |
67 LOG(ERROR) << "X IO Error detected"; | 67 LOG(ERROR) << "X IO Error detected"; |
68 _exit(1); | 68 _exit(1); |
69 } | 69 } |
70 | 70 |
71 XErrorHandler current_error_handler = DefaultX11ErrorHandler; | |
72 XErrorEvent* last_error_event = NULL; | |
73 | |
74 int BaseX11ErrorHandler(Display* d, XErrorEvent* e) { | |
75 last_error_event = e; | |
Ami GONE FROM CHROMIUM
2011/09/14 23:23:11
(this is the comment referenced from the .h commen
| |
76 return current_error_handler(d, e); | |
77 } | |
78 | |
71 // Note: The caller should free the resulting value data. | 79 // Note: The caller should free the resulting value data. |
72 bool GetProperty(XID window, const std::string& property_name, long max_length, | 80 bool GetProperty(XID window, const std::string& property_name, long max_length, |
73 Atom* type, int* format, unsigned long* num_items, | 81 Atom* type, int* format, unsigned long* num_items, |
74 unsigned char** property) { | 82 unsigned char** property) { |
75 Atom property_atom = gdk_x11_get_xatom_by_name_for_display( | 83 Atom property_atom = gdk_x11_get_xatom_by_name_for_display( |
76 gdk_display_get_default(), property_name.c_str()); | 84 gdk_display_get_default(), property_name.c_str()); |
77 | 85 |
78 unsigned long remaining_bytes = 0; | 86 unsigned long remaining_bytes = 0; |
79 return XGetWindowProperty(GetXDisplay(), | 87 return XGetWindowProperty(GetXDisplay(), |
80 window, | 88 window, |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 event.xclient.format = 32; | 680 event.xclient.format = 32; |
673 event.xclient.data.l[0] = desktop; | 681 event.xclient.data.l[0] = desktop; |
674 event.xclient.data.l[1] = 1; // source indication | 682 event.xclient.data.l[1] = 1; // source indication |
675 | 683 |
676 int result = XSendEvent(GetXDisplay(), GetX11RootWindow(), False, | 684 int result = XSendEvent(GetXDisplay(), GetX11RootWindow(), False, |
677 SubstructureNotifyMask, &event); | 685 SubstructureNotifyMask, &event); |
678 return result == Success; | 686 return result == Success; |
679 } | 687 } |
680 | 688 |
681 void SetDefaultX11ErrorHandlers() { | 689 void SetDefaultX11ErrorHandlers() { |
690 XSetErrorHandler(BaseX11ErrorHandler); | |
682 SetX11ErrorHandlers(NULL, NULL); | 691 SetX11ErrorHandlers(NULL, NULL); |
683 } | 692 } |
684 | 693 |
685 bool IsX11WindowFullScreen(XID window) { | 694 bool IsX11WindowFullScreen(XID window) { |
686 // First check if _NET_WM_STATE property contains _NET_WM_STATE_FULLSCREEN. | 695 // First check if _NET_WM_STATE property contains _NET_WM_STATE_FULLSCREEN. |
687 static Atom atom = gdk_x11_get_xatom_by_name_for_display( | 696 static Atom atom = gdk_x11_get_xatom_by_name_for_display( |
688 gdk_display_get_default(), "_NET_WM_STATE_FULLSCREEN"); | 697 gdk_display_get_default(), "_NET_WM_STATE_FULLSCREEN"); |
689 | 698 |
690 std::vector<Atom> atom_properties; | 699 std::vector<Atom> atom_properties; |
691 if (GetAtomArrayProperty(window, | 700 if (GetAtomArrayProperty(window, |
(...skipping 11 matching lines...) Expand all Loading... | |
703 gfx::Rect window_rect; | 712 gfx::Rect window_rect; |
704 if (!ui::GetWindowRect(window, &window_rect)) | 713 if (!ui::GetWindowRect(window, &window_rect)) |
705 return false; | 714 return false; |
706 | 715 |
707 return monitor_rect.x == window_rect.x() && | 716 return monitor_rect.x == window_rect.x() && |
708 monitor_rect.y == window_rect.y() && | 717 monitor_rect.y == window_rect.y() && |
709 monitor_rect.width == window_rect.width() && | 718 monitor_rect.width == window_rect.width() && |
710 monitor_rect.height == window_rect.height(); | 719 monitor_rect.height == window_rect.height(); |
711 } | 720 } |
712 | 721 |
722 XErrorEvent* GetLastX11Error(Display* display) { | |
723 XSync(display, False); | |
724 XErrorEvent* e = last_error_event; | |
725 last_error_event = NULL; | |
726 return e; | |
727 } | |
728 | |
713 // ---------------------------------------------------------------------------- | 729 // ---------------------------------------------------------------------------- |
714 // These functions are declared in x11_util_internal.h because they require | 730 // These functions are declared in x11_util_internal.h because they require |
715 // XLib.h to be included, and it conflicts with many other headers. | 731 // XLib.h to be included, and it conflicts with many other headers. |
716 XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { | 732 XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { |
717 static XRenderPictFormat* pictformat = NULL; | 733 static XRenderPictFormat* pictformat = NULL; |
718 if (pictformat) | 734 if (pictformat) |
719 return pictformat; | 735 return pictformat; |
720 | 736 |
721 // First look for a 32-bit format which ignores the alpha value | 737 // First look for a 32-bit format which ignores the alpha value |
722 XRenderPictFormat templ; | 738 XRenderPictFormat templ; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
781 // always blowing away the cache. If we are, then we should figure out why | 797 // always blowing away the cache. If we are, then we should figure out why |
782 // and make it bigger. | 798 // and make it bigger. |
783 NOTREACHED(); | 799 NOTREACHED(); |
784 } | 800 } |
785 | 801 |
786 return pictformat; | 802 return pictformat; |
787 } | 803 } |
788 | 804 |
789 void SetX11ErrorHandlers(XErrorHandler error_handler, | 805 void SetX11ErrorHandlers(XErrorHandler error_handler, |
790 XIOErrorHandler io_error_handler) { | 806 XIOErrorHandler io_error_handler) { |
791 XSetErrorHandler(error_handler ? error_handler : DefaultX11ErrorHandler); | 807 current_error_handler = error_handler ? |
792 XSetIOErrorHandler( | 808 error_handler : DefaultX11ErrorHandler; |
793 io_error_handler ? io_error_handler : DefaultX11IOErrorHandler); | 809 XSetIOErrorHandler(io_error_handler ? |
810 io_error_handler : DefaultX11IOErrorHandler); | |
794 } | 811 } |
795 | 812 |
796 void LogErrorEventDescription(Display* dpy, | 813 void LogErrorEventDescription(Display* dpy, |
797 const XErrorEvent& error_event) { | 814 const XErrorEvent& error_event) { |
798 char error_str[256]; | 815 char error_str[256]; |
799 char request_str[256]; | 816 char request_str[256]; |
800 | 817 |
801 XGetErrorText(dpy, error_event.error_code, error_str, sizeof(error_str)); | 818 XGetErrorText(dpy, error_event.error_code, error_str, sizeof(error_str)); |
802 | 819 |
803 strncpy(request_str, "Unknown", sizeof(request_str)); | 820 strncpy(request_str, "Unknown", sizeof(request_str)); |
(...skipping 29 matching lines...) Expand all Loading... | |
833 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 850 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
834 << "minor_code " << static_cast<int>(error_event.minor_code) | 851 << "minor_code " << static_cast<int>(error_event.minor_code) |
835 << " (" << request_str << ")"; | 852 << " (" << request_str << ")"; |
836 } | 853 } |
837 | 854 |
838 // ---------------------------------------------------------------------------- | 855 // ---------------------------------------------------------------------------- |
839 // End of x11_util_internal.h | 856 // End of x11_util_internal.h |
840 | 857 |
841 | 858 |
842 } // namespace ui | 859 } // namespace ui |
OLD | NEW |