| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 DesktopNativeWidgetAura* desktop_native_widget_aura) | 131 DesktopNativeWidgetAura* desktop_native_widget_aura) |
| 132 : close_widget_factory_(this), | 132 : close_widget_factory_(this), |
| 133 xdisplay_(gfx::GetXDisplay()), | 133 xdisplay_(gfx::GetXDisplay()), |
| 134 xwindow_(0), | 134 xwindow_(0), |
| 135 x_root_window_(DefaultRootWindow(xdisplay_)), | 135 x_root_window_(DefaultRootWindow(xdisplay_)), |
| 136 atom_cache_(xdisplay_, kAtomsToCache), | 136 atom_cache_(xdisplay_, kAtomsToCache), |
| 137 window_mapped_(false), | 137 window_mapped_(false), |
| 138 is_fullscreen_(false), | 138 is_fullscreen_(false), |
| 139 is_always_on_top_(false), | 139 is_always_on_top_(false), |
| 140 use_native_frame_(false), | 140 use_native_frame_(false), |
| 141 should_maximize_after_map_(false), | |
| 142 use_argb_visual_(false), | 141 use_argb_visual_(false), |
| 143 drag_drop_client_(NULL), | 142 drag_drop_client_(NULL), |
| 144 native_widget_delegate_(native_widget_delegate), | 143 native_widget_delegate_(native_widget_delegate), |
| 145 desktop_native_widget_aura_(desktop_native_widget_aura), | 144 desktop_native_widget_aura_(desktop_native_widget_aura), |
| 146 content_window_(NULL), | 145 content_window_(NULL), |
| 147 window_parent_(NULL), | 146 window_parent_(NULL), |
| 148 window_shape_(NULL), | 147 window_shape_(NULL), |
| 149 custom_window_shape_(false), | 148 custom_window_shape_(false), |
| 150 urgency_hint_set_(false) { | 149 urgency_hint_set_(false) { |
| 151 } | 150 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 return this; | 359 return this; |
| 361 } | 360 } |
| 362 | 361 |
| 363 void DesktopWindowTreeHostX11::ShowWindowWithState( | 362 void DesktopWindowTreeHostX11::ShowWindowWithState( |
| 364 ui::WindowShowState show_state) { | 363 ui::WindowShowState show_state) { |
| 365 if (!window_mapped_) | 364 if (!window_mapped_) |
| 366 MapWindow(show_state); | 365 MapWindow(show_state); |
| 367 | 366 |
| 368 if (show_state == ui::SHOW_STATE_NORMAL || | 367 if (show_state == ui::SHOW_STATE_NORMAL || |
| 369 show_state == ui::SHOW_STATE_MAXIMIZED) { | 368 show_state == ui::SHOW_STATE_MAXIMIZED) { |
| 369 // Note: XFCE ignores a maximize hint given before mapping the window. |
| 370 if (show_state == ui::SHOW_STATE_MAXIMIZED) |
| 371 Maximize(); |
| 370 Activate(); | 372 Activate(); |
| 371 } | 373 } |
| 372 | 374 |
| 373 native_widget_delegate_->AsWidget()->SetInitialFocus(show_state); | 375 native_widget_delegate_->AsWidget()->SetInitialFocus(show_state); |
| 374 } | 376 } |
| 375 | 377 |
| 376 void DesktopWindowTreeHostX11::ShowMaximizedWithBounds( | 378 void DesktopWindowTreeHostX11::ShowMaximizedWithBounds( |
| 377 const gfx::Rect& restored_bounds) { | 379 const gfx::Rect& restored_bounds) { |
| 378 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); | 380 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED); |
| 379 // Enforce |restored_bounds_| since calling Maximize() could have reset it. | 381 // Enforce |restored_bounds_| since calling Maximize() could have reset it. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 None); | 534 None); |
| 533 | 535 |
| 534 // Resize the window so that it does not have the same size as a monitor. | 536 // Resize the window so that it does not have the same size as a monitor. |
| 535 // (Otherwise, some window managers immediately put the window back in | 537 // (Otherwise, some window managers immediately put the window back in |
| 536 // fullscreen mode). | 538 // fullscreen mode). |
| 537 gfx::Rect adjusted_bounds(bounds_.origin(), AdjustSize(bounds_.size())); | 539 gfx::Rect adjusted_bounds(bounds_.origin(), AdjustSize(bounds_.size())); |
| 538 if (adjusted_bounds != bounds_) | 540 if (adjusted_bounds != bounds_) |
| 539 SetBounds(adjusted_bounds); | 541 SetBounds(adjusted_bounds); |
| 540 } | 542 } |
| 541 | 543 |
| 542 // Some WMs do not respect maximization hints on unmapped windows, so we | |
| 543 // save this one for later too. | |
| 544 should_maximize_after_map_ = !window_mapped_; | |
| 545 | |
| 546 // When we are in the process of requesting to maximize a window, we can | 544 // When we are in the process of requesting to maximize a window, we can |
| 547 // accurately keep track of our restored bounds instead of relying on the | 545 // accurately keep track of our restored bounds instead of relying on the |
| 548 // heuristics that are in the PropertyNotify and ConfigureNotify handlers. | 546 // heuristics that are in the PropertyNotify and ConfigureNotify handlers. |
| 549 restored_bounds_ = bounds_; | 547 restored_bounds_ = bounds_; |
| 550 | 548 |
| 551 SetWMSpecState(true, | 549 SetWMSpecState(true, |
| 552 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"), | 550 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"), |
| 553 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_HORZ")); | 551 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_HORZ")); |
| 554 if (IsMinimized()) | 552 if (IsMinimized()) |
| 555 ShowWindowWithState(ui::SHOW_STATE_NORMAL); | 553 ShowWindowWithState(ui::SHOW_STATE_NORMAL); |
| 556 } | 554 } |
| 557 | 555 |
| 558 void DesktopWindowTreeHostX11::Minimize() { | 556 void DesktopWindowTreeHostX11::Minimize() { |
| 559 ReleaseCapture(); | 557 ReleaseCapture(); |
| 560 XIconifyWindow(xdisplay_, xwindow_, 0); | 558 XIconifyWindow(xdisplay_, xwindow_, 0); |
| 561 } | 559 } |
| 562 | 560 |
| 563 void DesktopWindowTreeHostX11::Restore() { | 561 void DesktopWindowTreeHostX11::Restore() { |
| 564 should_maximize_after_map_ = false; | |
| 565 SetWMSpecState(false, | 562 SetWMSpecState(false, |
| 566 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"), | 563 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"), |
| 567 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_HORZ")); | 564 atom_cache_.GetAtom("_NET_WM_STATE_MAXIMIZED_HORZ")); |
| 568 if (IsMinimized()) | 565 if (IsMinimized()) |
| 569 ShowWindowWithState(ui::SHOW_STATE_NORMAL); | 566 ShowWindowWithState(ui::SHOW_STATE_NORMAL); |
| 570 } | 567 } |
| 571 | 568 |
| 572 bool DesktopWindowTreeHostX11::IsMaximized() const { | 569 bool DesktopWindowTreeHostX11::IsMaximized() const { |
| 573 return (HasWMSpecProperty("_NET_WM_STATE_MAXIMIZED_VERT") && | 570 return (HasWMSpecProperty("_NET_WM_STATE_MAXIMIZED_VERT") && |
| 574 HasWMSpecProperty("_NET_WM_STATE_MAXIMIZED_HORZ")); | 571 HasWMSpecProperty("_NET_WM_STATE_MAXIMIZED_HORZ")); |
| (...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 } | 1576 } |
| 1580 | 1577 |
| 1581 XMapWindow(xdisplay_, xwindow_); | 1578 XMapWindow(xdisplay_, xwindow_); |
| 1582 | 1579 |
| 1583 // We now block until our window is mapped. Some X11 APIs will crash and | 1580 // We now block until our window is mapped. Some X11 APIs will crash and |
| 1584 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is | 1581 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is |
| 1585 // asynchronous. | 1582 // asynchronous. |
| 1586 if (ui::X11EventSource::GetInstance()) | 1583 if (ui::X11EventSource::GetInstance()) |
| 1587 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(xwindow_); | 1584 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(xwindow_); |
| 1588 window_mapped_ = true; | 1585 window_mapped_ = true; |
| 1589 | |
| 1590 // Some WMs only respect maximize hints after the window has been mapped. | |
| 1591 // Check whether we need to re-do a maximization. | |
| 1592 if (should_maximize_after_map_) { | |
| 1593 Maximize(); | |
| 1594 should_maximize_after_map_ = false; | |
| 1595 } | |
| 1596 } | 1586 } |
| 1597 | 1587 |
| 1598 void DesktopWindowTreeHostX11::SetWindowTransparency() { | 1588 void DesktopWindowTreeHostX11::SetWindowTransparency() { |
| 1599 compositor()->SetHostHasTransparentBackground(use_argb_visual_); | 1589 compositor()->SetHostHasTransparentBackground(use_argb_visual_); |
| 1600 window()->SetTransparent(use_argb_visual_); | 1590 window()->SetTransparent(use_argb_visual_); |
| 1601 content_window_->SetTransparent(use_argb_visual_); | 1591 content_window_->SetTransparent(use_argb_visual_); |
| 1602 } | 1592 } |
| 1603 | 1593 |
| 1604 void DesktopWindowTreeHostX11::Relayout() { | 1594 void DesktopWindowTreeHostX11::Relayout() { |
| 1605 Widget* widget = native_widget_delegate_->AsWidget(); | 1595 Widget* widget = native_widget_delegate_->AsWidget(); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1924 if (linux_ui) { | 1914 if (linux_ui) { |
| 1925 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); | 1915 ui::NativeTheme* native_theme = linux_ui->GetNativeTheme(window); |
| 1926 if (native_theme) | 1916 if (native_theme) |
| 1927 return native_theme; | 1917 return native_theme; |
| 1928 } | 1918 } |
| 1929 | 1919 |
| 1930 return ui::NativeTheme::instance(); | 1920 return ui::NativeTheme::instance(); |
| 1931 } | 1921 } |
| 1932 | 1922 |
| 1933 } // namespace views | 1923 } // namespace views |
| OLD | NEW |