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/platform/platform_event_source.h" | 33 #include "ui/events/platform/platform_event_source.h" |
33 #include "ui/events/platform/x11/x11_event_source.h" | 34 #include "ui/events/platform/x11/x11_event_source.h" |
34 #include "ui/gfx/display.h" | 35 #include "ui/gfx/display.h" |
35 #include "ui/gfx/geometry/insets.h" | 36 #include "ui/gfx/geometry/insets.h" |
36 #include "ui/gfx/geometry/size_conversions.h" | 37 #include "ui/gfx/geometry/size_conversions.h" |
37 #include "ui/gfx/image/image_skia.h" | 38 #include "ui/gfx/image/image_skia.h" |
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 swa.override_redirect = True; | 1109 swa.override_redirect = True; |
1109 window_type = atom_cache_.GetAtom("_NET_WM_WINDOW_TYPE_DND"); | 1110 window_type = atom_cache_.GetAtom("_NET_WM_WINDOW_TYPE_DND"); |
1110 break; | 1111 break; |
1111 default: | 1112 default: |
1112 window_type = atom_cache_.GetAtom("_NET_WM_WINDOW_TYPE_NORMAL"); | 1113 window_type = atom_cache_.GetAtom("_NET_WM_WINDOW_TYPE_NORMAL"); |
1113 break; | 1114 break; |
1114 } | 1115 } |
1115 if (swa.override_redirect) | 1116 if (swa.override_redirect) |
1116 attribute_mask |= CWOverrideRedirect; | 1117 attribute_mask |= CWOverrideRedirect; |
1117 | 1118 |
1118 // Detect whether we're running inside a compositing manager. If so, try to | 1119 Visual* visual; |
1119 // use the ARGB visual. Otherwise, just use our parent's visual. | |
1120 Visual* visual = CopyFromParent; | |
1121 int depth = CopyFromParent; | 1120 int depth = CopyFromParent; |
1122 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1121 ui::ChooseARGBVisualForWindow(&visual, &depth); |
1123 switches::kEnableTransparentVisuals) && | 1122 if (depth == 32) { |
1124 XGetSelectionOwner(xdisplay_, atom_cache_.GetAtom("_NET_WM_CM_S0")) != | 1123 attribute_mask |= CWColormap; |
1125 None) { | 1124 swa.colormap = |
1126 Visual* rgba_visual = GetARGBVisual(); | 1125 XCreateColormap(xdisplay_, x_root_window_, visual, AllocNone); |
1127 if (rgba_visual) { | |
1128 visual = rgba_visual; | |
1129 depth = 32; | |
1130 | 1126 |
1131 attribute_mask |= CWColormap; | 1127 // x.org will BadMatch if we don't set a border when the depth isn't the |
1132 swa.colormap = XCreateColormap(xdisplay_, x_root_window_, visual, | 1128 // same as the parent depth. |
1133 AllocNone); | 1129 attribute_mask |= CWBorderPixel; |
| 1130 swa.border_pixel = 0; |
1134 | 1131 |
1135 // x.org will BadMatch if we don't set a border when the depth isn't the | 1132 use_argb_visual_ = true; |
1136 // same as the parent depth. | |
1137 attribute_mask |= CWBorderPixel; | |
1138 swa.border_pixel = 0; | |
1139 | |
1140 use_argb_visual_ = true; | |
1141 } | |
1142 } | 1133 } |
1143 | 1134 |
1144 bounds_in_pixels_ = ToPixelRect(params.bounds); | 1135 bounds_in_pixels_ = ToPixelRect(params.bounds); |
1145 bounds_in_pixels_.set_size(AdjustSize(bounds_in_pixels_.size())); | 1136 bounds_in_pixels_.set_size(AdjustSize(bounds_in_pixels_.size())); |
1146 xwindow_ = XCreateWindow(xdisplay_, x_root_window_, bounds_in_pixels_.x(), | 1137 xwindow_ = XCreateWindow(xdisplay_, x_root_window_, bounds_in_pixels_.x(), |
1147 bounds_in_pixels_.y(), bounds_in_pixels_.width(), | 1138 bounds_in_pixels_.y(), bounds_in_pixels_.width(), |
1148 bounds_in_pixels_.height(), | 1139 bounds_in_pixels_.height(), |
1149 0, // border width | 1140 0, // border width |
1150 depth, InputOutput, visual, attribute_mask, &swa); | 1141 depth, InputOutput, visual, attribute_mask, &swa); |
1151 if (ui::PlatformEventSource::GetInstance()) | 1142 if (ui::PlatformEventSource::GetInstance()) |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 data->push_back(height); | 1600 data->push_back(height); |
1610 | 1601 |
1611 const SkBitmap& bitmap = rep.sk_bitmap(); | 1602 const SkBitmap& bitmap = rep.sk_bitmap(); |
1612 SkAutoLockPixels locker(bitmap); | 1603 SkAutoLockPixels locker(bitmap); |
1613 | 1604 |
1614 for (int y = 0; y < height; ++y) | 1605 for (int y = 0; y < height; ++y) |
1615 for (int x = 0; x < width; ++x) | 1606 for (int x = 0; x < width; ++x) |
1616 data->push_back(bitmap.getColor(x, y)); | 1607 data->push_back(bitmap.getColor(x, y)); |
1617 } | 1608 } |
1618 | 1609 |
1619 Visual* DesktopWindowTreeHostX11::GetARGBVisual() { | |
1620 XVisualInfo visual_template; | |
1621 visual_template.screen = 0; | |
1622 | |
1623 int visuals_len; | |
1624 gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( | |
1625 xdisplay_, VisualScreenMask, &visual_template, &visuals_len)); | |
1626 for (int i = 0; i < visuals_len; ++i) { | |
1627 // Why support only 8888 ARGB? Because it's all that GTK+ supports. In | |
1628 // gdkvisual-x11.cc, they look for this specific visual and use it for all | |
1629 // their alpha channel using needs. | |
1630 // | |
1631 // TODO(erg): While the following does find a valid visual, some GL drivers | |
1632 // don't believe that this has an alpha channel. According to marcheu@, | |
1633 // this should work on open source driver though. (It doesn't work with | |
1634 // NVidia's binaries currently.) http://crbug.com/369209 | |
1635 const XVisualInfo& info = visual_list[i]; | |
1636 if (info.depth == 32 && info.visual->red_mask == 0xff0000 && | |
1637 info.visual->green_mask == 0x00ff00 && | |
1638 info.visual->blue_mask == 0x0000ff) { | |
1639 return info.visual; | |
1640 } | |
1641 } | |
1642 | |
1643 return nullptr; | |
1644 } | |
1645 | |
1646 std::list<XID>& DesktopWindowTreeHostX11::open_windows() { | 1610 std::list<XID>& DesktopWindowTreeHostX11::open_windows() { |
1647 if (!open_windows_) | 1611 if (!open_windows_) |
1648 open_windows_ = new std::list<XID>(); | 1612 open_windows_ = new std::list<XID>(); |
1649 return *open_windows_; | 1613 return *open_windows_; |
1650 } | 1614 } |
1651 | 1615 |
1652 void DesktopWindowTreeHostX11::MapWindow(ui::WindowShowState show_state) { | 1616 void DesktopWindowTreeHostX11::MapWindow(ui::WindowShowState show_state) { |
1653 if (show_state != ui::SHOW_STATE_DEFAULT && | 1617 if (show_state != ui::SHOW_STATE_DEFAULT && |
1654 show_state != ui::SHOW_STATE_NORMAL && | 1618 show_state != ui::SHOW_STATE_NORMAL && |
1655 show_state != ui::SHOW_STATE_INACTIVE && | 1619 show_state != ui::SHOW_STATE_INACTIVE && |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2066 if (linux_ui) { | 2030 if (linux_ui) { |
2067 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); | 2031 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); |
2068 if (native_theme) | 2032 if (native_theme) |
2069 return native_theme; | 2033 return native_theme; |
2070 } | 2034 } |
2071 | 2035 |
2072 return ui::NativeTheme::instance(); | 2036 return ui::NativeTheme::instance(); |
2073 } | 2037 } |
2074 | 2038 |
2075 } // namespace views | 2039 } // namespace views |
OLD | NEW |