Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: components/exo/wayland/server.cc

Issue 2645663004: exo: Initial support for multiple displays in ARC (Closed)
Patch Set: Fix bad merge in test Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 int32_t width, 1973 int32_t width,
1973 int32_t height) { 1974 int32_t height) {
1974 ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource); 1975 ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource);
1975 gfx::Rect content_bounds(x, y, width, height); 1976 gfx::Rect content_bounds(x, y, width, height);
1976 shell_surface->SetRectangularSurfaceShadow(content_bounds); 1977 shell_surface->SetRectangularSurfaceShadow(content_bounds);
1977 } 1978 }
1978 1979
1979 void remote_surface_ack_configure(wl_client* client, 1980 void remote_surface_ack_configure(wl_client* client,
1980 wl_resource* resource, 1981 wl_resource* resource,
1981 uint32_t serial) { 1982 uint32_t serial) {
1982 NOTIMPLEMENTED(); 1983 GetUserDataAs<ShellSurface>(resource)->AcknowledgeConfigure(serial);
1983 } 1984 }
1984 1985
1985 void remote_surface_set_moving(wl_client* client, wl_resource* resource) { 1986 void remote_surface_move(wl_client* client, wl_resource* resource) {
1986 NOTIMPLEMENTED(); 1987 GetUserDataAs<ShellSurface>(resource)->Move();
1987 }
1988
1989 void remote_surface_unset_moving(wl_client* client, wl_resource* resource) {
1990 NOTIMPLEMENTED();
1991 } 1988 }
1992 1989
1993 const struct zcr_remote_surface_v1_interface remote_surface_implementation = { 1990 const struct zcr_remote_surface_v1_interface remote_surface_implementation = {
1994 remote_surface_destroy, 1991 remote_surface_destroy,
1995 remote_surface_set_app_id, 1992 remote_surface_set_app_id,
1996 remote_surface_set_window_geometry, 1993 remote_surface_set_window_geometry,
1997 remote_surface_set_scale, 1994 remote_surface_set_scale,
1998 remote_surface_set_rectangular_shadow_DEPRECATED, 1995 remote_surface_set_rectangular_shadow_DEPRECATED,
1999 remote_surface_set_rectangular_shadow_background_opacity, 1996 remote_surface_set_rectangular_shadow_background_opacity,
2000 remote_surface_set_title, 1997 remote_surface_set_title,
2001 remote_surface_set_top_inset, 1998 remote_surface_set_top_inset,
2002 remote_surface_activate, 1999 remote_surface_activate,
2003 remote_surface_maximize, 2000 remote_surface_maximize,
2004 remote_surface_minimize, 2001 remote_surface_minimize,
2005 remote_surface_restore, 2002 remote_surface_restore,
2006 remote_surface_fullscreen, 2003 remote_surface_fullscreen,
2007 remote_surface_unfullscreen, 2004 remote_surface_unfullscreen,
2008 remote_surface_pin, 2005 remote_surface_pin,
2009 remote_surface_unpin, 2006 remote_surface_unpin,
2010 remote_surface_set_system_modal, 2007 remote_surface_set_system_modal,
2011 remote_surface_unset_system_modal, 2008 remote_surface_unset_system_modal,
2012 remote_surface_set_rectangular_surface_shadow, 2009 remote_surface_set_rectangular_surface_shadow,
2013 remote_surface_ack_configure, 2010 remote_surface_ack_configure,
2014 remote_surface_set_moving, 2011 remote_surface_move};
2015 remote_surface_unset_moving};
2016 2012
2017 //////////////////////////////////////////////////////////////////////////////// 2013 ////////////////////////////////////////////////////////////////////////////////
2018 // notification_surface_interface: 2014 // notification_surface_interface:
2019 2015
2020 void notification_surface_destroy(wl_client* client, wl_resource* resource) { 2016 void notification_surface_destroy(wl_client* client, wl_resource* resource) {
2021 wl_resource_destroy(resource); 2017 wl_resource_destroy(resource);
2022 } 2018 }
2023 2019
2024 const struct zcr_notification_surface_v1_interface 2020 const struct zcr_notification_surface_v1_interface
2025 notification_surface_implementation = {notification_surface_destroy}; 2021 notification_surface_implementation = {notification_surface_destroy};
2026 2022
2027 //////////////////////////////////////////////////////////////////////////////// 2023 ////////////////////////////////////////////////////////////////////////////////
2028 // remote_shell_interface: 2024 // remote_shell_interface:
2029 2025
2030 // Implements remote shell interface and monitors workspace state needed 2026 // Implements remote shell interface and monitors workspace state needed
2031 // 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 //
2032 class WaylandRemoteShell : public WMHelper::MaximizeModeObserver, 2047 class WaylandRemoteShell : public WMHelper::MaximizeModeObserver,
2033 public WMHelper::ActivationObserver, 2048 public WMHelper::ActivationObserver,
2034 public display::DisplayObserver { 2049 public display::DisplayObserver {
2035 public: 2050 public:
2036 WaylandRemoteShell(Display* display, wl_resource* remote_shell_resource) 2051 WaylandRemoteShell(Display* display, wl_resource* remote_shell_resource)
2037 : display_(display), 2052 : display_(display),
2038 remote_shell_resource_(remote_shell_resource), 2053 remote_shell_resource_(remote_shell_resource),
2039 weak_ptr_factory_(this) { 2054 weak_ptr_factory_(this) {
2040 auto* helper = WMHelper::GetInstance(); 2055 auto* helper = WMHelper::GetInstance();
2041 helper->AddMaximizeModeObserver(this); 2056 helper->AddMaximizeModeObserver(this);
2042 helper->AddActivationObserver(this); 2057 helper->AddActivationObserver(this);
2043 display::Screen::GetScreen()->AddObserver(this); 2058 display::Screen::GetScreen()->AddObserver(this);
2044 2059
2045 layout_mode_ = helper->IsMaximizeModeWindowManagerEnabled() 2060 layout_mode_ = helper->IsMaximizeModeWindowManagerEnabled()
2046 ? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET 2061 ? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET
2047 : ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; 2062 : ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED;
2048 2063
2049 SendPrimaryDisplayMetrics(); 2064 SendDisplayMetrics();
2050 SendActivated(helper->GetActiveWindow(), nullptr); 2065 SendActivated(helper->GetActiveWindow(), nullptr);
2051 } 2066 }
2052 ~WaylandRemoteShell() override { 2067 ~WaylandRemoteShell() override {
2053 auto* helper = WMHelper::GetInstance(); 2068 auto* helper = WMHelper::GetInstance();
2054 helper->RemoveMaximizeModeObserver(this); 2069 helper->RemoveMaximizeModeObserver(this);
2055 helper->RemoveActivationObserver(this); 2070 helper->RemoveActivationObserver(this);
2056 display::Screen::GetScreen()->RemoveObserver(this); 2071 display::Screen::GetScreen()->RemoveObserver(this);
2057 } 2072 }
2058 2073
2059 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, 2074 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface,
2060 int container) { 2075 int container) {
2061 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);
2062 } 2089 }
2063 2090
2064 std::unique_ptr<NotificationSurface> CreateNotificationSurface( 2091 std::unique_ptr<NotificationSurface> CreateNotificationSurface(
2065 Surface* surface, 2092 Surface* surface,
2066 const std::string& notification_id) { 2093 const std::string& notification_id) {
2067 return display_->CreateNotificationSurface(surface, notification_id); 2094 return display_->CreateNotificationSurface(surface, notification_id);
2068 } 2095 }
2069 2096
2070 // Overridden from display::DisplayObserver: 2097 // Overridden from display::DisplayObserver:
2071 void OnDisplayAdded(const display::Display& new_display) override {} 2098 void OnDisplayAdded(const display::Display& new_display) override {
2072 void OnDisplayRemoved(const display::Display& new_display) override {} 2099 if (IsMultiDisplaySupported())
2100 ScheduleSendDisplayMetrics();
2101 }
2102
2103 void OnDisplayRemoved(const display::Display& old_display) override {
2104 if (IsMultiDisplaySupported())
2105 ScheduleSendDisplayMetrics();
2106 }
2107
2073 void OnDisplayMetricsChanged(const display::Display& display, 2108 void OnDisplayMetricsChanged(const display::Display& display,
2074 uint32_t changed_metrics) override { 2109 uint32_t changed_metrics) override {
2075 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) 2110 if (!IsMultiDisplaySupported() &&
2111 display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id())
2076 return; 2112 return;
2077 2113
2078 // No need to update when a primary dislpay has changed without bounds 2114 // No need to update when a primary display has changed without bounds
2079 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged 2115 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged
2080 // for more details. 2116 // for more details.
2081 if (changed_metrics & 2117 if (changed_metrics &
2082 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | 2118 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR |
2083 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { 2119 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) {
2084 SendDisplayMetrics(display); 2120 ScheduleSendDisplayMetrics();
2085 } 2121 }
2086 } 2122 }
2087 2123
2088 // Overridden from WMHelper::MaximizeModeObserver: 2124 // Overridden from WMHelper::MaximizeModeObserver:
2089 void OnMaximizeModeStarted() override { 2125 void OnMaximizeModeStarted() override {
2090 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET; 2126 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET;
2091 2127 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 } 2128 }
2098 void OnMaximizeModeEnded() override { 2129 void OnMaximizeModeEnded() override {
2099 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; 2130 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED;
2100 send_configure_after_layout_change_ = true; 2131 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 } 2132 }
2106 2133
2107 // Overridden from WMHelper::ActivationObserver: 2134 // Overridden from WMHelper::ActivationObserver:
2108 void OnWindowActivated(aura::Window* gained_active, 2135 void OnWindowActivated(aura::Window* gained_active,
2109 aura::Window* lost_active) override { 2136 aura::Window* lost_active) override {
2110 SendActivated(gained_active, lost_active); 2137 SendActivated(gained_active, lost_active);
2111 } 2138 }
2112 2139
2113 private: 2140 private:
2114 void SendPrimaryDisplayMetrics() { 2141 bool IsMultiDisplaySupported() const {
2115 const display::Display primary = 2142 return wl_resource_get_version(remote_shell_resource_) >= 2;
2116 display::Screen::GetScreen()->GetPrimaryDisplay();
2117
2118 SendDisplayMetrics(primary);
2119 } 2143 }
2120 2144
2121 void MaybeSendConfigure() { 2145 void ScheduleSendDisplayMetrics(int delay_ms = 0) {
2122 if (send_configure_after_layout_change_) 2146 needs_send_display_metrics_ = true;
2123 SendPrimaryDisplayMetrics(); 2147 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
2148 FROM_HERE, base::Bind(&WaylandRemoteShell::SendDisplayMetrics,
2149 weak_ptr_factory_.GetWeakPtr()),
2150 base::TimeDelta::FromMilliseconds(delay_ms));
2124 } 2151 }
2125 2152
2126 void SendDisplayMetrics(const display::Display& display) { 2153 void SendDisplayMetrics() {
2127 send_configure_after_layout_change_ = false; 2154 if (!needs_send_display_metrics_)
2155 return;
2156 needs_send_display_metrics_ = false;
2128 2157
2129 const gfx::Insets& work_area_insets = display.GetWorkAreaInsets(); 2158 const display::Screen* screen = display::Screen::GetScreen();
2159 const display::Display primary = screen->GetPrimaryDisplay();
2160
2161 gfx::Size size = primary.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.
2178 const gfx::Insets& work_area_insets = primary.GetWorkAreaInsets();
2130 2179
2131 zcr_remote_shell_v1_send_configuration_changed( 2180 zcr_remote_shell_v1_send_configuration_changed(
2132 remote_shell_resource_, display.size().width(), display.size().height(), 2181 remote_shell_resource_, size.width(), size.height(),
2133 OutputTransform(display.rotation()), 2182 OutputTransform(primary.rotation()),
2134 wl_fixed_from_double(display.device_scale_factor()), 2183 wl_fixed_from_double(primary.device_scale_factor()),
2135 work_area_insets.left(), work_area_insets.top(), 2184 work_area_insets.left(), work_area_insets.top(),
2136 work_area_insets.right(), work_area_insets.bottom(), layout_mode_); 2185 work_area_insets.right(), work_area_insets.bottom(), layout_mode_);
2137 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); 2186 wl_client_flush(wl_resource_get_client(remote_shell_resource_));
2138 } 2187 }
2139 2188
2140 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { 2189 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) {
2141 Surface* gained_active_surface = 2190 Surface* gained_active_surface =
2142 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; 2191 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr;
2143 Surface* lost_active_surface = 2192 Surface* lost_active_surface =
2144 lost_active ? ShellSurface::GetMainSurface(lost_active) : nullptr; 2193 lost_active ? ShellSurface::GetMainSurface(lost_active) : nullptr;
(...skipping 24 matching lines...) Expand all
2169 lost_active_surface_resource); 2218 lost_active_surface_resource);
2170 wl_client_flush(client); 2219 wl_client_flush(client);
2171 } 2220 }
2172 2221
2173 // The exo display instance. Not owned. 2222 // The exo display instance. Not owned.
2174 Display* const display_; 2223 Display* const display_;
2175 2224
2176 // The remote shell resource associated with observer. 2225 // The remote shell resource associated with observer.
2177 wl_resource* const remote_shell_resource_; 2226 wl_resource* const remote_shell_resource_;
2178 2227
2179 bool send_configure_after_layout_change_ = false; 2228 bool needs_send_display_metrics_ = true;
2180 2229
2181 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; 2230 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED;
2182 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.
2236
2183 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; 2237 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_;
2184 2238
2185 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); 2239 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell);
2186 }; 2240 };
2187 2241
2188 void remote_shell_destroy(wl_client* client, wl_resource* resource) { 2242 void remote_shell_destroy(wl_client* client, wl_resource* resource) {
2189 // Nothing to do here. 2243 // Nothing to do here.
2190 } 2244 }
2191 2245
2192 int RemoteSurfaceContainer(uint32_t container) { 2246 int RemoteSurfaceContainer(uint32_t container) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 state_type = ZCR_REMOTE_SHELL_V1_STATE_TYPE_TRUSTED_PINNED; 2284 state_type = ZCR_REMOTE_SHELL_V1_STATE_TYPE_TRUSTED_PINNED;
2231 break; 2285 break;
2232 default: 2286 default:
2233 break; 2287 break;
2234 } 2288 }
2235 2289
2236 zcr_remote_surface_v1_send_state_type_changed(resource, state_type); 2290 zcr_remote_surface_v1_send_state_type_changed(resource, state_type);
2237 wl_client_flush(wl_resource_get_client(resource)); 2291 wl_client_flush(wl_resource_get_client(resource));
2238 } 2292 }
2239 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
2240 void remote_shell_get_remote_surface(wl_client* client, 2312 void remote_shell_get_remote_surface(wl_client* client,
2241 wl_resource* resource, 2313 wl_resource* resource,
2242 uint32_t id, 2314 uint32_t id,
2243 wl_resource* surface, 2315 wl_resource* surface,
2244 uint32_t container) { 2316 uint32_t container) {
2245 std::unique_ptr<ShellSurface> shell_surface = 2317 std::unique_ptr<ShellSurface> shell_surface =
2246 GetUserDataAs<WaylandRemoteShell>(resource)->CreateShellSurface( 2318 GetUserDataAs<WaylandRemoteShell>(resource)->CreateShellSurface(
2247 GetUserDataAs<Surface>(surface), RemoteSurfaceContainer(container)); 2319 GetUserDataAs<Surface>(surface), RemoteSurfaceContainer(container));
2248 if (!shell_surface) { 2320 if (!shell_surface) {
2249 wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V1_ERROR_ROLE, 2321 wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V1_ERROR_ROLE,
2250 "surface has already been assigned a role"); 2322 "surface has already been assigned a role");
2251 return; 2323 return;
2252 } 2324 }
2253 2325
2254 wl_resource* remote_surface_resource = 2326 wl_resource* remote_surface_resource =
2255 wl_resource_create(client, &zcr_remote_surface_v1_interface, 2327 wl_resource_create(client, &zcr_remote_surface_v1_interface,
2256 wl_resource_get_version(resource), id); 2328 wl_resource_get_version(resource), id);
2257 2329
2258 shell_surface->set_close_callback( 2330 shell_surface->set_close_callback(
2259 base::Bind(&HandleRemoteSurfaceCloseCallback, 2331 base::Bind(&HandleRemoteSurfaceCloseCallback,
2260 base::Unretained(remote_surface_resource))); 2332 base::Unretained(remote_surface_resource)));
2261 shell_surface->set_state_changed_callback( 2333 shell_surface->set_state_changed_callback(
2262 base::Bind(&HandleRemoteSurfaceStateChangedCallback, 2334 base::Bind(&HandleRemoteSurfaceStateChangedCallback,
2263 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)));
2264 2339
2265 SetImplementation(remote_surface_resource, &remote_surface_implementation, 2340 SetImplementation(remote_surface_resource, &remote_surface_implementation,
2266 std::move(shell_surface)); 2341 std::move(shell_surface));
2267 } 2342 }
2268 2343
2269 void remote_shell_get_notification_surface(wl_client* client, 2344 void remote_shell_get_notification_surface(wl_client* client,
2270 wl_resource* resource, 2345 wl_resource* resource,
2271 uint32_t id, 2346 uint32_t id,
2272 wl_resource* surface, 2347 wl_resource* surface,
2273 const char* notification_id) { 2348 const char* notification_id) {
(...skipping 18 matching lines...) Expand all
2292 wl_resource_get_version(resource), id); 2367 wl_resource_get_version(resource), id);
2293 SetImplementation(notification_surface_resource, 2368 SetImplementation(notification_surface_resource,
2294 &notification_surface_implementation, 2369 &notification_surface_implementation,
2295 std::move(notification_surface)); 2370 std::move(notification_surface));
2296 } 2371 }
2297 2372
2298 const struct zcr_remote_shell_v1_interface remote_shell_implementation = { 2373 const struct zcr_remote_shell_v1_interface remote_shell_implementation = {
2299 remote_shell_destroy, remote_shell_get_remote_surface, 2374 remote_shell_destroy, remote_shell_get_remote_surface,
2300 remote_shell_get_notification_surface}; 2375 remote_shell_get_notification_surface};
2301 2376
2302 const uint32_t remote_shell_version = 2; 2377 const uint32_t remote_shell_version = 3;
2303 2378
2304 void bind_remote_shell(wl_client* client, 2379 void bind_remote_shell(wl_client* client,
2305 void* data, 2380 void* data,
2306 uint32_t version, 2381 uint32_t version,
2307 uint32_t id) { 2382 uint32_t id) {
2308 wl_resource* resource = 2383 wl_resource* resource =
2309 wl_resource_create(client, &zcr_remote_shell_v1_interface, 2384 wl_resource_create(client, &zcr_remote_shell_v1_interface,
2310 std::min(version, remote_shell_version), id); 2385 std::min(version, remote_shell_version), id);
2311 2386
2312 SetImplementation(resource, &remote_shell_implementation, 2387 SetImplementation(resource, &remote_shell_implementation,
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after
3749 DCHECK(event_loop); 3824 DCHECK(event_loop);
3750 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 3825 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
3751 } 3826 }
3752 3827
3753 void Server::Flush() { 3828 void Server::Flush() {
3754 wl_display_flush_clients(wl_display_.get()); 3829 wl_display_flush_clients(wl_display_.get());
3755 } 3830 }
3756 3831
3757 } // namespace wayland 3832 } // namespace wayland
3758 } // namespace exo 3833 } // namespace exo
OLDNEW
« components/exo/shell_surface.h ('K') | « components/exo/test/exo_test_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698