| 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 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 5 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| 6 | 6 |
| 7 #include <X11/extensions/shape.h> | 7 #include <X11/extensions/shape.h> |
| 8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
| 9 #include <X11/Xatom.h> | 9 #include <X11/Xatom.h> |
| 10 #include <X11/Xregion.h> | 10 #include <X11/Xregion.h> |
| 11 #include <X11/Xutil.h> | 11 #include <X11/Xutil.h> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 18 #include "third_party/skia/include/core/SkPath.h" | 18 #include "third_party/skia/include/core/SkPath.h" |
| 19 #include "ui/aura/client/cursor_client.h" | 19 #include "ui/aura/client/cursor_client.h" |
| 20 #include "ui/aura/client/focus_client.h" | 20 #include "ui/aura/client/focus_client.h" |
| 21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 22 #include "ui/aura/window_event_dispatcher.h" | 22 #include "ui/aura/window_event_dispatcher.h" |
| 23 #include "ui/aura/window_property.h" | 23 #include "ui/aura/window_property.h" |
| 24 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" | 24 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" |
| 25 #include "ui/base/hit_test.h" | 25 #include "ui/base/hit_test.h" |
| 26 #include "ui/base/ime/input_method.h" | 26 #include "ui/base/ime/input_method.h" |
| 27 #include "ui/base/x/x11_util.h" | 27 #include "ui/base/x/x11_util.h" |
| 28 #include "ui/base/x/x11_util_internal.h" |
| 28 #include "ui/events/devices/x11/device_data_manager_x11.h" | 29 #include "ui/events/devices/x11/device_data_manager_x11.h" |
| 29 #include "ui/events/devices/x11/device_list_cache_x11.h" | 30 #include "ui/events/devices/x11/device_list_cache_x11.h" |
| 30 #include "ui/events/devices/x11/touch_factory_x11.h" | 31 #include "ui/events/devices/x11/touch_factory_x11.h" |
| 31 #include "ui/events/event_utils.h" | 32 #include "ui/events/event_utils.h" |
| 32 #include "ui/events/null_event_targeter.h" | 33 #include "ui/events/null_event_targeter.h" |
| 33 #include "ui/events/platform/platform_event_source.h" | 34 #include "ui/events/platform/platform_event_source.h" |
| 34 #include "ui/events/platform/x11/x11_event_source.h" | 35 #include "ui/events/platform/x11/x11_event_source.h" |
| 35 #include "ui/gfx/display.h" | 36 #include "ui/gfx/display.h" |
| 36 #include "ui/gfx/geometry/insets.h" | 37 #include "ui/gfx/geometry/insets.h" |
| 37 #include "ui/gfx/geometry/size_conversions.h" | 38 #include "ui/gfx/geometry/size_conversions.h" |
| (...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 swa.override_redirect = True; | 1111 swa.override_redirect = True; |
| 1111 window_type = atom_cache_.GetAtom("_NET_WM_WINDOW_TYPE_DND"); | 1112 window_type = atom_cache_.GetAtom("_NET_WM_WINDOW_TYPE_DND"); |
| 1112 break; | 1113 break; |
| 1113 default: | 1114 default: |
| 1114 window_type = atom_cache_.GetAtom("_NET_WM_WINDOW_TYPE_NORMAL"); | 1115 window_type = atom_cache_.GetAtom("_NET_WM_WINDOW_TYPE_NORMAL"); |
| 1115 break; | 1116 break; |
| 1116 } | 1117 } |
| 1117 if (swa.override_redirect) | 1118 if (swa.override_redirect) |
| 1118 attribute_mask |= CWOverrideRedirect; | 1119 attribute_mask |= CWOverrideRedirect; |
| 1119 | 1120 |
| 1120 // Detect whether we're running inside a compositing manager. If so, try to | 1121 Visual* visual; |
| 1121 // use the ARGB visual. Otherwise, just use our parent's visual. | 1122 int depth; |
| 1122 Visual* visual = CopyFromParent; | 1123 ui::ChooseVisualForWindow(&visual, &depth); |
| 1123 int depth = CopyFromParent; | 1124 if (depth == 32) { |
| 1124 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1125 attribute_mask |= CWColormap; |
| 1125 switches::kEnableTransparentVisuals) && | 1126 swa.colormap = |
| 1126 XGetSelectionOwner(xdisplay_, atom_cache_.GetAtom("_NET_WM_CM_S0")) != | 1127 XCreateColormap(xdisplay_, x_root_window_, visual, AllocNone); |
| 1127 None) { | |
| 1128 Visual* rgba_visual = GetARGBVisual(); | |
| 1129 if (rgba_visual) { | |
| 1130 visual = rgba_visual; | |
| 1131 depth = 32; | |
| 1132 | 1128 |
| 1133 attribute_mask |= CWColormap; | 1129 // x.org will BadMatch if we don't set a border when the depth isn't the |
| 1134 swa.colormap = XCreateColormap(xdisplay_, x_root_window_, visual, | 1130 // same as the parent depth. |
| 1135 AllocNone); | 1131 attribute_mask |= CWBorderPixel; |
| 1132 swa.border_pixel = 0; |
| 1136 | 1133 |
| 1137 // x.org will BadMatch if we don't set a border when the depth isn't the | 1134 use_argb_visual_ = true; |
| 1138 // same as the parent depth. | |
| 1139 attribute_mask |= CWBorderPixel; | |
| 1140 swa.border_pixel = 0; | |
| 1141 | |
| 1142 use_argb_visual_ = true; | |
| 1143 } | |
| 1144 } | 1135 } |
| 1145 | 1136 |
| 1146 bounds_in_pixels_ = ToPixelRect(params.bounds); | 1137 bounds_in_pixels_ = ToPixelRect(params.bounds); |
| 1147 bounds_in_pixels_.set_size(AdjustSize(bounds_in_pixels_.size())); | 1138 bounds_in_pixels_.set_size(AdjustSize(bounds_in_pixels_.size())); |
| 1148 xwindow_ = XCreateWindow(xdisplay_, x_root_window_, bounds_in_pixels_.x(), | 1139 xwindow_ = XCreateWindow(xdisplay_, x_root_window_, bounds_in_pixels_.x(), |
| 1149 bounds_in_pixels_.y(), bounds_in_pixels_.width(), | 1140 bounds_in_pixels_.y(), bounds_in_pixels_.width(), |
| 1150 bounds_in_pixels_.height(), | 1141 bounds_in_pixels_.height(), |
| 1151 0, // border width | 1142 0, // border width |
| 1152 depth, InputOutput, visual, attribute_mask, &swa); | 1143 depth, InputOutput, visual, attribute_mask, &swa); |
| 1153 if (ui::PlatformEventSource::GetInstance()) | 1144 if (ui::PlatformEventSource::GetInstance()) |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 data->push_back(height); | 1603 data->push_back(height); |
| 1613 | 1604 |
| 1614 const SkBitmap& bitmap = rep.sk_bitmap(); | 1605 const SkBitmap& bitmap = rep.sk_bitmap(); |
| 1615 SkAutoLockPixels locker(bitmap); | 1606 SkAutoLockPixels locker(bitmap); |
| 1616 | 1607 |
| 1617 for (int y = 0; y < height; ++y) | 1608 for (int y = 0; y < height; ++y) |
| 1618 for (int x = 0; x < width; ++x) | 1609 for (int x = 0; x < width; ++x) |
| 1619 data->push_back(bitmap.getColor(x, y)); | 1610 data->push_back(bitmap.getColor(x, y)); |
| 1620 } | 1611 } |
| 1621 | 1612 |
| 1622 Visual* DesktopWindowTreeHostX11::GetARGBVisual() { | |
| 1623 XVisualInfo visual_template; | |
| 1624 visual_template.screen = 0; | |
| 1625 | |
| 1626 int visuals_len; | |
| 1627 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( | |
| 1628 xdisplay_, VisualScreenMask, &visual_template, &visuals_len)); | |
| 1629 for (int i = 0; i < visuals_len; ++i) { | |
| 1630 // Why support only 8888 ARGB? Because it's all that GTK+ supports. In | |
| 1631 // gdkvisual-x11.cc, they look for this specific visual and use it for all | |
| 1632 // their alpha channel using needs. | |
| 1633 // | |
| 1634 // TODO(erg): While the following does find a valid visual, some GL drivers | |
| 1635 // don't believe that this has an alpha channel. According to marcheu@, | |
| 1636 // this should work on open source driver though. (It doesn't work with | |
| 1637 // NVidia's binaries currently.) http://crbug.com/369209 | |
| 1638 const XVisualInfo& info = visual_list[i]; | |
| 1639 if (info.depth == 32 && info.visual->red_mask == 0xff0000 && | |
| 1640 info.visual->green_mask == 0x00ff00 && | |
| 1641 info.visual->blue_mask == 0x0000ff) { | |
| 1642 return info.visual; | |
| 1643 } | |
| 1644 } | |
| 1645 | |
| 1646 return nullptr; | |
| 1647 } | |
| 1648 | |
| 1649 std::list<XID>& DesktopWindowTreeHostX11::open_windows() { | 1613 std::list<XID>& DesktopWindowTreeHostX11::open_windows() { |
| 1650 if (!open_windows_) | 1614 if (!open_windows_) |
| 1651 open_windows_ = new std::list<XID>(); | 1615 open_windows_ = new std::list<XID>(); |
| 1652 return *open_windows_; | 1616 return *open_windows_; |
| 1653 } | 1617 } |
| 1654 | 1618 |
| 1655 void DesktopWindowTreeHostX11::MapWindow(ui::WindowShowState show_state) { | 1619 void DesktopWindowTreeHostX11::MapWindow(ui::WindowShowState show_state) { |
| 1656 if (show_state != ui::SHOW_STATE_DEFAULT && | 1620 if (show_state != ui::SHOW_STATE_DEFAULT && |
| 1657 show_state != ui::SHOW_STATE_NORMAL && | 1621 show_state != ui::SHOW_STATE_NORMAL && |
| 1658 show_state != ui::SHOW_STATE_INACTIVE && | 1622 show_state != ui::SHOW_STATE_INACTIVE && |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2089 if (linux_ui) { | 2053 if (linux_ui) { |
| 2090 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); | 2054 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); |
| 2091 if (native_theme) | 2055 if (native_theme) |
| 2092 return native_theme; | 2056 return native_theme; |
| 2093 } | 2057 } |
| 2094 | 2058 |
| 2095 return ui::NativeTheme::instance(); | 2059 return ui::NativeTheme::instance(); |
| 2096 } | 2060 } |
| 2097 | 2061 |
| 2098 } // namespace views | 2062 } // namespace views |
| OLD | NEW |