Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/exo/wayland/server.h" | 5 #include "components/exo/wayland/server.h" |
| 6 | 6 |
| 7 #include <alpha-compositing-unstable-v1-server-protocol.h> | 7 #include <alpha-compositing-unstable-v1-server-protocol.h> |
| 8 #include <gaming-input-unstable-v1-server-protocol.h> | 8 #include <gaming-input-unstable-v1-server-protocol.h> |
| 9 #include <grp.h> | 9 #include <grp.h> |
| 10 #include <keyboard-configuration-unstable-v1-server-protocol.h> | 10 #include <keyboard-configuration-unstable-v1-server-protocol.h> |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include <wayland-server-protocol-core.h> | 22 #include <wayland-server-protocol-core.h> |
| 23 #include <xdg-shell-unstable-v5-server-protocol.h> | 23 #include <xdg-shell-unstable-v5-server-protocol.h> |
| 24 #include <xdg-shell-unstable-v6-server-protocol.h> | 24 #include <xdg-shell-unstable-v6-server-protocol.h> |
| 25 | 25 |
| 26 #include <algorithm> | 26 #include <algorithm> |
| 27 #include <cstdlib> | 27 #include <cstdlib> |
| 28 #include <iterator> | 28 #include <iterator> |
| 29 #include <string> | 29 #include <string> |
| 30 #include <utility> | 30 #include <utility> |
| 31 | 31 |
| 32 #include "ash/common/shell_observer.h" | |
| 33 #include "ash/public/cpp/shell_window_ids.h" | 32 #include "ash/public/cpp/shell_window_ids.h" |
| 34 #include "ash/shell.h" | 33 #include "ash/shell.h" |
| 35 #include "base/bind.h" | 34 #include "base/bind.h" |
| 36 #include "base/cancelable_callback.h" | 35 #include "base/cancelable_callback.h" |
| 37 #include "base/files/file_path.h" | 36 #include "base/files/file_path.h" |
| 38 #include "base/macros.h" | 37 #include "base/macros.h" |
| 39 #include "base/memory/free_deleter.h" | 38 #include "base/memory/free_deleter.h" |
| 40 #include "base/memory/ptr_util.h" | 39 #include "base/memory/ptr_util.h" |
| 41 #include "base/memory/weak_ptr.h" | 40 #include "base/memory/weak_ptr.h" |
| 42 #include "base/strings/stringprintf.h" | 41 #include "base/strings/stringprintf.h" |
| (...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1082 WaylandPrimaryDisplayObserver(wl_resource* output_resource) | 1081 WaylandPrimaryDisplayObserver(wl_resource* output_resource) |
| 1083 : output_resource_(output_resource) { | 1082 : output_resource_(output_resource) { |
| 1084 display::Screen::GetScreen()->AddObserver(this); | 1083 display::Screen::GetScreen()->AddObserver(this); |
| 1085 SendDisplayMetrics(); | 1084 SendDisplayMetrics(); |
| 1086 } | 1085 } |
| 1087 ~WaylandPrimaryDisplayObserver() override { | 1086 ~WaylandPrimaryDisplayObserver() override { |
| 1088 display::Screen::GetScreen()->RemoveObserver(this); | 1087 display::Screen::GetScreen()->RemoveObserver(this); |
| 1089 } | 1088 } |
| 1090 | 1089 |
| 1091 // Overridden from display::DisplayObserver: | 1090 // Overridden from display::DisplayObserver: |
| 1092 void OnDisplayAdded(const display::Display& new_display) override {} | |
| 1093 void OnDisplayRemoved(const display::Display& new_display) override {} | |
| 1094 void OnDisplayMetricsChanged(const display::Display& display, | 1091 void OnDisplayMetricsChanged(const display::Display& display, |
| 1095 uint32_t changed_metrics) override { | 1092 uint32_t changed_metrics) override { |
| 1096 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) | 1093 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) |
| 1097 return; | 1094 return; |
| 1098 | 1095 |
| 1099 // There is no need to check DISPLAY_METRIC_PRIMARY because when primary | 1096 // There is no need to check DISPLAY_METRIC_PRIMARY because when primary |
| 1100 // changes, bounds always changes. (new primary should have had non | 1097 // changes, bounds always changes. (new primary should have had non |
| 1101 // 0,0 origin). | 1098 // 0,0 origin). |
| 1102 // Only exception is when switching to newly connected primary with | 1099 // Only exception is when switching to newly connected primary with |
| 1103 // the same bounds. This happens whenyou're in docked mode, suspend, | 1100 // the same bounds. This happens whenyou're in docked mode, suspend, |
| (...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2039 weak_ptr_factory_(this) { | 2036 weak_ptr_factory_(this) { |
| 2040 auto* helper = WMHelper::GetInstance(); | 2037 auto* helper = WMHelper::GetInstance(); |
| 2041 helper->AddMaximizeModeObserver(this); | 2038 helper->AddMaximizeModeObserver(this); |
| 2042 helper->AddActivationObserver(this); | 2039 helper->AddActivationObserver(this); |
| 2043 display::Screen::GetScreen()->AddObserver(this); | 2040 display::Screen::GetScreen()->AddObserver(this); |
| 2044 | 2041 |
| 2045 layout_mode_ = helper->IsMaximizeModeWindowManagerEnabled() | 2042 layout_mode_ = helper->IsMaximizeModeWindowManagerEnabled() |
| 2046 ? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET | 2043 ? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET |
| 2047 : ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 2044 : ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 2048 | 2045 |
| 2049 SendPrimaryDisplayMetrics(); | 2046 SendDisplayMetrics(); |
| 2050 SendActivated(helper->GetActiveWindow(), nullptr); | 2047 SendActivated(helper->GetActiveWindow(), nullptr); |
| 2051 } | 2048 } |
| 2052 ~WaylandRemoteShell() override { | 2049 ~WaylandRemoteShell() override { |
| 2053 auto* helper = WMHelper::GetInstance(); | 2050 auto* helper = WMHelper::GetInstance(); |
| 2054 helper->RemoveMaximizeModeObserver(this); | 2051 helper->RemoveMaximizeModeObserver(this); |
| 2055 helper->RemoveActivationObserver(this); | 2052 helper->RemoveActivationObserver(this); |
| 2056 display::Screen::GetScreen()->RemoveObserver(this); | 2053 display::Screen::GetScreen()->RemoveObserver(this); |
| 2057 } | 2054 } |
| 2058 | 2055 |
| 2059 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, | 2056 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, |
| 2060 int container) { | 2057 int container) { |
| 2061 return display_->CreateRemoteShellSurface(surface, container); | 2058 return display_->CreateRemoteShellSurface(surface, container); |
| 2062 } | 2059 } |
| 2063 | 2060 |
| 2064 std::unique_ptr<NotificationSurface> CreateNotificationSurface( | 2061 std::unique_ptr<NotificationSurface> CreateNotificationSurface( |
| 2065 Surface* surface, | 2062 Surface* surface, |
| 2066 const std::string& notification_id) { | 2063 const std::string& notification_id) { |
| 2067 return display_->CreateNotificationSurface(surface, notification_id); | 2064 return display_->CreateNotificationSurface(surface, notification_id); |
| 2068 } | 2065 } |
| 2069 | 2066 |
| 2070 // Overridden from display::DisplayObserver: | 2067 // Overridden from display::DisplayObserver: |
| 2071 void OnDisplayAdded(const display::Display& new_display) override {} | |
| 2072 void OnDisplayRemoved(const display::Display& new_display) override {} | |
| 2073 void OnDisplayMetricsChanged(const display::Display& display, | 2068 void OnDisplayMetricsChanged(const display::Display& display, |
| 2074 uint32_t changed_metrics) override { | 2069 uint32_t changed_metrics) override { |
| 2075 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) | 2070 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) |
| 2076 return; | 2071 return; |
| 2077 | 2072 |
| 2078 // No need to update when a primary dislpay has changed without bounds | 2073 // No need to update when a primary display has changed without bounds |
| 2079 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged | 2074 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged |
| 2080 // for more details. | 2075 // for more details. |
| 2081 if (changed_metrics & | 2076 if (changed_metrics & |
| 2082 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | | 2077 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | |
| 2083 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { | 2078 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { |
| 2084 SendDisplayMetrics(display); | 2079 ScheduleSendDisplayMetrics(); |
| 2085 } | 2080 } |
| 2086 } | 2081 } |
| 2087 | 2082 |
| 2088 // Overridden from WMHelper::MaximizeModeObserver: | 2083 // Overridden from WMHelper::MaximizeModeObserver: |
| 2089 void OnMaximizeModeStarted() override { | 2084 void OnMaximizeModeStarted() override { |
| 2090 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET; | 2085 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET; |
| 2091 | 2086 ScheduleSendDisplayMetrics(kConfigureDelayAfterLayoutSwitchMs); |
| 2092 send_configure_after_layout_change_ = true; | |
| 2093 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 2094 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure, | |
| 2095 weak_ptr_factory_.GetWeakPtr()), | |
| 2096 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs)); | |
| 2097 } | 2087 } |
| 2098 void OnMaximizeModeEnded() override { | 2088 void OnMaximizeModeEnded() override { |
| 2099 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 2089 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 2100 send_configure_after_layout_change_ = true; | 2090 ScheduleSendDisplayMetrics(kConfigureDelayAfterLayoutSwitchMs); |
| 2101 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 2102 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure, | |
| 2103 weak_ptr_factory_.GetWeakPtr()), | |
| 2104 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs)); | |
| 2105 } | 2091 } |
| 2106 | 2092 |
| 2107 // Overridden from WMHelper::ActivationObserver: | 2093 // Overridden from WMHelper::ActivationObserver: |
| 2108 void OnWindowActivated(aura::Window* gained_active, | 2094 void OnWindowActivated(aura::Window* gained_active, |
| 2109 aura::Window* lost_active) override { | 2095 aura::Window* lost_active) override { |
| 2110 SendActivated(gained_active, lost_active); | 2096 SendActivated(gained_active, lost_active); |
| 2111 } | 2097 } |
| 2112 | 2098 |
| 2113 private: | 2099 private: |
| 2114 void SendPrimaryDisplayMetrics() { | 2100 void ScheduleSendDisplayMetrics(int delay_ms = 0) { |
|
reveman
2017/02/10 02:10:53
nit: remove default argument and explicitly pass 0
Dominik Laskowski
2017/02/10 03:05:19
Done.
| |
| 2115 const display::Display primary = | 2101 needs_send_display_metrics_ = true; |
| 2116 display::Screen::GetScreen()->GetPrimaryDisplay(); | 2102 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 2117 | 2103 FROM_HERE, base::Bind(&WaylandRemoteShell::SendDisplayMetrics, |
| 2118 SendDisplayMetrics(primary); | 2104 weak_ptr_factory_.GetWeakPtr()), |
| 2105 base::TimeDelta::FromMilliseconds(delay_ms)); | |
| 2119 } | 2106 } |
| 2120 | 2107 |
| 2121 void MaybeSendConfigure() { | 2108 void SendDisplayMetrics() { |
| 2122 if (send_configure_after_layout_change_) | 2109 if (!needs_send_display_metrics_) |
| 2123 SendPrimaryDisplayMetrics(); | 2110 return; |
| 2124 } | 2111 needs_send_display_metrics_ = false; |
| 2125 | 2112 |
| 2126 void SendDisplayMetrics(const display::Display& display) { | 2113 const display::Screen* screen = display::Screen::GetScreen(); |
| 2127 send_configure_after_layout_change_ = false; | 2114 const display::Display primary = screen->GetPrimaryDisplay(); |
|
reveman
2017/02/10 02:10:54
nit: s/primary/primary_display/
Dominik Laskowski
2017/02/10 03:05:19
Done.
| |
| 2128 | 2115 |
| 2129 const gfx::Insets& work_area_insets = display.GetWorkAreaInsets(); | 2116 gfx::Size size = primary.size(); |
|
reveman
2017/02/10 02:10:53
where is this used? is the temporary variable need
Dominik Laskowski
2017/02/10 03:05:19
In the dependent CL, where it might be the size of
reveman
2017/02/10 05:51:54
Save that for the follow up CL. Changes are hard t
Dominik Laskowski
2017/02/10 18:47:17
Done.
| |
| 2117 const gfx::Insets& work_area_insets = primary.GetWorkAreaInsets(); | |
| 2130 | 2118 |
| 2131 zcr_remote_shell_v1_send_configuration_changed( | 2119 zcr_remote_shell_v1_send_configuration_changed( |
| 2132 remote_shell_resource_, display.size().width(), display.size().height(), | 2120 remote_shell_resource_, size.width(), size.height(), |
| 2133 OutputTransform(display.rotation()), | 2121 OutputTransform(primary.rotation()), |
| 2134 wl_fixed_from_double(display.device_scale_factor()), | 2122 wl_fixed_from_double(primary.device_scale_factor()), |
| 2135 work_area_insets.left(), work_area_insets.top(), | 2123 work_area_insets.left(), work_area_insets.top(), |
| 2136 work_area_insets.right(), work_area_insets.bottom(), layout_mode_); | 2124 work_area_insets.right(), work_area_insets.bottom(), layout_mode_); |
| 2137 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); | 2125 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); |
| 2138 } | 2126 } |
| 2139 | 2127 |
| 2140 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { | 2128 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { |
| 2141 Surface* gained_active_surface = | 2129 Surface* gained_active_surface = |
| 2142 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; | 2130 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; |
| 2143 Surface* lost_active_surface = | 2131 Surface* lost_active_surface = |
| 2144 lost_active ? ShellSurface::GetMainSurface(lost_active) : nullptr; | 2132 lost_active ? ShellSurface::GetMainSurface(lost_active) : nullptr; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2169 lost_active_surface_resource); | 2157 lost_active_surface_resource); |
| 2170 wl_client_flush(client); | 2158 wl_client_flush(client); |
| 2171 } | 2159 } |
| 2172 | 2160 |
| 2173 // The exo display instance. Not owned. | 2161 // The exo display instance. Not owned. |
| 2174 Display* const display_; | 2162 Display* const display_; |
| 2175 | 2163 |
| 2176 // The remote shell resource associated with observer. | 2164 // The remote shell resource associated with observer. |
| 2177 wl_resource* const remote_shell_resource_; | 2165 wl_resource* const remote_shell_resource_; |
| 2178 | 2166 |
| 2179 bool send_configure_after_layout_change_ = false; | 2167 bool needs_send_display_metrics_ = true; |
| 2180 | 2168 |
| 2181 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 2169 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 2182 | 2170 |
| 2183 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; | 2171 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; |
| 2184 | 2172 |
| 2185 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); | 2173 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); |
| 2186 }; | 2174 }; |
| 2187 | 2175 |
| 2188 void remote_shell_destroy(wl_client* client, wl_resource* resource) { | 2176 void remote_shell_destroy(wl_client* client, wl_resource* resource) { |
| 2189 // Nothing to do here. | 2177 // Nothing to do here. |
| (...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3749 DCHECK(event_loop); | 3737 DCHECK(event_loop); |
| 3750 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3738 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3751 } | 3739 } |
| 3752 | 3740 |
| 3753 void Server::Flush() { | 3741 void Server::Flush() { |
| 3754 wl_display_flush_clients(wl_display_.get()); | 3742 wl_display_flush_clients(wl_display_.get()); |
| 3755 } | 3743 } |
| 3756 | 3744 |
| 3757 } // namespace wayland | 3745 } // namespace wayland |
| 3758 } // namespace exo | 3746 } // namespace exo |
| OLD | NEW |