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> |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 "XdndProxy", // Proxy windows? | 121 "XdndProxy", // Proxy windows? |
122 "XdndSelection", | 122 "XdndSelection", |
123 "XdndStatus", | 123 "XdndStatus", |
124 "XdndTypeList", | 124 "XdndTypeList", |
125 NULL | 125 NULL |
126 }; | 126 }; |
127 | 127 |
128 const char kX11WindowRolePopup[] = "popup"; | 128 const char kX11WindowRolePopup[] = "popup"; |
129 const char kX11WindowRoleBubble[] = "bubble"; | 129 const char kX11WindowRoleBubble[] = "bubble"; |
130 | 130 |
| 131 // Returns the whole path from |window| to the root. |
| 132 std::vector<::Window> GetParentsList(XDisplay* xdisplay, ::Window window) { |
| 133 ::Window parent_win, root_win; |
| 134 Window* child_windows; |
| 135 unsigned int num_child_windows; |
| 136 std::vector<::Window> result; |
| 137 |
| 138 while (window) { |
| 139 result.push_back(window); |
| 140 if (!XQueryTree(xdisplay, window, |
| 141 &root_win, &parent_win, &child_windows, &num_child_windows)) |
| 142 break; |
| 143 if (child_windows) |
| 144 XFree(child_windows); |
| 145 window = parent_win; |
| 146 } |
| 147 return result; |
| 148 } |
| 149 |
131 } // namespace | 150 } // namespace |
132 | 151 |
133 //////////////////////////////////////////////////////////////////////////////// | 152 //////////////////////////////////////////////////////////////////////////////// |
134 // DesktopWindowTreeHostX11, public: | 153 // DesktopWindowTreeHostX11, public: |
135 | 154 |
136 DesktopWindowTreeHostX11::DesktopWindowTreeHostX11( | 155 DesktopWindowTreeHostX11::DesktopWindowTreeHostX11( |
137 internal::NativeWidgetDelegate* native_widget_delegate, | 156 internal::NativeWidgetDelegate* native_widget_delegate, |
138 DesktopNativeWidgetAura* desktop_native_widget_aura) | 157 DesktopNativeWidgetAura* desktop_native_widget_aura) |
139 : xdisplay_(gfx::GetXDisplay()), | 158 : xdisplay_(gfx::GetXDisplay()), |
140 xwindow_(0), | 159 xwindow_(0), |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 bool size_changed = bounds_in_pixels_.size() != size_in_pixels; | 427 bool size_changed = bounds_in_pixels_.size() != size_in_pixels; |
409 XResizeWindow(xdisplay_, xwindow_, size_in_pixels.width(), | 428 XResizeWindow(xdisplay_, xwindow_, size_in_pixels.width(), |
410 size_in_pixels.height()); | 429 size_in_pixels.height()); |
411 bounds_in_pixels_.set_size(size_in_pixels); | 430 bounds_in_pixels_.set_size(size_in_pixels); |
412 if (size_changed) { | 431 if (size_changed) { |
413 OnHostResized(size_in_pixels); | 432 OnHostResized(size_in_pixels); |
414 ResetWindowRegion(); | 433 ResetWindowRegion(); |
415 } | 434 } |
416 } | 435 } |
417 | 436 |
| 437 void DesktopWindowTreeHostX11::StackAbove(aura::Window* window) { |
| 438 if (window && window->GetRootWindow()) { |
| 439 ::Window window_below = window->GetHost()->GetAcceleratedWidget(); |
| 440 // Find all parent windows up to the root. |
| 441 std::vector<::Window> window_below_parents = |
| 442 GetParentsList(xdisplay_, window_below); |
| 443 std::vector<::Window> window_above_parents = |
| 444 GetParentsList(xdisplay_, xwindow_); |
| 445 |
| 446 // Find their common ancestor. |
| 447 auto it_below_window = window_below_parents.rbegin(); |
| 448 auto it_above_window = window_above_parents.rbegin(); |
| 449 for (; it_below_window != window_below_parents.rend() && |
| 450 it_above_window != window_above_parents.rend() && |
| 451 *it_below_window == *it_above_window; |
| 452 ++it_below_window, ++it_above_window) { |
| 453 } |
| 454 |
| 455 if (it_below_window != window_below_parents.rend() && |
| 456 it_above_window != window_above_parents.rend()) { |
| 457 // First stack |xwindow_| below so Z-order of |window| stays the same. |
| 458 ::Window windows[] = {*it_below_window, *it_above_window}; |
| 459 if (XRestackWindows(xdisplay_, windows, 2) == 0) { |
| 460 // Now stack them properly. |
| 461 std::swap(windows[0], windows[1]); |
| 462 XRestackWindows(xdisplay_, windows, 2); |
| 463 } |
| 464 } |
| 465 } |
| 466 } |
| 467 |
418 void DesktopWindowTreeHostX11::StackAtTop() { | 468 void DesktopWindowTreeHostX11::StackAtTop() { |
419 XRaiseWindow(xdisplay_, xwindow_); | 469 XRaiseWindow(xdisplay_, xwindow_); |
420 } | 470 } |
421 | 471 |
422 void DesktopWindowTreeHostX11::CenterWindow(const gfx::Size& size) { | 472 void DesktopWindowTreeHostX11::CenterWindow(const gfx::Size& size) { |
423 gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(size)).size(); | 473 gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(size)).size(); |
424 gfx::Rect parent_bounds_in_pixels = GetWorkAreaBoundsInPixels(); | 474 gfx::Rect parent_bounds_in_pixels = GetWorkAreaBoundsInPixels(); |
425 | 475 |
426 // If |window_|'s transient parent bounds are big enough to contain |size|, | 476 // If |window_|'s transient parent bounds are big enough to contain |size|, |
427 // use them instead. | 477 // use them instead. |
(...skipping 1571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 if (linux_ui) { | 2049 if (linux_ui) { |
2000 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); | 2050 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); |
2001 if (native_theme) | 2051 if (native_theme) |
2002 return native_theme; | 2052 return native_theme; |
2003 } | 2053 } |
2004 | 2054 |
2005 return ui::NativeTheme::instance(); | 2055 return ui::NativeTheme::instance(); |
2006 } | 2056 } |
2007 | 2057 |
2008 } // namespace views | 2058 } // namespace views |
OLD | NEW |