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