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 12 matching lines...) Expand all Loading... |
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/x/x11_util.h" | 26 #include "ui/base/x/x11_util.h" |
27 #include "ui/events/event_utils.h" | 27 #include "ui/events/event_utils.h" |
28 #include "ui/events/platform/platform_event_source.h" | 28 #include "ui/events/platform/platform_event_source.h" |
29 #include "ui/events/platform/x11/x11_event_source.h" | 29 #include "ui/events/platform/x11/x11_event_source.h" |
30 #include "ui/events/x/device_data_manager_x11.h" | 30 #include "ui/events/x/device_data_manager_x11.h" |
31 #include "ui/events/x/device_list_cache_x.h" | 31 #include "ui/events/x/device_list_cache_x.h" |
32 #include "ui/events/x/touch_factory_x11.h" | 32 #include "ui/events/x/touch_factory_x11.h" |
| 33 #include "ui/gfx/display.h" |
33 #include "ui/gfx/image/image_skia.h" | 34 #include "ui/gfx/image/image_skia.h" |
34 #include "ui/gfx/image/image_skia_rep.h" | 35 #include "ui/gfx/image/image_skia_rep.h" |
35 #include "ui/gfx/insets.h" | 36 #include "ui/gfx/insets.h" |
36 #include "ui/gfx/path.h" | 37 #include "ui/gfx/path.h" |
37 #include "ui/gfx/path_x11.h" | 38 #include "ui/gfx/path_x11.h" |
38 #include "ui/gfx/screen.h" | 39 #include "ui/gfx/screen.h" |
39 #include "ui/native_theme/native_theme.h" | 40 #include "ui/native_theme/native_theme.h" |
40 #include "ui/views/corewm/tooltip_aura.h" | 41 #include "ui/views/corewm/tooltip_aura.h" |
41 #include "ui/views/ime/input_method.h" | 42 #include "ui/views/ime/input_method.h" |
42 #include "ui/views/linux_ui/linux_ui.h" | 43 #include "ui/views/linux_ui/linux_ui.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 const gfx::Rect& restored_bounds) { | 379 const gfx::Rect& restored_bounds) { |
379 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); | 380 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); |
380 // Enforce |restored_bounds_| since calling Maximize() could have reset it. | 381 // Enforce |restored_bounds_| since calling Maximize() could have reset it. |
381 restored_bounds_ = restored_bounds; | 382 restored_bounds_ = restored_bounds; |
382 } | 383 } |
383 | 384 |
384 bool DesktopWindowTreeHostX11::IsVisible() const { | 385 bool DesktopWindowTreeHostX11::IsVisible() const { |
385 return window_mapped_; | 386 return window_mapped_; |
386 } | 387 } |
387 | 388 |
388 void DesktopWindowTreeHostX11::SetSize(const gfx::Size& size) { | 389 void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) { |
| 390 gfx::Size size = AdjustSize(requested_size); |
389 bool size_changed = bounds_.size() != size; | 391 bool size_changed = bounds_.size() != size; |
390 XResizeWindow(xdisplay_, xwindow_, size.width(), size.height()); | 392 XResizeWindow(xdisplay_, xwindow_, size.width(), size.height()); |
391 bounds_.set_size(size); | 393 bounds_.set_size(size); |
392 if (size_changed) { | 394 if (size_changed) { |
393 OnHostResized(size); | 395 OnHostResized(size); |
394 ResetWindowRegion(); | 396 ResetWindowRegion(); |
395 } | 397 } |
396 } | 398 } |
397 | 399 |
398 void DesktopWindowTreeHostX11::StackAtTop() { | 400 void DesktopWindowTreeHostX11::StackAtTop() { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 | 515 |
514 ReleaseCapture(); | 516 ReleaseCapture(); |
515 X11DesktopHandler::get()->DeactivateWindow(xwindow_); | 517 X11DesktopHandler::get()->DeactivateWindow(xwindow_); |
516 } | 518 } |
517 | 519 |
518 bool DesktopWindowTreeHostX11::IsActive() const { | 520 bool DesktopWindowTreeHostX11::IsActive() const { |
519 return X11DesktopHandler::get()->IsActiveWindow(xwindow_); | 521 return X11DesktopHandler::get()->IsActiveWindow(xwindow_); |
520 } | 522 } |
521 | 523 |
522 void DesktopWindowTreeHostX11::Maximize() { | 524 void DesktopWindowTreeHostX11::Maximize() { |
| 525 if (HasWMSpecProperty("_NET_WM_STATE_FULLSCREEN")) { |
| 526 // Unfullscreen the window if it is fullscreen. |
| 527 SetWMSpecState(false, |
| 528 atom_cache_.GetAtom("_NET_WM_STATE_FULLSCREEN"), |
| 529 None); |
| 530 |
| 531 // Resize the window so that it does not have the same size as a monitor. |
| 532 // (Otherwise, some window managers immediately put the window back in |
| 533 // fullscreen mode). |
| 534 gfx::Rect adjusted_bounds(bounds_.origin(), AdjustSize(bounds_.size())); |
| 535 if (adjusted_bounds != bounds_) |
| 536 SetBounds(adjusted_bounds); |
| 537 } |
| 538 |
523 // When we are in the process of requesting to maximize a window, we can | 539 // When we are in the process of requesting to maximize a window, we can |
524 // accurately keep track of our restored bounds instead of relying on the | 540 // accurately keep track of our restored bounds instead of relying on the |
525 // heuristics that are in the PropertyNotify and ConfigureNotify handlers. | 541 // heuristics that are in the PropertyNotify and ConfigureNotify handlers. |
526 restored_bounds_ = bounds_; | 542 restored_bounds_ = bounds_; |
527 | 543 |
528 SetWMSpecState(true, | 544 SetWMSpecState(true, |
529 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"), | 545 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"), |
530 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_HORZ")); | 546 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_HORZ")); |
531 if (IsMinimized()) | 547 if (IsMinimized()) |
532 ShowWindowWithState(ui::SHOW_STATE_NORMAL); | 548 ShowWindowWithState(ui::SHOW_STATE_NORMAL); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 XWithdrawWindow(xdisplay_, xwindow_, 0); | 859 XWithdrawWindow(xdisplay_, xwindow_, 0); |
844 window_mapped_ = false; | 860 window_mapped_ = false; |
845 } | 861 } |
846 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false); | 862 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false); |
847 } | 863 } |
848 | 864 |
849 gfx::Rect DesktopWindowTreeHostX11::GetBounds() const { | 865 gfx::Rect DesktopWindowTreeHostX11::GetBounds() const { |
850 return bounds_; | 866 return bounds_; |
851 } | 867 } |
852 | 868 |
853 void DesktopWindowTreeHostX11::SetBounds(const gfx::Rect& bounds) { | 869 void DesktopWindowTreeHostX11::SetBounds(const gfx::Rect& requested_bounds) { |
| 870 gfx::Rect bounds(requested_bounds.origin(), |
| 871 AdjustSize(requested_bounds.size())); |
854 bool origin_changed = bounds_.origin() != bounds.origin(); | 872 bool origin_changed = bounds_.origin() != bounds.origin(); |
855 bool size_changed = bounds_.size() != bounds.size(); | 873 bool size_changed = bounds_.size() != bounds.size(); |
856 XWindowChanges changes = {0}; | 874 XWindowChanges changes = {0}; |
857 unsigned value_mask = 0; | 875 unsigned value_mask = 0; |
858 | 876 |
859 if (size_changed) { | 877 if (size_changed) { |
860 // X11 will send an XError at our process if have a 0 sized window. | 878 // X11 will send an XError at our process if have a 0 sized window. |
861 DCHECK_GT(bounds.width(), 0); | 879 DCHECK_GT(bounds.width(), 0); |
862 DCHECK_GT(bounds.height(), 0); | 880 DCHECK_GT(bounds.height(), 0); |
863 | 881 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 | 1049 |
1032 // x.org will BadMatch if we don't set a border when the depth isn't the | 1050 // x.org will BadMatch if we don't set a border when the depth isn't the |
1033 // same as the parent depth. | 1051 // same as the parent depth. |
1034 attribute_mask |= CWBorderPixel; | 1052 attribute_mask |= CWBorderPixel; |
1035 swa.border_pixel = 0; | 1053 swa.border_pixel = 0; |
1036 | 1054 |
1037 use_argb_visual_ = true; | 1055 use_argb_visual_ = true; |
1038 } | 1056 } |
1039 } | 1057 } |
1040 | 1058 |
1041 bounds_ = params.bounds; | 1059 bounds_ = gfx::Rect(params.bounds.origin(), |
| 1060 AdjustSize(params.bounds.size())); |
1042 xwindow_ = XCreateWindow( | 1061 xwindow_ = XCreateWindow( |
1043 xdisplay_, x_root_window_, | 1062 xdisplay_, x_root_window_, |
1044 bounds_.x(), bounds_.y(), | 1063 bounds_.x(), bounds_.y(), |
1045 bounds_.width(), bounds_.height(), | 1064 bounds_.width(), bounds_.height(), |
1046 0, // border width | 1065 0, // border width |
1047 depth, | 1066 depth, |
1048 InputOutput, | 1067 InputOutput, |
1049 visual, | 1068 visual, |
1050 attribute_mask, | 1069 attribute_mask, |
1051 &swa); | 1070 &swa); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 // If we have a delegate which is providing a default window icon, use that | 1183 // If we have a delegate which is providing a default window icon, use that |
1165 // icon. | 1184 // icon. |
1166 gfx::ImageSkia* window_icon = ViewsDelegate::views_delegate ? | 1185 gfx::ImageSkia* window_icon = ViewsDelegate::views_delegate ? |
1167 ViewsDelegate::views_delegate->GetDefaultWindowIcon() : NULL; | 1186 ViewsDelegate::views_delegate->GetDefaultWindowIcon() : NULL; |
1168 if (window_icon) { | 1187 if (window_icon) { |
1169 SetWindowIcons(gfx::ImageSkia(), *window_icon); | 1188 SetWindowIcons(gfx::ImageSkia(), *window_icon); |
1170 } | 1189 } |
1171 CreateCompositor(GetAcceleratedWidget()); | 1190 CreateCompositor(GetAcceleratedWidget()); |
1172 } | 1191 } |
1173 | 1192 |
| 1193 gfx::Size DesktopWindowTreeHostX11::AdjustSize( |
| 1194 const gfx::Size& requested_size) { |
| 1195 std::vector<gfx::Display> displays = |
| 1196 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)->GetAllDisplays(); |
| 1197 // Compare against all monitor sizes. The window manager can move the window |
| 1198 // to whichever monitor it wants. |
| 1199 for (size_t i = 0; i < displays.size(); ++i) { |
| 1200 if (requested_size == displays[i].size()) { |
| 1201 return gfx::Size(requested_size.width() - 1, |
| 1202 requested_size.height() - 1); |
| 1203 } |
| 1204 } |
| 1205 return requested_size; |
| 1206 } |
| 1207 |
1174 void DesktopWindowTreeHostX11::OnWMStateUpdated() { | 1208 void DesktopWindowTreeHostX11::OnWMStateUpdated() { |
1175 std::vector< ::Atom> atom_list; | 1209 std::vector< ::Atom> atom_list; |
1176 if (!ui::GetAtomArrayProperty(xwindow_, "_NET_WM_STATE", &atom_list)) | 1210 if (!ui::GetAtomArrayProperty(xwindow_, "_NET_WM_STATE", &atom_list)) |
1177 return; | 1211 return; |
1178 | 1212 |
1179 bool was_minimized = IsMinimized(); | 1213 bool was_minimized = IsMinimized(); |
1180 | 1214 |
1181 window_properties_.clear(); | 1215 window_properties_.clear(); |
1182 std::copy(atom_list.begin(), atom_list.end(), | 1216 std::copy(atom_list.begin(), atom_list.end(), |
1183 inserter(window_properties_, window_properties_.begin())); | 1217 inserter(window_properties_, window_properties_.begin())); |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 if (linux_ui) { | 1894 if (linux_ui) { |
1861 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); | 1895 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); |
1862 if (native_theme) | 1896 if (native_theme) |
1863 return native_theme; | 1897 return native_theme; |
1864 } | 1898 } |
1865 | 1899 |
1866 return ui::NativeTheme::instance(); | 1900 return ui::NativeTheme::instance(); |
1867 } | 1901 } |
1868 | 1902 |
1869 } // namespace views | 1903 } // namespace views |
OLD | NEW |