| 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/common/shell_observer.h" | |
| 33 #include "ash/public/cpp/shell_window_ids.h" | 33 #include "ash/public/cpp/shell_window_ids.h" |
| 34 #include "ash/shell.h" | 34 #include "ash/shell.h" |
| 35 #include "base/bind.h" | 35 #include "base/bind.h" |
| 36 #include "base/cancelable_callback.h" | 36 #include "base/cancelable_callback.h" |
| 37 #include "base/files/file_path.h" | 37 #include "base/files/file_path.h" |
| 38 #include "base/macros.h" | 38 #include "base/macros.h" |
| 39 #include "base/memory/free_deleter.h" | 39 #include "base/memory/free_deleter.h" |
| 40 #include "base/memory/ptr_util.h" | 40 #include "base/memory/ptr_util.h" |
| 41 #include "base/memory/weak_ptr.h" | 41 #include "base/memory/weak_ptr.h" |
| 42 #include "base/strings/stringprintf.h" | 42 #include "base/strings/stringprintf.h" |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 wl_client_get_display(wl_resource_get_client(resource))); | 999 wl_client_get_display(wl_resource_get_client(resource))); |
| 1000 wl_shell_surface_send_ping(resource, serial); | 1000 wl_shell_surface_send_ping(resource, serial); |
| 1001 wl_client_flush(wl_resource_get_client(resource)); | 1001 wl_client_flush(wl_resource_get_client(resource)); |
| 1002 } | 1002 } |
| 1003 | 1003 |
| 1004 uint32_t HandleShellSurfaceConfigureCallback( | 1004 uint32_t HandleShellSurfaceConfigureCallback( |
| 1005 wl_resource* resource, | 1005 wl_resource* resource, |
| 1006 const gfx::Size& size, | 1006 const gfx::Size& size, |
| 1007 ash::wm::WindowStateType state_type, | 1007 ash::wm::WindowStateType state_type, |
| 1008 bool resizing, | 1008 bool resizing, |
| 1009 bool activated) { | 1009 bool activated, |
| 1010 const gfx::Point& origin) { |
| 1010 wl_shell_surface_send_configure(resource, WL_SHELL_SURFACE_RESIZE_NONE, | 1011 wl_shell_surface_send_configure(resource, WL_SHELL_SURFACE_RESIZE_NONE, |
| 1011 size.width(), size.height()); | 1012 size.width(), size.height()); |
| 1012 wl_client_flush(wl_resource_get_client(resource)); | 1013 wl_client_flush(wl_resource_get_client(resource)); |
| 1013 return 0; | 1014 return 0; |
| 1014 } | 1015 } |
| 1015 | 1016 |
| 1016 void shell_get_shell_surface(wl_client* client, | 1017 void shell_get_shell_surface(wl_client* client, |
| 1017 wl_resource* resource, | 1018 wl_resource* resource, |
| 1018 uint32_t id, | 1019 uint32_t id, |
| 1019 wl_resource* surface) { | 1020 wl_resource* surface) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 WaylandPrimaryDisplayObserver(wl_resource* output_resource) | 1083 WaylandPrimaryDisplayObserver(wl_resource* output_resource) |
| 1083 : output_resource_(output_resource) { | 1084 : output_resource_(output_resource) { |
| 1084 display::Screen::GetScreen()->AddObserver(this); | 1085 display::Screen::GetScreen()->AddObserver(this); |
| 1085 SendDisplayMetrics(); | 1086 SendDisplayMetrics(); |
| 1086 } | 1087 } |
| 1087 ~WaylandPrimaryDisplayObserver() override { | 1088 ~WaylandPrimaryDisplayObserver() override { |
| 1088 display::Screen::GetScreen()->RemoveObserver(this); | 1089 display::Screen::GetScreen()->RemoveObserver(this); |
| 1089 } | 1090 } |
| 1090 | 1091 |
| 1091 // Overridden from display::DisplayObserver: | 1092 // 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, | 1093 void OnDisplayMetricsChanged(const display::Display& display, |
| 1095 uint32_t changed_metrics) override { | 1094 uint32_t changed_metrics) override { |
| 1096 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) | 1095 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) |
| 1097 return; | 1096 return; |
| 1098 | 1097 |
| 1099 // There is no need to check DISPLAY_METRIC_PRIMARY because when primary | 1098 // There is no need to check DISPLAY_METRIC_PRIMARY because when primary |
| 1100 // changes, bounds always changes. (new primary should have had non | 1099 // changes, bounds always changes. (new primary should have had non |
| 1101 // 0,0 origin). | 1100 // 0,0 origin). |
| 1102 // Only exception is when switching to newly connected primary with | 1101 // Only exception is when switching to newly connected primary with |
| 1103 // the same bounds. This happens whenyou're in docked mode, suspend, | 1102 // the same bounds. This happens whenyou're in docked mode, suspend, |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 DCHECK(value); | 1525 DCHECK(value); |
| 1527 *value = state; | 1526 *value = state; |
| 1528 } | 1527 } |
| 1529 | 1528 |
| 1530 uint32_t HandleXdgToplevelV6ConfigureCallback( | 1529 uint32_t HandleXdgToplevelV6ConfigureCallback( |
| 1531 wl_resource* resource, | 1530 wl_resource* resource, |
| 1532 wl_resource* surface_resource, | 1531 wl_resource* surface_resource, |
| 1533 const gfx::Size& size, | 1532 const gfx::Size& size, |
| 1534 ash::wm::WindowStateType state_type, | 1533 ash::wm::WindowStateType state_type, |
| 1535 bool resizing, | 1534 bool resizing, |
| 1536 bool activated) { | 1535 bool activated, |
| 1536 const gfx::Point& origin) { |
| 1537 wl_array states; | 1537 wl_array states; |
| 1538 wl_array_init(&states); | 1538 wl_array_init(&states); |
| 1539 if (state_type == ash::wm::WINDOW_STATE_TYPE_MAXIMIZED) | 1539 if (state_type == ash::wm::WINDOW_STATE_TYPE_MAXIMIZED) |
| 1540 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED); | 1540 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED); |
| 1541 if (state_type == ash::wm::WINDOW_STATE_TYPE_FULLSCREEN) | 1541 if (state_type == ash::wm::WINDOW_STATE_TYPE_FULLSCREEN) |
| 1542 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN); | 1542 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN); |
| 1543 if (resizing) | 1543 if (resizing) |
| 1544 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_RESIZING); | 1544 AddXdgToplevelV6State(&states, ZXDG_TOPLEVEL_V6_STATE_RESIZING); |
| 1545 if (activated) | 1545 if (activated) |
| 1546 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... |
| 1663 wl_array_add(states, sizeof(xdg_surface_state))); | 1663 wl_array_add(states, sizeof(xdg_surface_state))); |
| 1664 DCHECK(value); | 1664 DCHECK(value); |
| 1665 *value = state; | 1665 *value = state; |
| 1666 } | 1666 } |
| 1667 | 1667 |
| 1668 uint32_t HandleXdgSurfaceV5ConfigureCallback( | 1668 uint32_t HandleXdgSurfaceV5ConfigureCallback( |
| 1669 wl_resource* resource, | 1669 wl_resource* resource, |
| 1670 const gfx::Size& size, | 1670 const gfx::Size& size, |
| 1671 ash::wm::WindowStateType state_type, | 1671 ash::wm::WindowStateType state_type, |
| 1672 bool resizing, | 1672 bool resizing, |
| 1673 bool activated) { | 1673 bool activated, |
| 1674 const gfx::Point& origin) { |
| 1674 wl_array states; | 1675 wl_array states; |
| 1675 wl_array_init(&states); | 1676 wl_array_init(&states); |
| 1676 if (state_type == ash::wm::WINDOW_STATE_TYPE_MAXIMIZED) | 1677 if (state_type == ash::wm::WINDOW_STATE_TYPE_MAXIMIZED) |
| 1677 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_MAXIMIZED); | 1678 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_MAXIMIZED); |
| 1678 if (state_type == ash::wm::WINDOW_STATE_TYPE_FULLSCREEN) | 1679 if (state_type == ash::wm::WINDOW_STATE_TYPE_FULLSCREEN) |
| 1679 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_FULLSCREEN); | 1680 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_FULLSCREEN); |
| 1680 if (resizing) | 1681 if (resizing) |
| 1681 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_RESIZING); | 1682 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_RESIZING); |
| 1682 if (activated) | 1683 if (activated) |
| 1683 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_ACTIVATED); | 1684 AddXdgSurfaceV5State(&states, XDG_SURFACE_STATE_ACTIVATED); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1960 | 1961 |
| 1961 void remote_surface_set_system_modal(wl_client* client, wl_resource* resource) { | 1962 void remote_surface_set_system_modal(wl_client* client, wl_resource* resource) { |
| 1962 GetUserDataAs<ShellSurface>(resource)->SetSystemModal(true); | 1963 GetUserDataAs<ShellSurface>(resource)->SetSystemModal(true); |
| 1963 } | 1964 } |
| 1964 | 1965 |
| 1965 void remote_surface_unset_system_modal(wl_client* client, | 1966 void remote_surface_unset_system_modal(wl_client* client, |
| 1966 wl_resource* resource) { | 1967 wl_resource* resource) { |
| 1967 GetUserDataAs<ShellSurface>(resource)->SetSystemModal(false); | 1968 GetUserDataAs<ShellSurface>(resource)->SetSystemModal(false); |
| 1968 } | 1969 } |
| 1969 | 1970 |
| 1971 void remote_surface_ack_configure(wl_client* client, |
| 1972 wl_resource* resource, |
| 1973 uint32_t serial) { |
| 1974 GetUserDataAs<ShellSurface>(resource)->AcknowledgeConfigure(serial); |
| 1975 } |
| 1976 |
| 1977 void remote_surface_set_moving(wl_client* client, wl_resource* resource) { |
| 1978 GetUserDataAs<ShellSurface>(resource)->SetMoving(); |
| 1979 } |
| 1980 |
| 1981 void remote_surface_unset_moving(wl_client* client, wl_resource* resource) { |
| 1982 GetUserDataAs<ShellSurface>(resource)->UnsetMoving(false /* revert */); |
| 1983 } |
| 1984 |
| 1970 const struct zcr_remote_surface_v1_interface remote_surface_implementation = { | 1985 const struct zcr_remote_surface_v1_interface remote_surface_implementation = { |
| 1971 remote_surface_destroy, | 1986 remote_surface_destroy, |
| 1972 remote_surface_set_app_id, | 1987 remote_surface_set_app_id, |
| 1973 remote_surface_set_window_geometry, | 1988 remote_surface_set_window_geometry, |
| 1974 remote_surface_set_scale, | 1989 remote_surface_set_scale, |
| 1975 remote_surface_set_rectangular_shadow, | 1990 remote_surface_set_rectangular_shadow, |
| 1976 remote_surface_set_rectangular_shadow_background_opacity, | 1991 remote_surface_set_rectangular_shadow_background_opacity, |
| 1977 remote_surface_set_title, | 1992 remote_surface_set_title, |
| 1978 remote_surface_set_top_inset, | 1993 remote_surface_set_top_inset, |
| 1979 remote_surface_activate, | 1994 remote_surface_activate, |
| 1980 remote_surface_maximize, | 1995 remote_surface_maximize, |
| 1981 remote_surface_minimize, | 1996 remote_surface_minimize, |
| 1982 remote_surface_restore, | 1997 remote_surface_restore, |
| 1983 remote_surface_fullscreen, | 1998 remote_surface_fullscreen, |
| 1984 remote_surface_unfullscreen, | 1999 remote_surface_unfullscreen, |
| 1985 remote_surface_pin, | 2000 remote_surface_pin, |
| 1986 remote_surface_unpin, | 2001 remote_surface_unpin, |
| 1987 remote_surface_set_system_modal, | 2002 remote_surface_set_system_modal, |
| 1988 remote_surface_unset_system_modal}; | 2003 remote_surface_unset_system_modal, |
| 2004 remote_surface_ack_configure, |
| 2005 remote_surface_set_moving, |
| 2006 remote_surface_unset_moving}; |
| 1989 | 2007 |
| 1990 //////////////////////////////////////////////////////////////////////////////// | 2008 //////////////////////////////////////////////////////////////////////////////// |
| 1991 // notification_surface_interface: | 2009 // notification_surface_interface: |
| 1992 | 2010 |
| 1993 void notification_surface_destroy(wl_client* client, wl_resource* resource) { | 2011 void notification_surface_destroy(wl_client* client, wl_resource* resource) { |
| 1994 wl_resource_destroy(resource); | 2012 wl_resource_destroy(resource); |
| 1995 } | 2013 } |
| 1996 | 2014 |
| 1997 const struct zcr_notification_surface_v1_interface | 2015 const struct zcr_notification_surface_v1_interface |
| 1998 notification_surface_implementation = {notification_surface_destroy}; | 2016 notification_surface_implementation = {notification_surface_destroy}; |
| 1999 | 2017 |
| 2000 //////////////////////////////////////////////////////////////////////////////// | 2018 //////////////////////////////////////////////////////////////////////////////// |
| 2001 // remote_shell_interface: | 2019 // remote_shell_interface: |
| 2002 | 2020 |
| 2003 // Implements remote shell interface and monitors workspace state needed | 2021 // Implements remote shell interface and monitors workspace state needed |
| 2004 // for the remote shell interface. | 2022 // for the remote shell interface. |
| 2023 // |
| 2024 // This class is also responsible for conversion between server-side screen |
| 2025 // coordinates and client-side virtual coordinates. This mapping enables |
| 2026 // support for multiple displays when the client is limited to a single |
| 2027 // display. In that case, the client uses a virtual display computed as |
| 2028 // the bounding box of the physical displays, and the server translates |
| 2029 // positions based on the display layout. For example, P is the client's |
| 2030 // origin in virtual coordinates, and Q is the server's origin in screen |
| 2031 // coordinates. |
| 2032 // |
| 2033 // P Q |
| 2034 // +-----+ / |
| 2035 // | |/ |
| 2036 // | 2 +-----------+ |
| 2037 // | | | |
| 2038 // +-----+ 1 | |
| 2039 // | | |
| 2040 // +-----------+ |
| 2041 // |
| 2005 class WaylandRemoteShell : public WMHelper::MaximizeModeObserver, | 2042 class WaylandRemoteShell : public WMHelper::MaximizeModeObserver, |
| 2006 public WMHelper::ActivationObserver, | 2043 public WMHelper::ActivationObserver, |
| 2007 public display::DisplayObserver { | 2044 public display::DisplayObserver { |
| 2008 public: | 2045 public: |
| 2009 WaylandRemoteShell(Display* display, wl_resource* remote_shell_resource) | 2046 WaylandRemoteShell(Display* display, wl_resource* remote_shell_resource) |
| 2010 : display_(display), | 2047 : display_(display), |
| 2011 remote_shell_resource_(remote_shell_resource), | 2048 remote_shell_resource_(remote_shell_resource), |
| 2012 weak_ptr_factory_(this) { | 2049 weak_ptr_factory_(this) { |
| 2013 auto* helper = WMHelper::GetInstance(); | 2050 auto* helper = WMHelper::GetInstance(); |
| 2014 helper->AddMaximizeModeObserver(this); | 2051 helper->AddMaximizeModeObserver(this); |
| 2015 helper->AddActivationObserver(this); | 2052 helper->AddActivationObserver(this); |
| 2016 display::Screen::GetScreen()->AddObserver(this); | 2053 display::Screen::GetScreen()->AddObserver(this); |
| 2017 | 2054 |
| 2018 layout_mode_ = helper->IsMaximizeModeWindowManagerEnabled() | 2055 layout_mode_ = helper->IsMaximizeModeWindowManagerEnabled() |
| 2019 ? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET | 2056 ? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET |
| 2020 : ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 2057 : ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 2021 | 2058 |
| 2022 SendPrimaryDisplayMetrics(); | 2059 SendDisplayMetrics(); |
| 2023 SendActivated(helper->GetActiveWindow(), nullptr); | 2060 SendActivated(helper->GetActiveWindow(), nullptr); |
| 2024 } | 2061 } |
| 2025 ~WaylandRemoteShell() override { | 2062 ~WaylandRemoteShell() override { |
| 2026 auto* helper = WMHelper::GetInstance(); | 2063 auto* helper = WMHelper::GetInstance(); |
| 2027 helper->RemoveMaximizeModeObserver(this); | 2064 helper->RemoveMaximizeModeObserver(this); |
| 2028 helper->RemoveActivationObserver(this); | 2065 helper->RemoveActivationObserver(this); |
| 2029 display::Screen::GetScreen()->RemoveObserver(this); | 2066 display::Screen::GetScreen()->RemoveObserver(this); |
| 2030 } | 2067 } |
| 2031 | 2068 |
| 2032 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, | 2069 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, |
| 2033 int container) { | 2070 int container) { |
| 2034 return display_->CreateRemoteShellSurface(surface, container); | 2071 std::unique_ptr<ShellSurface> shell_surface = |
| 2072 display_->CreateRemoteShellSurface(surface, virtual_origin_, container); |
| 2073 |
| 2074 shell_surfaces_.insert(shell_surface.get()); |
| 2075 shell_surface->set_destroyed_callback( |
| 2076 base::Bind(&WaylandRemoteShell::OnShellSurfaceDestroyed, |
| 2077 weak_ptr_factory_.GetWeakPtr(), shell_surface.get())); |
| 2078 |
| 2079 return shell_surface; |
| 2080 } |
| 2081 |
| 2082 void OnShellSurfaceDestroyed(ShellSurface* shell_surface) { |
| 2083 shell_surfaces_.erase(shell_surface); |
| 2035 } | 2084 } |
| 2036 | 2085 |
| 2037 std::unique_ptr<NotificationSurface> CreateNotificationSurface( | 2086 std::unique_ptr<NotificationSurface> CreateNotificationSurface( |
| 2038 Surface* surface, | 2087 Surface* surface, |
| 2039 const std::string& notification_id) { | 2088 const std::string& notification_id) { |
| 2040 return display_->CreateNotificationSurface(surface, notification_id); | 2089 return display_->CreateNotificationSurface(surface, notification_id); |
| 2041 } | 2090 } |
| 2042 | 2091 |
| 2043 // Overridden from display::DisplayObserver: | 2092 // Overridden from display::DisplayObserver: |
| 2044 void OnDisplayAdded(const display::Display& new_display) override {} | 2093 void OnDisplayAdded(const display::Display& new_display) override { |
| 2045 void OnDisplayRemoved(const display::Display& new_display) override {} | 2094 if (IsMultiDisplaySupported()) |
| 2095 ScheduleSendDisplayMetrics(); |
| 2096 } |
| 2097 |
| 2098 void OnDisplayRemoved(const display::Display& old_display) override { |
| 2099 if (IsMultiDisplaySupported()) |
| 2100 ScheduleSendDisplayMetrics(); |
| 2101 } |
| 2102 |
| 2046 void OnDisplayMetricsChanged(const display::Display& display, | 2103 void OnDisplayMetricsChanged(const display::Display& display, |
| 2047 uint32_t changed_metrics) override { | 2104 uint32_t changed_metrics) override { |
| 2048 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) | 2105 if (!IsMultiDisplaySupported() && |
| 2106 display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) |
| 2049 return; | 2107 return; |
| 2050 | 2108 |
| 2051 // No need to update when a primary dislpay has changed without bounds | 2109 // No need to update when a primary display has changed without bounds |
| 2052 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged | 2110 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged |
| 2053 // for more details. | 2111 // for more details. |
| 2054 if (changed_metrics & | 2112 if (changed_metrics & |
| 2055 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | | 2113 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | |
| 2056 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { | 2114 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { |
| 2057 SendDisplayMetrics(display); | 2115 ScheduleSendDisplayMetrics(); |
| 2058 } | 2116 } |
| 2059 } | 2117 } |
| 2060 | 2118 |
| 2061 // Overridden from WMHelper::MaximizeModeObserver: | 2119 // Overridden from WMHelper::MaximizeModeObserver: |
| 2062 void OnMaximizeModeStarted() override { | 2120 void OnMaximizeModeStarted() override { |
| 2063 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET; | 2121 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET; |
| 2064 | 2122 ScheduleSendDisplayMetrics(kConfigureDelayAfterLayoutSwitchMs); |
| 2065 send_configure_after_layout_change_ = true; | |
| 2066 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 2067 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure, | |
| 2068 weak_ptr_factory_.GetWeakPtr()), | |
| 2069 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs)); | |
| 2070 } | 2123 } |
| 2071 void OnMaximizeModeEnded() override { | 2124 void OnMaximizeModeEnded() override { |
| 2072 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 2125 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 2073 send_configure_after_layout_change_ = true; | 2126 ScheduleSendDisplayMetrics(kConfigureDelayAfterLayoutSwitchMs); |
| 2074 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 2075 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure, | |
| 2076 weak_ptr_factory_.GetWeakPtr()), | |
| 2077 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs)); | |
| 2078 } | 2127 } |
| 2079 | 2128 |
| 2080 // Overridden from WMHelper::ActivationObserver: | 2129 // Overridden from WMHelper::ActivationObserver: |
| 2081 void OnWindowActivated(aura::Window* gained_active, | 2130 void OnWindowActivated(aura::Window* gained_active, |
| 2082 aura::Window* lost_active) override { | 2131 aura::Window* lost_active) override { |
| 2083 SendActivated(gained_active, lost_active); | 2132 SendActivated(gained_active, lost_active); |
| 2084 } | 2133 } |
| 2085 | 2134 |
| 2086 private: | 2135 private: |
| 2087 void SendPrimaryDisplayMetrics() { | 2136 bool IsMultiDisplaySupported() const { |
| 2088 const display::Display primary = | 2137 return wl_resource_get_version(remote_shell_resource_) >= 2; |
| 2089 display::Screen::GetScreen()->GetPrimaryDisplay(); | |
| 2090 | |
| 2091 SendDisplayMetrics(primary); | |
| 2092 } | 2138 } |
| 2093 | 2139 |
| 2094 void MaybeSendConfigure() { | 2140 void ScheduleSendDisplayMetrics(int delay_ms = 0) { |
| 2095 if (send_configure_after_layout_change_) | 2141 needs_send_display_metrics_ = true; |
| 2096 SendPrimaryDisplayMetrics(); | 2142 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 2143 FROM_HERE, base::Bind(&WaylandRemoteShell::SendDisplayMetrics, |
| 2144 weak_ptr_factory_.GetWeakPtr()), |
| 2145 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 2097 } | 2146 } |
| 2098 | 2147 |
| 2099 void SendDisplayMetrics(const display::Display& display) { | 2148 void SendDisplayMetrics() { |
| 2100 send_configure_after_layout_change_ = false; | 2149 if (!needs_send_display_metrics_) |
| 2150 return; |
| 2151 needs_send_display_metrics_ = false; |
| 2101 | 2152 |
| 2102 const gfx::Insets& work_area_insets = display.GetWorkAreaInsets(); | 2153 const display::Screen* screen = display::Screen::GetScreen(); |
| 2154 const display::Display primary = screen->GetPrimaryDisplay(); |
| 2155 |
| 2156 gfx::Size size = primary.size(); |
| 2157 |
| 2158 if (IsMultiDisplaySupported()) { |
| 2159 // Virtual screen is the bounding box of the displays in screen |
| 2160 // coordinates. |
| 2161 gfx::Rect bounds; |
| 2162 for (const auto& display : screen->GetAllDisplays()) |
| 2163 bounds.Union(display.bounds()); |
| 2164 |
| 2165 virtual_origin_ = bounds.origin(); |
| 2166 size = bounds.size(); |
| 2167 |
| 2168 for (ShellSurface* shell_surface : shell_surfaces_) |
| 2169 shell_surface->SetOrigin(virtual_origin_); |
| 2170 } |
| 2171 |
| 2172 // TODO(domlaskowski): Send insets for each workspace. |
| 2173 const gfx::Insets& work_area_insets = primary.GetWorkAreaInsets(); |
| 2103 | 2174 |
| 2104 zcr_remote_shell_v1_send_configuration_changed( | 2175 zcr_remote_shell_v1_send_configuration_changed( |
| 2105 remote_shell_resource_, display.size().width(), display.size().height(), | 2176 remote_shell_resource_, size.width(), size.height(), |
| 2106 OutputTransform(display.rotation()), | 2177 OutputTransform(primary.rotation()), |
| 2107 wl_fixed_from_double(display.device_scale_factor()), | 2178 wl_fixed_from_double(primary.device_scale_factor()), |
| 2108 work_area_insets.left(), work_area_insets.top(), | 2179 work_area_insets.left(), work_area_insets.top(), |
| 2109 work_area_insets.right(), work_area_insets.bottom(), layout_mode_); | 2180 work_area_insets.right(), work_area_insets.bottom(), layout_mode_); |
| 2110 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); | 2181 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); |
| 2111 } | 2182 } |
| 2112 | 2183 |
| 2113 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { | 2184 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { |
| 2114 Surface* gained_active_surface = | 2185 Surface* gained_active_surface = |
| 2115 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; | 2186 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; |
| 2116 Surface* lost_active_surface = | 2187 Surface* lost_active_surface = |
| 2117 lost_active ? ShellSurface::GetMainSurface(lost_active) : nullptr; | 2188 lost_active ? ShellSurface::GetMainSurface(lost_active) : nullptr; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2142 lost_active_surface_resource); | 2213 lost_active_surface_resource); |
| 2143 wl_client_flush(client); | 2214 wl_client_flush(client); |
| 2144 } | 2215 } |
| 2145 | 2216 |
| 2146 // The exo display instance. Not owned. | 2217 // The exo display instance. Not owned. |
| 2147 Display* const display_; | 2218 Display* const display_; |
| 2148 | 2219 |
| 2149 // The remote shell resource associated with observer. | 2220 // The remote shell resource associated with observer. |
| 2150 wl_resource* const remote_shell_resource_; | 2221 wl_resource* const remote_shell_resource_; |
| 2151 | 2222 |
| 2152 bool send_configure_after_layout_change_ = false; | 2223 bool needs_send_display_metrics_ = true; |
| 2153 | 2224 |
| 2154 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 2225 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 2155 | 2226 |
| 2227 // Origin of the virtual screen relative to the primary display. |
| 2228 gfx::Point virtual_origin_; |
| 2229 |
| 2230 std::unordered_set<ShellSurface*> shell_surfaces_; // Unowned. |
| 2231 |
| 2156 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; | 2232 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; |
| 2157 | 2233 |
| 2158 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); | 2234 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); |
| 2159 }; | 2235 }; |
| 2160 | 2236 |
| 2161 void remote_shell_destroy(wl_client* client, wl_resource* resource) { | 2237 void remote_shell_destroy(wl_client* client, wl_resource* resource) { |
| 2162 // Nothing to do here. | 2238 // Nothing to do here. |
| 2163 } | 2239 } |
| 2164 | 2240 |
| 2165 int RemoteSurfaceContainer(uint32_t container) { | 2241 int RemoteSurfaceContainer(uint32_t container) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2203 state_type = ZCR_REMOTE_SHELL_V1_STATE_TYPE_TRUSTED_PINNED; | 2279 state_type = ZCR_REMOTE_SHELL_V1_STATE_TYPE_TRUSTED_PINNED; |
| 2204 break; | 2280 break; |
| 2205 default: | 2281 default: |
| 2206 break; | 2282 break; |
| 2207 } | 2283 } |
| 2208 | 2284 |
| 2209 zcr_remote_surface_v1_send_state_type_changed(resource, state_type); | 2285 zcr_remote_surface_v1_send_state_type_changed(resource, state_type); |
| 2210 wl_client_flush(wl_resource_get_client(resource)); | 2286 wl_client_flush(wl_resource_get_client(resource)); |
| 2211 } | 2287 } |
| 2212 | 2288 |
| 2289 uint32_t HandleRemoteSurfaceConfigureCallback( |
| 2290 wl_resource* resource, |
| 2291 const gfx::Size& size, |
| 2292 ash::wm::WindowStateType state_type, |
| 2293 bool resizing, |
| 2294 bool activated, |
| 2295 const gfx::Point& origin) { |
| 2296 uint32_t serial = wl_display_next_serial( |
| 2297 wl_client_get_display(wl_resource_get_client(resource))); |
| 2298 zcr_remote_surface_v1_send_configure(resource, origin.x(), origin.y(), |
| 2299 serial); |
| 2300 wl_client_flush(wl_resource_get_client(resource)); |
| 2301 return serial; |
| 2302 } |
| 2303 |
| 2213 void remote_shell_get_remote_surface(wl_client* client, | 2304 void remote_shell_get_remote_surface(wl_client* client, |
| 2214 wl_resource* resource, | 2305 wl_resource* resource, |
| 2215 uint32_t id, | 2306 uint32_t id, |
| 2216 wl_resource* surface, | 2307 wl_resource* surface, |
| 2217 uint32_t container) { | 2308 uint32_t container) { |
| 2218 std::unique_ptr<ShellSurface> shell_surface = | 2309 std::unique_ptr<ShellSurface> shell_surface = |
| 2219 GetUserDataAs<WaylandRemoteShell>(resource)->CreateShellSurface( | 2310 GetUserDataAs<WaylandRemoteShell>(resource)->CreateShellSurface( |
| 2220 GetUserDataAs<Surface>(surface), RemoteSurfaceContainer(container)); | 2311 GetUserDataAs<Surface>(surface), RemoteSurfaceContainer(container)); |
| 2221 if (!shell_surface) { | 2312 if (!shell_surface) { |
| 2222 wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V1_ERROR_ROLE, | 2313 wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V1_ERROR_ROLE, |
| 2223 "surface has already been assigned a role"); | 2314 "surface has already been assigned a role"); |
| 2224 return; | 2315 return; |
| 2225 } | 2316 } |
| 2226 | 2317 |
| 2227 wl_resource* remote_surface_resource = | 2318 wl_resource* remote_surface_resource = |
| 2228 wl_resource_create(client, &zcr_remote_surface_v1_interface, | 2319 wl_resource_create(client, &zcr_remote_surface_v1_interface, |
| 2229 wl_resource_get_version(resource), id); | 2320 wl_resource_get_version(resource), id); |
| 2230 | 2321 |
| 2231 shell_surface->set_close_callback( | 2322 shell_surface->set_close_callback( |
| 2232 base::Bind(&HandleRemoteSurfaceCloseCallback, | 2323 base::Bind(&HandleRemoteSurfaceCloseCallback, |
| 2233 base::Unretained(remote_surface_resource))); | 2324 base::Unretained(remote_surface_resource))); |
| 2234 shell_surface->set_state_changed_callback( | 2325 shell_surface->set_state_changed_callback( |
| 2235 base::Bind(&HandleRemoteSurfaceStateChangedCallback, | 2326 base::Bind(&HandleRemoteSurfaceStateChangedCallback, |
| 2236 base::Unretained(remote_surface_resource))); | 2327 base::Unretained(remote_surface_resource))); |
| 2328 shell_surface->set_configure_callback( |
| 2329 base::Bind(&HandleRemoteSurfaceConfigureCallback, |
| 2330 base::Unretained(remote_surface_resource))); |
| 2237 | 2331 |
| 2238 SetImplementation(remote_surface_resource, &remote_surface_implementation, | 2332 SetImplementation(remote_surface_resource, &remote_surface_implementation, |
| 2239 std::move(shell_surface)); | 2333 std::move(shell_surface)); |
| 2240 } | 2334 } |
| 2241 | 2335 |
| 2242 void remote_shell_get_notification_surface(wl_client* client, | 2336 void remote_shell_get_notification_surface(wl_client* client, |
| 2243 wl_resource* resource, | 2337 wl_resource* resource, |
| 2244 uint32_t id, | 2338 uint32_t id, |
| 2245 wl_resource* surface, | 2339 wl_resource* surface, |
| 2246 const char* notification_id) { | 2340 const char* notification_id) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2265 wl_resource_get_version(resource), id); | 2359 wl_resource_get_version(resource), id); |
| 2266 SetImplementation(notification_surface_resource, | 2360 SetImplementation(notification_surface_resource, |
| 2267 ¬ification_surface_implementation, | 2361 ¬ification_surface_implementation, |
| 2268 std::move(notification_surface)); | 2362 std::move(notification_surface)); |
| 2269 } | 2363 } |
| 2270 | 2364 |
| 2271 const struct zcr_remote_shell_v1_interface remote_shell_implementation = { | 2365 const struct zcr_remote_shell_v1_interface remote_shell_implementation = { |
| 2272 remote_shell_destroy, remote_shell_get_remote_surface, | 2366 remote_shell_destroy, remote_shell_get_remote_surface, |
| 2273 remote_shell_get_notification_surface}; | 2367 remote_shell_get_notification_surface}; |
| 2274 | 2368 |
| 2275 const uint32_t remote_shell_version = 1; | 2369 const uint32_t remote_shell_version = 2; |
| 2276 | 2370 |
| 2277 void bind_remote_shell(wl_client* client, | 2371 void bind_remote_shell(wl_client* client, |
| 2278 void* data, | 2372 void* data, |
| 2279 uint32_t version, | 2373 uint32_t version, |
| 2280 uint32_t id) { | 2374 uint32_t id) { |
| 2281 wl_resource* resource = | 2375 wl_resource* resource = |
| 2282 wl_resource_create(client, &zcr_remote_shell_v1_interface, | 2376 wl_resource_create(client, &zcr_remote_shell_v1_interface, |
| 2283 std::min(version, remote_shell_version), id); | 2377 std::min(version, remote_shell_version), id); |
| 2284 | 2378 |
| 2285 SetImplementation(resource, &remote_shell_implementation, | 2379 SetImplementation(resource, &remote_shell_implementation, |
| (...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3722 DCHECK(event_loop); | 3816 DCHECK(event_loop); |
| 3723 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3817 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3724 } | 3818 } |
| 3725 | 3819 |
| 3726 void Server::Flush() { | 3820 void Server::Flush() { |
| 3727 wl_display_flush_clients(wl_display_.get()); | 3821 wl_display_flush_clients(wl_display_.get()); |
| 3728 } | 3822 } |
| 3729 | 3823 |
| 3730 } // namespace wayland | 3824 } // namespace wayland |
| 3731 } // namespace exo | 3825 } // namespace exo |
| OLD | NEW |