| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 LOG(ERROR) << "X IO error received (X server probably went away)"; | 89 LOG(ERROR) << "X IO error received (X server probably went away)"; |
| 90 _exit(1); | 90 _exit(1); |
| 91 } | 91 } |
| 92 | 92 |
| 93 // Note: The caller should free the resulting value data. | 93 // Note: The caller should free the resulting value data. |
| 94 bool GetProperty(XID window, const std::string& property_name, long max_length, | 94 bool GetProperty(XID window, const std::string& property_name, long max_length, |
| 95 XAtom* type, int* format, unsigned long* num_items, | 95 XAtom* type, int* format, unsigned long* num_items, |
| 96 unsigned char** property) { | 96 unsigned char** property) { |
| 97 XAtom property_atom = gfx::GetAtom(property_name.c_str()); | 97 XAtom property_atom = gfx::GetAtom(property_name.c_str()); |
| 98 unsigned long remaining_bytes = 0; | 98 unsigned long remaining_bytes = 0; |
| 99 return XGetWindowProperty(gfx::GetXDisplay(), | 99 return XGetWindowProperty(gfx::GetXDisplay(), window, property_atom, |
| 100 window, | 100 0, // offset into property data to read |
| 101 property_atom, | 101 max_length, // max length to get |
| 102 0, // offset into property data to read | 102 X11Constants::False, // deleted |
| 103 max_length, // max length to get | 103 AnyPropertyType, type, format, num_items, |
| 104 False, // deleted | 104 &remaining_bytes, property); |
| 105 AnyPropertyType, | |
| 106 type, | |
| 107 format, | |
| 108 num_items, | |
| 109 &remaining_bytes, | |
| 110 property); | |
| 111 } | 105 } |
| 112 | 106 |
| 113 bool SupportsEWMH() { | 107 bool SupportsEWMH() { |
| 114 static bool supports_ewmh = false; | 108 static bool supports_ewmh = false; |
| 115 static bool supports_ewmh_cached = false; | 109 static bool supports_ewmh_cached = false; |
| 116 if (!supports_ewmh_cached) { | 110 if (!supports_ewmh_cached) { |
| 117 supports_ewmh_cached = true; | 111 supports_ewmh_cached = true; |
| 118 | 112 |
| 119 int wm_window = 0u; | 113 int wm_window = 0u; |
| 120 if (!GetIntProperty(GetX11RootWindow(), | 114 if (!GetIntProperty(GetX11RootWindow(), |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 } | 617 } |
| 624 } | 618 } |
| 625 if (!is_in_shape_rects) | 619 if (!is_in_shape_rects) |
| 626 return false; | 620 return false; |
| 627 } | 621 } |
| 628 return true; | 622 return true; |
| 629 } | 623 } |
| 630 | 624 |
| 631 | 625 |
| 632 bool PropertyExists(XID window, const std::string& property_name) { | 626 bool PropertyExists(XID window, const std::string& property_name) { |
| 633 XAtom type = None; | 627 XAtom type = X11Constants::None; |
| 634 int format = 0; // size in bits of each item in 'property' | 628 int format = 0; // size in bits of each item in 'property' |
| 635 unsigned long num_items = 0; | 629 unsigned long num_items = 0; |
| 636 unsigned char* property = NULL; | 630 unsigned char* property = NULL; |
| 637 | 631 |
| 638 int result = GetProperty(window, property_name, 1, | 632 int result = GetProperty(window, property_name, 1, |
| 639 &type, &format, &num_items, &property); | 633 &type, &format, &num_items, &property); |
| 640 gfx::XScopedPtr<unsigned char> scoped_property(property); | 634 gfx::XScopedPtr<unsigned char> scoped_property(property); |
| 641 if (result != Success) | 635 if (result != X11Constants::Success) |
| 642 return false; | 636 return false; |
| 643 | 637 |
| 644 return num_items > 0; | 638 return num_items > 0; |
| 645 } | 639 } |
| 646 | 640 |
| 647 bool GetRawBytesOfProperty(XID window, | 641 bool GetRawBytesOfProperty(XID window, |
| 648 XAtom property, | 642 XAtom property, |
| 649 scoped_refptr<base::RefCountedMemory>* out_data, | 643 scoped_refptr<base::RefCountedMemory>* out_data, |
| 650 size_t* out_data_items, | 644 size_t* out_data_items, |
| 651 XAtom* out_type) { | 645 XAtom* out_type) { |
| 652 // Retrieve the data from our window. | 646 // Retrieve the data from our window. |
| 653 unsigned long nitems = 0; | 647 unsigned long nitems = 0; |
| 654 unsigned long nbytes = 0; | 648 unsigned long nbytes = 0; |
| 655 XAtom prop_type = None; | 649 XAtom prop_type = X11Constants::None; |
| 656 int prop_format = 0; | 650 int prop_format = 0; |
| 657 unsigned char* property_data = NULL; | 651 unsigned char* property_data = NULL; |
| 658 if (XGetWindowProperty(gfx::GetXDisplay(), window, property, | 652 if (XGetWindowProperty(gfx::GetXDisplay(), window, property, 0, |
| 659 0, 0x1FFFFFFF /* MAXINT32 / 4 */, False, | 653 0x1FFFFFFF /* MAXINT32 / 4 */, X11Constants::False, |
| 660 AnyPropertyType, &prop_type, &prop_format, | 654 AnyPropertyType, &prop_type, &prop_format, &nitems, |
| 661 &nitems, &nbytes, &property_data) != Success) { | 655 &nbytes, &property_data) != X11Constants::Success) { |
| 662 return false; | 656 return false; |
| 663 } | 657 } |
| 664 gfx::XScopedPtr<unsigned char> scoped_property(property_data); | 658 gfx::XScopedPtr<unsigned char> scoped_property(property_data); |
| 665 | 659 |
| 666 if (prop_type == None) | 660 if (prop_type == X11Constants::None) |
| 667 return false; | 661 return false; |
| 668 | 662 |
| 669 size_t bytes = 0; | 663 size_t bytes = 0; |
| 670 // So even though we should theoretically have nbytes (and we can't | 664 // So even though we should theoretically have nbytes (and we can't |
| 671 // pass NULL there), we need to manually calculate the byte length here | 665 // pass NULL there), we need to manually calculate the byte length here |
| 672 // because nbytes always returns zero. | 666 // because nbytes always returns zero. |
| 673 switch (prop_format) { | 667 switch (prop_format) { |
| 674 case 8: | 668 case 8: |
| 675 bytes = nitems; | 669 bytes = nitems; |
| 676 break; | 670 break; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 691 if (out_data_items) | 685 if (out_data_items) |
| 692 *out_data_items = nitems; | 686 *out_data_items = nitems; |
| 693 | 687 |
| 694 if (out_type) | 688 if (out_type) |
| 695 *out_type = prop_type; | 689 *out_type = prop_type; |
| 696 | 690 |
| 697 return true; | 691 return true; |
| 698 } | 692 } |
| 699 | 693 |
| 700 bool GetIntProperty(XID window, const std::string& property_name, int* value) { | 694 bool GetIntProperty(XID window, const std::string& property_name, int* value) { |
| 701 XAtom type = None; | 695 XAtom type = X11Constants::None; |
| 702 int format = 0; // size in bits of each item in 'property' | 696 int format = 0; // size in bits of each item in 'property' |
| 703 unsigned long num_items = 0; | 697 unsigned long num_items = 0; |
| 704 unsigned char* property = NULL; | 698 unsigned char* property = NULL; |
| 705 | 699 |
| 706 int result = GetProperty(window, property_name, 1, | 700 int result = GetProperty(window, property_name, 1, |
| 707 &type, &format, &num_items, &property); | 701 &type, &format, &num_items, &property); |
| 708 gfx::XScopedPtr<unsigned char> scoped_property(property); | 702 gfx::XScopedPtr<unsigned char> scoped_property(property); |
| 709 if (result != Success) | 703 if (result != X11Constants::Success) |
| 710 return false; | 704 return false; |
| 711 | 705 |
| 712 if (format != 32 || num_items != 1) | 706 if (format != 32 || num_items != 1) |
| 713 return false; | 707 return false; |
| 714 | 708 |
| 715 *value = static_cast<int>(*(reinterpret_cast<long*>(property))); | 709 *value = static_cast<int>(*(reinterpret_cast<long*>(property))); |
| 716 return true; | 710 return true; |
| 717 } | 711 } |
| 718 | 712 |
| 719 bool GetXIDProperty(XID window, const std::string& property_name, XID* value) { | 713 bool GetXIDProperty(XID window, const std::string& property_name, XID* value) { |
| 720 XAtom type = None; | 714 XAtom type = X11Constants::None; |
| 721 int format = 0; // size in bits of each item in 'property' | 715 int format = 0; // size in bits of each item in 'property' |
| 722 unsigned long num_items = 0; | 716 unsigned long num_items = 0; |
| 723 unsigned char* property = NULL; | 717 unsigned char* property = NULL; |
| 724 | 718 |
| 725 int result = GetProperty(window, property_name, 1, | 719 int result = GetProperty(window, property_name, 1, |
| 726 &type, &format, &num_items, &property); | 720 &type, &format, &num_items, &property); |
| 727 gfx::XScopedPtr<unsigned char> scoped_property(property); | 721 gfx::XScopedPtr<unsigned char> scoped_property(property); |
| 728 if (result != Success) | 722 if (result != X11Constants::Success) |
| 729 return false; | 723 return false; |
| 730 | 724 |
| 731 if (format != 32 || num_items != 1) | 725 if (format != 32 || num_items != 1) |
| 732 return false; | 726 return false; |
| 733 | 727 |
| 734 *value = *(reinterpret_cast<XID*>(property)); | 728 *value = *(reinterpret_cast<XID*>(property)); |
| 735 return true; | 729 return true; |
| 736 } | 730 } |
| 737 | 731 |
| 738 bool GetIntArrayProperty(XID window, | 732 bool GetIntArrayProperty(XID window, |
| 739 const std::string& property_name, | 733 const std::string& property_name, |
| 740 std::vector<int>* value) { | 734 std::vector<int>* value) { |
| 741 XAtom type = None; | 735 XAtom type = X11Constants::None; |
| 742 int format = 0; // size in bits of each item in 'property' | 736 int format = 0; // size in bits of each item in 'property' |
| 743 unsigned long num_items = 0; | 737 unsigned long num_items = 0; |
| 744 unsigned char* properties = NULL; | 738 unsigned char* properties = NULL; |
| 745 | 739 |
| 746 int result = GetProperty(window, property_name, | 740 int result = GetProperty(window, property_name, |
| 747 (~0L), // (all of them) | 741 (~0L), // (all of them) |
| 748 &type, &format, &num_items, &properties); | 742 &type, &format, &num_items, &properties); |
| 749 gfx::XScopedPtr<unsigned char> scoped_properties(properties); | 743 gfx::XScopedPtr<unsigned char> scoped_properties(properties); |
| 750 if (result != Success) | 744 if (result != X11Constants::Success) |
| 751 return false; | 745 return false; |
| 752 | 746 |
| 753 if (format != 32) | 747 if (format != 32) |
| 754 return false; | 748 return false; |
| 755 | 749 |
| 756 long* int_properties = reinterpret_cast<long*>(properties); | 750 long* int_properties = reinterpret_cast<long*>(properties); |
| 757 value->clear(); | 751 value->clear(); |
| 758 for (unsigned long i = 0; i < num_items; ++i) { | 752 for (unsigned long i = 0; i < num_items; ++i) { |
| 759 value->push_back(static_cast<int>(int_properties[i])); | 753 value->push_back(static_cast<int>(int_properties[i])); |
| 760 } | 754 } |
| 761 return true; | 755 return true; |
| 762 } | 756 } |
| 763 | 757 |
| 764 bool GetAtomArrayProperty(XID window, | 758 bool GetAtomArrayProperty(XID window, |
| 765 const std::string& property_name, | 759 const std::string& property_name, |
| 766 std::vector<XAtom>* value) { | 760 std::vector<XAtom>* value) { |
| 767 XAtom type = None; | 761 XAtom type = X11Constants::None; |
| 768 int format = 0; // size in bits of each item in 'property' | 762 int format = 0; // size in bits of each item in 'property' |
| 769 unsigned long num_items = 0; | 763 unsigned long num_items = 0; |
| 770 unsigned char* properties = NULL; | 764 unsigned char* properties = NULL; |
| 771 | 765 |
| 772 int result = GetProperty(window, property_name, | 766 int result = GetProperty(window, property_name, |
| 773 (~0L), // (all of them) | 767 (~0L), // (all of them) |
| 774 &type, &format, &num_items, &properties); | 768 &type, &format, &num_items, &properties); |
| 775 gfx::XScopedPtr<unsigned char> scoped_properties(properties); | 769 gfx::XScopedPtr<unsigned char> scoped_properties(properties); |
| 776 if (result != Success) | 770 if (result != X11Constants::Success) |
| 777 return false; | 771 return false; |
| 778 | 772 |
| 779 if (type != XA_ATOM) | 773 if (type != XA_ATOM) |
| 780 return false; | 774 return false; |
| 781 | 775 |
| 782 XAtom* atom_properties = reinterpret_cast<XAtom*>(properties); | 776 XAtom* atom_properties = reinterpret_cast<XAtom*>(properties); |
| 783 value->clear(); | 777 value->clear(); |
| 784 value->insert(value->begin(), atom_properties, atom_properties + num_items); | 778 value->insert(value->begin(), atom_properties, atom_properties + num_items); |
| 785 return true; | 779 return true; |
| 786 } | 780 } |
| 787 | 781 |
| 788 bool GetStringProperty( | 782 bool GetStringProperty( |
| 789 XID window, const std::string& property_name, std::string* value) { | 783 XID window, const std::string& property_name, std::string* value) { |
| 790 XAtom type = None; | 784 XAtom type = X11Constants::None; |
| 791 int format = 0; // size in bits of each item in 'property' | 785 int format = 0; // size in bits of each item in 'property' |
| 792 unsigned long num_items = 0; | 786 unsigned long num_items = 0; |
| 793 unsigned char* property = NULL; | 787 unsigned char* property = NULL; |
| 794 | 788 |
| 795 int result = GetProperty(window, property_name, 1024, | 789 int result = GetProperty(window, property_name, 1024, |
| 796 &type, &format, &num_items, &property); | 790 &type, &format, &num_items, &property); |
| 797 gfx::XScopedPtr<unsigned char> scoped_property(property); | 791 gfx::XScopedPtr<unsigned char> scoped_property(property); |
| 798 if (result != Success) | 792 if (result != X11Constants::Success) |
| 799 return false; | 793 return false; |
| 800 | 794 |
| 801 if (format != 8) | 795 if (format != 8) |
| 802 return false; | 796 return false; |
| 803 | 797 |
| 804 value->assign(reinterpret_cast<char*>(property), num_items); | 798 value->assign(reinterpret_cast<char*>(property), num_items); |
| 805 return true; | 799 return true; |
| 806 } | 800 } |
| 807 | 801 |
| 808 bool SetIntProperty(XID window, | 802 bool SetIntProperty(XID window, |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 } | 1032 } |
| 1039 } | 1033 } |
| 1040 | 1034 |
| 1041 bool GetXWindowStack(Window window, std::vector<XID>* windows) { | 1035 bool GetXWindowStack(Window window, std::vector<XID>* windows) { |
| 1042 windows->clear(); | 1036 windows->clear(); |
| 1043 | 1037 |
| 1044 Atom type; | 1038 Atom type; |
| 1045 int format; | 1039 int format; |
| 1046 unsigned long count; | 1040 unsigned long count; |
| 1047 unsigned char *data = NULL; | 1041 unsigned char *data = NULL; |
| 1048 if (GetProperty(window, | 1042 if (GetProperty(window, "_NET_CLIENT_LIST_STACKING", ~0L, &type, &format, |
| 1049 "_NET_CLIENT_LIST_STACKING", | 1043 &count, &data) != X11Constants::Success) { |
| 1050 ~0L, | |
| 1051 &type, | |
| 1052 &format, | |
| 1053 &count, | |
| 1054 &data) != Success) { | |
| 1055 return false; | 1044 return false; |
| 1056 } | 1045 } |
| 1057 gfx::XScopedPtr<unsigned char> scoped_data(data); | 1046 gfx::XScopedPtr<unsigned char> scoped_data(data); |
| 1058 | 1047 |
| 1059 bool result = false; | 1048 bool result = false; |
| 1060 if (type == XA_WINDOW && format == 32 && data && count > 0) { | 1049 if (type == XA_WINDOW && format == 32 && data && count > 0) { |
| 1061 result = true; | 1050 result = true; |
| 1062 XID* stack = reinterpret_cast<XID*>(data); | 1051 XID* stack = reinterpret_cast<XID*>(data); |
| 1063 for (long i = static_cast<long>(count) - 1; i >= 0; i--) | 1052 for (long i = static_cast<long>(count) - 1; i >= 0; i--) |
| 1064 windows->push_back(stack[i]); | 1053 windows->push_back(stack[i]); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 | 1155 |
| 1167 std::string GuessWindowManagerName() { | 1156 std::string GuessWindowManagerName() { |
| 1168 std::string name; | 1157 std::string name; |
| 1169 if (GetWindowManagerName(&name)) | 1158 if (GetWindowManagerName(&name)) |
| 1170 return name; | 1159 return name; |
| 1171 return "Unknown"; | 1160 return "Unknown"; |
| 1172 } | 1161 } |
| 1173 | 1162 |
| 1174 bool IsCompositingManagerPresent() { | 1163 bool IsCompositingManagerPresent() { |
| 1175 static bool is_compositing_manager_present = | 1164 static bool is_compositing_manager_present = |
| 1176 XGetSelectionOwner(gfx::GetXDisplay(), gfx::GetAtom("_NET_WM_CM_S0")) != | 1165 XGetSelectionOwner(gfx::GetXDisplay(), |
| 1177 None; | 1166 gfx::GetAtom("_NET_WM_CM_S0")) != X11Constants::None; |
| 1178 return is_compositing_manager_present; | 1167 return is_compositing_manager_present; |
| 1179 } | 1168 } |
| 1180 | 1169 |
| 1181 void SetDefaultX11ErrorHandlers() { | 1170 void SetDefaultX11ErrorHandlers() { |
| 1182 SetX11ErrorHandlers(NULL, NULL); | 1171 SetX11ErrorHandlers(NULL, NULL); |
| 1183 } | 1172 } |
| 1184 | 1173 |
| 1185 bool IsX11WindowFullScreen(XID window) { | 1174 bool IsX11WindowFullScreen(XID window) { |
| 1186 // If _NET_WM_STATE_FULLSCREEN is in _NET_SUPPORTED, use the presence or | 1175 // If _NET_WM_STATE_FULLSCREEN is in _NET_SUPPORTED, use the presence or |
| 1187 // absence of _NET_WM_STATE_FULLSCREEN in _NET_WM_STATE to determine | 1176 // absence of _NET_WM_STATE_FULLSCREEN in _NET_WM_STATE to determine |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 have_gpu_argb_visual_(false) { | 1359 have_gpu_argb_visual_(false) { |
| 1371 int visuals_len = 0; | 1360 int visuals_len = 0; |
| 1372 XVisualInfo visual_template; | 1361 XVisualInfo visual_template; |
| 1373 visual_template.screen = DefaultScreen(display_); | 1362 visual_template.screen = DefaultScreen(display_); |
| 1374 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( | 1363 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( |
| 1375 display_, VisualScreenMask, &visual_template, &visuals_len)); | 1364 display_, VisualScreenMask, &visual_template, &visuals_len)); |
| 1376 for (int i = 0; i < visuals_len; ++i) | 1365 for (int i = 0; i < visuals_len; ++i) |
| 1377 visuals_[visual_list[i].visualid].reset(new XVisualData(visual_list[i])); | 1366 visuals_[visual_list[i].visualid].reset(new XVisualData(visual_list[i])); |
| 1378 | 1367 |
| 1379 XAtom NET_WM_CM_S0 = gfx::GetAtom("_NET_WM_CM_S0"); | 1368 XAtom NET_WM_CM_S0 = gfx::GetAtom("_NET_WM_CM_S0"); |
| 1380 using_compositing_wm_ = XGetSelectionOwner(display_, NET_WM_CM_S0) != None; | 1369 using_compositing_wm_ = XGetSelectionOwner(display_, NET_WM_CM_S0) != X11Const
ants::None; |
| 1381 | 1370 |
| 1382 // Choose the opaque visual. | 1371 // Choose the opaque visual. |
| 1383 default_visual_id_ = | 1372 default_visual_id_ = |
| 1384 XVisualIDFromVisual(DefaultVisual(display_, DefaultScreen(display_))); | 1373 XVisualIDFromVisual(DefaultVisual(display_, DefaultScreen(display_))); |
| 1385 system_visual_id_ = default_visual_id_; | 1374 system_visual_id_ = default_visual_id_; |
| 1386 DCHECK(system_visual_id_); | 1375 DCHECK(system_visual_id_); |
| 1387 DCHECK(visuals_.find(system_visual_id_) != visuals_.end()); | 1376 DCHECK(visuals_.find(system_visual_id_) != visuals_.end()); |
| 1388 | 1377 |
| 1389 // Choose the transparent visual. | 1378 // Choose the transparent visual. |
| 1390 for (const auto& pair : visuals_) { | 1379 for (const auto& pair : visuals_) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 visual_info.visual, AllocNone); | 1455 visual_info.visual, AllocNone); |
| 1467 } | 1456 } |
| 1468 return colormap_; | 1457 return colormap_; |
| 1469 } | 1458 } |
| 1470 | 1459 |
| 1471 // ---------------------------------------------------------------------------- | 1460 // ---------------------------------------------------------------------------- |
| 1472 // End of x11_util_internal.h | 1461 // End of x11_util_internal.h |
| 1473 | 1462 |
| 1474 | 1463 |
| 1475 } // namespace ui | 1464 } // namespace ui |
| OLD | NEW |