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> |
| 11 #include <linux/input.h> | 11 #include <linux/input.h> |
| 12 #include <presentation-time-server-protocol.h> | 12 #include <presentation-time-server-protocol.h> |
| 13 #include <remote-shell-unstable-v1-server-protocol.h> | 13 #include <remote-shell-unstable-v1-server-protocol.h> |
| 14 #include <secure-output-unstable-v1-server-protocol.h> | 14 #include <secure-output-unstable-v1-server-protocol.h> |
| 15 #include <stddef.h> | 15 #include <stddef.h> |
| 16 #include <stdint.h> | 16 #include <stdint.h> |
| 17 #include <stylus-unstable-v1-server-protocol.h> | 17 #include <stylus-unstable-v1-server-protocol.h> |
| 18 #include <stylus-unstable-v2-server-protocol.h> | 18 #include <stylus-unstable-v2-server-protocol.h> |
| 19 #include <viewporter-server-protocol.h> | 19 #include <viewporter-server-protocol.h> |
| 20 #include <vsync-feedback-unstable-v1-server-protocol.h> | 20 #include <vsync-feedback-unstable-v1-server-protocol.h> |
| 21 #include <wayland-server-core.h> | 21 #include <wayland-server-core.h> |
| 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 <unordered_set> | |
| 30 #include <utility> | 31 #include <utility> |
| 31 | 32 |
| 32 #include "ash/public/cpp/shell_window_ids.h" | 33 #include "ash/public/cpp/shell_window_ids.h" |
| 33 #include "ash/shell.h" | 34 #include "ash/shell.h" |
| 34 #include "base/bind.h" | 35 #include "base/bind.h" |
| 35 #include "base/cancelable_callback.h" | 36 #include "base/cancelable_callback.h" |
| 36 #include "base/files/file_path.h" | 37 #include "base/files/file_path.h" |
| 37 #include "base/macros.h" | 38 #include "base/macros.h" |
| 38 #include "base/memory/free_deleter.h" | 39 #include "base/memory/free_deleter.h" |
| 39 #include "base/memory/ptr_util.h" | 40 #include "base/memory/ptr_util.h" |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 wl_client_get_display(wl_resource_get_client(resource))); | 999 wl_client_get_display(wl_resource_get_client(resource))); |
| 999 wl_shell_surface_send_ping(resource, serial); | 1000 wl_shell_surface_send_ping(resource, serial); |
| 1000 wl_client_flush(wl_resource_get_client(resource)); | 1001 wl_client_flush(wl_resource_get_client(resource)); |
| 1001 } | 1002 } |
| 1002 | 1003 |
| 1003 uint32_t HandleShellSurfaceConfigureCallback( | 1004 uint32_t HandleShellSurfaceConfigureCallback( |
| 1004 wl_resource* resource, | 1005 wl_resource* resource, |
| 1005 const gfx::Size& size, | 1006 const gfx::Size& size, |
| 1006 ash::wm::WindowStateType state_type, | 1007 ash::wm::WindowStateType state_type, |
| 1007 bool resizing, | 1008 bool resizing, |
| 1008 bool activated) { | 1009 bool activated, |
| 1010 const gfx::Point& origin) { | |
| 1009 wl_shell_surface_send_configure(resource, WL_SHELL_SURFACE_RESIZE_NONE, | 1011 wl_shell_surface_send_configure(resource, WL_SHELL_SURFACE_RESIZE_NONE, |
| 1010 size.width(), size.height()); | 1012 size.width(), size.height()); |
| 1011 wl_client_flush(wl_resource_get_client(resource)); | 1013 wl_client_flush(wl_resource_get_client(resource)); |
| 1012 return 0; | 1014 return 0; |
| 1013 } | 1015 } |
| 1014 | 1016 |
| 1015 void shell_get_shell_surface(wl_client* client, | 1017 void shell_get_shell_surface(wl_client* client, |
| 1016 wl_resource* resource, | 1018 wl_resource* resource, |
| 1017 uint32_t id, | 1019 uint32_t id, |
| 1018 wl_resource* surface) { | 1020 wl_resource* surface) { |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1523 DCHECK(value); | 1525 DCHECK(value); |
| 1524 *value = state; | 1526 *value = state; |
| 1525 } | 1527 } |
| 1526 | 1528 |
| 1527 uint32_t HandleXdgToplevelV6ConfigureCallback( | 1529 uint32_t HandleXdgToplevelV6ConfigureCallback( |
| 1528 wl_resource* resource, | 1530 wl_resource* resource, |
| 1529 wl_resource* surface_resource, | 1531 wl_resource* surface_resource, |
| 1530 const gfx::Size& size, | 1532 const gfx::Size& size, |
| 1531 ash::wm::WindowStateType state_type, | 1533 ash::wm::WindowStateType state_type, |
| 1532 bool resizing, | 1534 bool resizing, |
| 1533 bool activated) { | 1535 bool activated, |
| 1536 const gfx::Point& origin) { | |
| 1534 wl_array states; | 1537 wl_array states; |
| 1535 wl_array_init(&states); | 1538 wl_array_init(&states); |
| 1536 if (state_type == ash::wm::WINDOW_STATE_TYPE_MAXIMIZED) | 1539 if (state_type == ash::wm::WINDOW_STATE_TYPE_MAXIMIZED) |
| 1537 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED); | 1540 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED); |
| 1538 if (state_type == ash::wm::WINDOW_STATE_TYPE_FULLSCREEN) | 1541 if (state_type == ash::wm::WINDOW_STATE_TYPE_FULLSCREEN) |
| 1539 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN); | 1542 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN); |
| 1540 if (resizing) | 1543 if (resizing) |
| 1541 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_RESIZING); | 1544 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_RESIZING); |
| 1542 if (activated) | 1545 if (activated) |
| 1543 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_ACTIVATED); | 1546 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_ACTIVATED); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1660 wl_array_add(states, sizeof(xdg_surface_state))); | 1663 wl_array_add(states, sizeof(xdg_surface_state))); |
| 1661 DCHECK(value); | 1664 DCHECK(value); |
| 1662 *value = state; | 1665 *value = state; |
| 1663 } | 1666 } |
| 1664 | 1667 |
| 1665 uint32_t HandleXdgSurfaceV5ConfigureCallback( | 1668 uint32_t HandleXdgSurfaceV5ConfigureCallback( |
| 1666 wl_resource* resource, | 1669 wl_resource* resource, |
| 1667 const gfx::Size& size, | 1670 const gfx::Size& size, |
| 1668 ash::wm::WindowStateType state_type, | 1671 ash::wm::WindowStateType state_type, |
| 1669 bool resizing, | 1672 bool resizing, |
| 1670 bool activated) { | 1673 bool activated, |
| 1674 const gfx::Point& origin) { | |
| 1671 wl_array states; | 1675 wl_array states; |
| 1672 wl_array_init(&states); | 1676 wl_array_init(&states); |
| 1673 if (state_type == ash::wm::WINDOW_STATE_TYPE_MAXIMIZED) | 1677 if (state_type == ash::wm::WINDOW_STATE_TYPE_MAXIMIZED) |
| 1674 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_MAXIMIZED); | 1678 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_MAXIMIZED); |
| 1675 if (state_type == ash::wm::WINDOW_STATE_TYPE_FULLSCREEN) | 1679 if (state_type == ash::wm::WINDOW_STATE_TYPE_FULLSCREEN) |
| 1676 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_FULLSCREEN); | 1680 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_FULLSCREEN); |
| 1677 if (resizing) | 1681 if (resizing) |
| 1678 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_RESIZING); | 1682 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_RESIZING); |
| 1679 if (activated) | 1683 if (activated) |
| 1680 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_ACTIVATED); | 1684 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_ACTIVATED); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1969 int32_t width, | 1973 int32_t width, |
| 1970 int32_t height) { | 1974 int32_t height) { |
| 1971 ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource); | 1975 ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource); |
| 1972 gfx::Rect content_bounds(x, y, width, height); | 1976 gfx::Rect content_bounds(x, y, width, height); |
| 1973 shell_surface->SetRectangularSurfaceShadow(content_bounds); | 1977 shell_surface->SetRectangularSurfaceShadow(content_bounds); |
| 1974 } | 1978 } |
| 1975 | 1979 |
| 1976 void remote_surface_ack_configure(wl_client* client, | 1980 void remote_surface_ack_configure(wl_client* client, |
| 1977 wl_resource* resource, | 1981 wl_resource* resource, |
| 1978 uint32_t serial) { | 1982 uint32_t serial) { |
| 1979 NOTIMPLEMENTED(); | 1983 GetUserDataAs<ShellSurface>(resource)->AcknowledgeConfigure(serial); |
| 1980 } | 1984 } |
| 1981 | 1985 |
| 1982 void remote_surface_move(wl_client* client, wl_resource* resource) { | 1986 void remote_surface_move(wl_client* client, wl_resource* resource) { |
| 1983 NOTIMPLEMENTED(); | 1987 GetUserDataAs<ShellSurface>(resource)->Move(); |
| 1984 } | 1988 } |
| 1985 | 1989 |
| 1986 const struct zcr_remote_surface_v1_interface remote_surface_implementation = { | 1990 const struct zcr_remote_surface_v1_interface remote_surface_implementation = { |
| 1987 remote_surface_destroy, | 1991 remote_surface_destroy, |
| 1988 remote_surface_set_app_id, | 1992 remote_surface_set_app_id, |
| 1989 remote_surface_set_window_geometry, | 1993 remote_surface_set_window_geometry, |
| 1990 remote_surface_set_scale, | 1994 remote_surface_set_scale, |
| 1991 remote_surface_set_rectangular_shadow_DEPRECATED, | 1995 remote_surface_set_rectangular_shadow_DEPRECATED, |
| 1992 remote_surface_set_rectangular_shadow_background_opacity, | 1996 remote_surface_set_rectangular_shadow_background_opacity, |
| 1993 remote_surface_set_title, | 1997 remote_surface_set_title, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2014 } | 2018 } |
| 2015 | 2019 |
| 2016 const struct zcr_notification_surface_v1_interface | 2020 const struct zcr_notification_surface_v1_interface |
| 2017 notification_surface_implementation = {notification_surface_destroy}; | 2021 notification_surface_implementation = {notification_surface_destroy}; |
| 2018 | 2022 |
| 2019 //////////////////////////////////////////////////////////////////////////////// | 2023 //////////////////////////////////////////////////////////////////////////////// |
| 2020 // remote_shell_interface: | 2024 // remote_shell_interface: |
| 2021 | 2025 |
| 2022 // Implements remote shell interface and monitors workspace state needed | 2026 // Implements remote shell interface and monitors workspace state needed |
| 2023 // for the remote shell interface. | 2027 // for the remote shell interface. |
| 2028 // | |
| 2029 // This class is also responsible for conversion between server-side screen | |
| 2030 // coordinates and client-side virtual coordinates. This mapping enables | |
| 2031 // support for multiple displays when the client is limited to a single | |
| 2032 // display. In that case, the client uses a virtual display computed as | |
| 2033 // the bounding box of the physical displays, and the server translates | |
| 2034 // positions based on the display layout. For example, P is the client's | |
| 2035 // origin in virtual coordinates, and Q is the server's origin in screen | |
| 2036 // coordinates. | |
| 2037 // | |
| 2038 // P Q | |
| 2039 // +-----+ / | |
| 2040 // | |/ | |
| 2041 // | 2 +-----------+ | |
| 2042 // | | | | |
| 2043 // +-----+ 1 | | |
| 2044 // | | | |
| 2045 // +-----------+ | |
| 2046 // | |
| 2024 class WaylandRemoteShell : public WMHelper::MaximizeModeObserver, | 2047 class WaylandRemoteShell : public WMHelper::MaximizeModeObserver, |
| 2025 public WMHelper::ActivationObserver, | 2048 public WMHelper::ActivationObserver, |
| 2026 public display::DisplayObserver { | 2049 public display::DisplayObserver { |
| 2027 public: | 2050 public: |
| 2028 WaylandRemoteShell(Display* display, wl_resource* remote_shell_resource) | 2051 WaylandRemoteShell(Display* display, wl_resource* remote_shell_resource) |
| 2029 : display_(display), | 2052 : display_(display), |
| 2030 remote_shell_resource_(remote_shell_resource), | 2053 remote_shell_resource_(remote_shell_resource), |
| 2031 weak_ptr_factory_(this) { | 2054 weak_ptr_factory_(this) { |
| 2032 auto* helper = WMHelper::GetInstance(); | 2055 auto* helper = WMHelper::GetInstance(); |
| 2033 helper->AddMaximizeModeObserver(this); | 2056 helper->AddMaximizeModeObserver(this); |
| 2034 helper->AddActivationObserver(this); | 2057 helper->AddActivationObserver(this); |
| 2035 display::Screen::GetScreen()->AddObserver(this); | 2058 display::Screen::GetScreen()->AddObserver(this); |
| 2036 | 2059 |
| 2037 layout_mode_ = helper->IsMaximizeModeWindowManagerEnabled() | 2060 layout_mode_ = helper->IsMaximizeModeWindowManagerEnabled() |
| 2038 ? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET | 2061 ? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET |
| 2039 : ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 2062 : ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 2040 | 2063 |
| 2041 SendDisplayMetrics(); | 2064 SendDisplayMetrics(); |
| 2042 SendActivated(helper->GetActiveWindow(), nullptr); | 2065 SendActivated(helper->GetActiveWindow(), nullptr); |
| 2043 } | 2066 } |
| 2044 ~WaylandRemoteShell() override { | 2067 ~WaylandRemoteShell() override { |
| 2045 auto* helper = WMHelper::GetInstance(); | 2068 auto* helper = WMHelper::GetInstance(); |
| 2046 helper->RemoveMaximizeModeObserver(this); | 2069 helper->RemoveMaximizeModeObserver(this); |
| 2047 helper->RemoveActivationObserver(this); | 2070 helper->RemoveActivationObserver(this); |
| 2048 display::Screen::GetScreen()->RemoveObserver(this); | 2071 display::Screen::GetScreen()->RemoveObserver(this); |
| 2049 } | 2072 } |
| 2050 | 2073 |
| 2051 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, | 2074 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, |
| 2052 int container) { | 2075 int container) { |
| 2053 return display_->CreateRemoteShellSurface(surface, container); | 2076 std::unique_ptr<ShellSurface> shell_surface = |
| 2077 display_->CreateRemoteShellSurface(surface, virtual_origin_, container); | |
| 2078 | |
| 2079 shell_surfaces_.insert(shell_surface.get()); | |
| 2080 shell_surface->set_destroyed_callback( | |
| 2081 base::Bind(&WaylandRemoteShell::OnShellSurfaceDestroyed, | |
| 2082 weak_ptr_factory_.GetWeakPtr(), shell_surface.get())); | |
| 2083 | |
| 2084 return shell_surface; | |
| 2085 } | |
| 2086 | |
| 2087 void OnShellSurfaceDestroyed(ShellSurface* shell_surface) { | |
| 2088 shell_surfaces_.erase(shell_surface); | |
| 2054 } | 2089 } |
| 2055 | 2090 |
| 2056 std::unique_ptr<NotificationSurface> CreateNotificationSurface( | 2091 std::unique_ptr<NotificationSurface> CreateNotificationSurface( |
| 2057 Surface* surface, | 2092 Surface* surface, |
| 2058 const std::string& notification_id) { | 2093 const std::string& notification_id) { |
| 2059 return display_->CreateNotificationSurface(surface, notification_id); | 2094 return display_->CreateNotificationSurface(surface, notification_id); |
| 2060 } | 2095 } |
| 2061 | 2096 |
| 2062 // Overridden from display::DisplayObserver: | 2097 // Overridden from display::DisplayObserver: |
| 2098 void OnDisplayAdded(const display::Display& new_display) override { | |
| 2099 if (IsMultiDisplaySupported()) | |
| 2100 ScheduleSendDisplayMetrics(0); | |
| 2101 } | |
| 2102 | |
| 2103 void OnDisplayRemoved(const display::Display& old_display) override { | |
| 2104 if (IsMultiDisplaySupported()) | |
| 2105 ScheduleSendDisplayMetrics(0); | |
| 2106 } | |
| 2107 | |
| 2063 void OnDisplayMetricsChanged(const display::Display& display, | 2108 void OnDisplayMetricsChanged(const display::Display& display, |
| 2064 uint32_t changed_metrics) override { | 2109 uint32_t changed_metrics) override { |
| 2065 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) | 2110 if (!IsMultiDisplaySupported() && |
| 2111 display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) | |
| 2066 return; | 2112 return; |
| 2067 | 2113 |
| 2068 // No need to update when a primary display has changed without bounds | 2114 // No need to update when a primary display has changed without bounds |
| 2069 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged | 2115 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged |
| 2070 // for more details. | 2116 // for more details. |
| 2071 if (changed_metrics & | 2117 if (changed_metrics & |
| 2072 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | | 2118 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | |
| 2073 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { | 2119 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { |
| 2074 ScheduleSendDisplayMetrics(0); | 2120 ScheduleSendDisplayMetrics(0); |
| 2075 } | 2121 } |
| 2076 } | 2122 } |
| 2077 | 2123 |
| 2078 // Overridden from WMHelper::MaximizeModeObserver: | 2124 // Overridden from WMHelper::MaximizeModeObserver: |
| 2079 void OnMaximizeModeStarted() override { | 2125 void OnMaximizeModeStarted() override { |
| 2080 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET; | 2126 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET; |
| 2081 ScheduleSendDisplayMetrics(kConfigureDelayAfterLayoutSwitchMs); | 2127 ScheduleSendDisplayMetrics(kConfigureDelayAfterLayoutSwitchMs); |
| 2082 } | 2128 } |
| 2083 void OnMaximizeModeEnded() override { | 2129 void OnMaximizeModeEnded() override { |
| 2084 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 2130 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 2085 ScheduleSendDisplayMetrics(kConfigureDelayAfterLayoutSwitchMs); | 2131 ScheduleSendDisplayMetrics(kConfigureDelayAfterLayoutSwitchMs); |
| 2086 } | 2132 } |
| 2087 | 2133 |
| 2088 // Overridden from WMHelper::ActivationObserver: | 2134 // Overridden from WMHelper::ActivationObserver: |
| 2089 void OnWindowActivated(aura::Window* gained_active, | 2135 void OnWindowActivated(aura::Window* gained_active, |
| 2090 aura::Window* lost_active) override { | 2136 aura::Window* lost_active) override { |
| 2091 SendActivated(gained_active, lost_active); | 2137 SendActivated(gained_active, lost_active); |
| 2092 } | 2138 } |
| 2093 | 2139 |
| 2094 private: | 2140 private: |
| 2141 bool IsMultiDisplaySupported() const { | |
| 2142 return wl_resource_get_version(remote_shell_resource_) >= 3; | |
| 2143 } | |
| 2144 | |
| 2095 void ScheduleSendDisplayMetrics(int delay_ms) { | 2145 void ScheduleSendDisplayMetrics(int delay_ms) { |
| 2096 needs_send_display_metrics_ = true; | 2146 needs_send_display_metrics_ = true; |
| 2097 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 2147 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 2098 FROM_HERE, base::Bind(&WaylandRemoteShell::SendDisplayMetrics, | 2148 FROM_HERE, base::Bind(&WaylandRemoteShell::SendDisplayMetrics, |
| 2099 weak_ptr_factory_.GetWeakPtr()), | 2149 weak_ptr_factory_.GetWeakPtr()), |
| 2100 base::TimeDelta::FromMilliseconds(delay_ms)); | 2150 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 2101 } | 2151 } |
| 2102 | 2152 |
| 2103 void SendDisplayMetrics() { | 2153 void SendDisplayMetrics() { |
| 2104 if (!needs_send_display_metrics_) | 2154 if (!needs_send_display_metrics_) |
| 2105 return; | 2155 return; |
| 2106 needs_send_display_metrics_ = false; | 2156 needs_send_display_metrics_ = false; |
| 2107 | 2157 |
| 2108 const display::Screen* screen = display::Screen::GetScreen(); | 2158 const display::Screen* screen = display::Screen::GetScreen(); |
| 2109 const display::Display primary_display = screen->GetPrimaryDisplay(); | 2159 const display::Display primary_display = screen->GetPrimaryDisplay(); |
| 2110 | 2160 |
| 2161 gfx::Size size = primary_display.size(); | |
| 2162 | |
| 2163 if (IsMultiDisplaySupported()) { | |
| 2164 // Virtual screen is the bounding box of the displays in screen | |
| 2165 // coordinates. | |
| 2166 gfx::Rect bounds; | |
| 2167 for (const auto& display : screen->GetAllDisplays()) | |
| 2168 bounds.Union(display.bounds()); | |
| 2169 | |
| 2170 virtual_origin_ = bounds.origin(); | |
| 2171 size = bounds.size(); | |
| 2172 | |
| 2173 for (ShellSurface* shell_surface : shell_surfaces_) | |
| 2174 shell_surface->SetOrigin(virtual_origin_); | |
| 2175 } | |
| 2176 | |
| 2177 // TODO(domlaskowski): Send insets for each workspace. | |
| 2111 const gfx::Insets& work_area_insets = primary_display.GetWorkAreaInsets(); | 2178 const gfx::Insets& work_area_insets = primary_display.GetWorkAreaInsets(); |
| 2112 | 2179 |
| 2113 zcr_remote_shell_v1_send_configuration_changed( | 2180 zcr_remote_shell_v1_send_configuration_changed( |
| 2114 remote_shell_resource_, | 2181 remote_shell_resource_, size.width(), size.height(), |
| 2115 primary_display.size().width(), | |
| 2116 primary_display.size().height(), | |
| 2117 OutputTransform(primary_display.rotation()), | 2182 OutputTransform(primary_display.rotation()), |
| 2118 wl_fixed_from_double(primary_display.device_scale_factor()), | 2183 wl_fixed_from_double(primary_display.device_scale_factor()), |
| 2119 work_area_insets.left(), work_area_insets.top(), | 2184 work_area_insets.left(), work_area_insets.top(), |
| 2120 work_area_insets.right(), work_area_insets.bottom(), layout_mode_); | 2185 work_area_insets.right(), work_area_insets.bottom(), layout_mode_); |
| 2121 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); | 2186 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); |
| 2122 } | 2187 } |
| 2123 | 2188 |
| 2124 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { | 2189 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { |
| 2125 Surface* gained_active_surface = | 2190 Surface* gained_active_surface = |
| 2126 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; | 2191 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2157 // The exo display instance. Not owned. | 2222 // The exo display instance. Not owned. |
| 2158 Display* const display_; | 2223 Display* const display_; |
| 2159 | 2224 |
| 2160 // The remote shell resource associated with observer. | 2225 // The remote shell resource associated with observer. |
| 2161 wl_resource* const remote_shell_resource_; | 2226 wl_resource* const remote_shell_resource_; |
| 2162 | 2227 |
| 2163 bool needs_send_display_metrics_ = true; | 2228 bool needs_send_display_metrics_ = true; |
| 2164 | 2229 |
| 2165 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 2230 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 2166 | 2231 |
| 2232 // Origin of the virtual screen relative to the primary display. | |
| 2233 gfx::Point virtual_origin_; | |
| 2234 | |
| 2235 std::unordered_set<ShellSurface*> shell_surfaces_; // Unowned. | |
|
reveman
2017/02/17 01:29:34
As discussed. Please refactor ShellSurface so this
| |
| 2236 | |
| 2167 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; | 2237 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; |
| 2168 | 2238 |
| 2169 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); | 2239 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); |
| 2170 }; | 2240 }; |
| 2171 | 2241 |
| 2172 void remote_shell_destroy(wl_client* client, wl_resource* resource) { | 2242 void remote_shell_destroy(wl_client* client, wl_resource* resource) { |
| 2173 // Nothing to do here. | 2243 // Nothing to do here. |
| 2174 } | 2244 } |
| 2175 | 2245 |
| 2176 int RemoteSurfaceContainer(uint32_t container) { | 2246 int RemoteSurfaceContainer(uint32_t container) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2214 state_type = ZCR_REMOTE_SHELL_V1_STATE_TYPE_TRUSTED_PINNED; | 2284 state_type = ZCR_REMOTE_SHELL_V1_STATE_TYPE_TRUSTED_PINNED; |
| 2215 break; | 2285 break; |
| 2216 default: | 2286 default: |
| 2217 break; | 2287 break; |
| 2218 } | 2288 } |
| 2219 | 2289 |
| 2220 zcr_remote_surface_v1_send_state_type_changed(resource, state_type); | 2290 zcr_remote_surface_v1_send_state_type_changed(resource, state_type); |
| 2221 wl_client_flush(wl_resource_get_client(resource)); | 2291 wl_client_flush(wl_resource_get_client(resource)); |
| 2222 } | 2292 } |
| 2223 | 2293 |
| 2294 uint32_t HandleRemoteSurfaceConfigureCallback( | |
| 2295 wl_resource* resource, | |
| 2296 const gfx::Size& size, | |
| 2297 ash::wm::WindowStateType state_type, | |
| 2298 bool resizing, | |
| 2299 bool activated, | |
| 2300 const gfx::Point& origin) { | |
| 2301 wl_array states; | |
| 2302 wl_array_init(&states); | |
| 2303 uint32_t serial = wl_display_next_serial( | |
| 2304 wl_client_get_display(wl_resource_get_client(resource))); | |
| 2305 zcr_remote_surface_v1_send_configure(resource, origin.x(), origin.y(), | |
| 2306 &states, serial); | |
| 2307 wl_client_flush(wl_resource_get_client(resource)); | |
| 2308 wl_array_release(&states); | |
| 2309 return serial; | |
| 2310 } | |
| 2311 | |
| 2224 void remote_shell_get_remote_surface(wl_client* client, | 2312 void remote_shell_get_remote_surface(wl_client* client, |
| 2225 wl_resource* resource, | 2313 wl_resource* resource, |
| 2226 uint32_t id, | 2314 uint32_t id, |
| 2227 wl_resource* surface, | 2315 wl_resource* surface, |
| 2228 uint32_t container) { | 2316 uint32_t container) { |
| 2229 std::unique_ptr<ShellSurface> shell_surface = | 2317 std::unique_ptr<ShellSurface> shell_surface = |
| 2230 GetUserDataAs<WaylandRemoteShell>(resource)->CreateShellSurface( | 2318 GetUserDataAs<WaylandRemoteShell>(resource)->CreateShellSurface( |
| 2231 GetUserDataAs<Surface>(surface), RemoteSurfaceContainer(container)); | 2319 GetUserDataAs<Surface>(surface), RemoteSurfaceContainer(container)); |
| 2232 if (!shell_surface) { | 2320 if (!shell_surface) { |
| 2233 wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V1_ERROR_ROLE, | 2321 wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V1_ERROR_ROLE, |
| 2234 "surface has already been assigned a role"); | 2322 "surface has already been assigned a role"); |
| 2235 return; | 2323 return; |
| 2236 } | 2324 } |
| 2237 | 2325 |
| 2238 wl_resource* remote_surface_resource = | 2326 wl_resource* remote_surface_resource = |
| 2239 wl_resource_create(client, &zcr_remote_surface_v1_interface, | 2327 wl_resource_create(client, &zcr_remote_surface_v1_interface, |
| 2240 wl_resource_get_version(resource), id); | 2328 wl_resource_get_version(resource), id); |
| 2241 | 2329 |
| 2242 shell_surface->set_close_callback( | 2330 shell_surface->set_close_callback( |
| 2243 base::Bind(&HandleRemoteSurfaceCloseCallback, | 2331 base::Bind(&HandleRemoteSurfaceCloseCallback, |
| 2244 base::Unretained(remote_surface_resource))); | 2332 base::Unretained(remote_surface_resource))); |
| 2245 shell_surface->set_state_changed_callback( | 2333 shell_surface->set_state_changed_callback( |
| 2246 base::Bind(&HandleRemoteSurfaceStateChangedCallback, | 2334 base::Bind(&HandleRemoteSurfaceStateChangedCallback, |
| 2247 base::Unretained(remote_surface_resource))); | 2335 base::Unretained(remote_surface_resource))); |
| 2336 shell_surface->set_configure_callback( | |
| 2337 base::Bind(&HandleRemoteSurfaceConfigureCallback, | |
| 2338 base::Unretained(remote_surface_resource))); | |
| 2248 | 2339 |
| 2249 SetImplementation(remote_surface_resource, &remote_surface_implementation, | 2340 SetImplementation(remote_surface_resource, &remote_surface_implementation, |
| 2250 std::move(shell_surface)); | 2341 std::move(shell_surface)); |
| 2251 } | 2342 } |
| 2252 | 2343 |
| 2253 void remote_shell_get_notification_surface(wl_client* client, | 2344 void remote_shell_get_notification_surface(wl_client* client, |
| 2254 wl_resource* resource, | 2345 wl_resource* resource, |
| 2255 uint32_t id, | 2346 uint32_t id, |
| 2256 wl_resource* surface, | 2347 wl_resource* surface, |
| 2257 const char* notification_id) { | 2348 const char* notification_id) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 2276 wl_resource_get_version(resource), id); | 2367 wl_resource_get_version(resource), id); |
| 2277 SetImplementation(notification_surface_resource, | 2368 SetImplementation(notification_surface_resource, |
| 2278 ¬ification_surface_implementation, | 2369 ¬ification_surface_implementation, |
| 2279 std::move(notification_surface)); | 2370 std::move(notification_surface)); |
| 2280 } | 2371 } |
| 2281 | 2372 |
| 2282 const struct zcr_remote_shell_v1_interface remote_shell_implementation = { | 2373 const struct zcr_remote_shell_v1_interface remote_shell_implementation = { |
| 2283 remote_shell_destroy, remote_shell_get_remote_surface, | 2374 remote_shell_destroy, remote_shell_get_remote_surface, |
| 2284 remote_shell_get_notification_surface}; | 2375 remote_shell_get_notification_surface}; |
| 2285 | 2376 |
| 2286 const uint32_t remote_shell_version = 2; | 2377 const uint32_t remote_shell_version = 3; |
| 2287 | 2378 |
| 2288 void bind_remote_shell(wl_client* client, | 2379 void bind_remote_shell(wl_client* client, |
| 2289 void* data, | 2380 void* data, |
| 2290 uint32_t version, | 2381 uint32_t version, |
| 2291 uint32_t id) { | 2382 uint32_t id) { |
| 2292 wl_resource* resource = | 2383 wl_resource* resource = |
| 2293 wl_resource_create(client, &zcr_remote_shell_v1_interface, | 2384 wl_resource_create(client, &zcr_remote_shell_v1_interface, |
| 2294 std::min(version, remote_shell_version), id); | 2385 std::min(version, remote_shell_version), id); |
| 2295 | 2386 |
| 2296 SetImplementation(resource, &remote_shell_implementation, | 2387 SetImplementation(resource, &remote_shell_implementation, |
| (...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3733 DCHECK(event_loop); | 3824 DCHECK(event_loop); |
| 3734 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3825 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3735 } | 3826 } |
| 3736 | 3827 |
| 3737 void Server::Flush() { | 3828 void Server::Flush() { |
| 3738 wl_display_flush_clients(wl_display_.get()); | 3829 wl_display_flush_clients(wl_display_.get()); |
| 3739 } | 3830 } |
| 3740 | 3831 |
| 3741 } // namespace wayland | 3832 } // namespace wayland |
| 3742 } // namespace exo | 3833 } // namespace exo |
| OLD | NEW |