| 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 <grp.h> | 7 #include <grp.h> |
| 8 #include <linux/input.h> | 8 #include <linux/input.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 return WL_OUTPUT_TRANSFORM_90; | 1031 return WL_OUTPUT_TRANSFORM_90; |
| 1032 case display::Display::ROTATE_180: | 1032 case display::Display::ROTATE_180: |
| 1033 return WL_OUTPUT_TRANSFORM_180; | 1033 return WL_OUTPUT_TRANSFORM_180; |
| 1034 case display::Display::ROTATE_270: | 1034 case display::Display::ROTATE_270: |
| 1035 return WL_OUTPUT_TRANSFORM_270; | 1035 return WL_OUTPUT_TRANSFORM_270; |
| 1036 } | 1036 } |
| 1037 NOTREACHED(); | 1037 NOTREACHED(); |
| 1038 return WL_OUTPUT_TRANSFORM_NORMAL; | 1038 return WL_OUTPUT_TRANSFORM_NORMAL; |
| 1039 } | 1039 } |
| 1040 | 1040 |
| 1041 class WaylandDisplayObserver : public display::DisplayObserver { | 1041 class WaylandPrimaryDisplayObserver : public display::DisplayObserver { |
| 1042 public: | 1042 public: |
| 1043 WaylandDisplayObserver(const display::Display& display, | 1043 WaylandPrimaryDisplayObserver(wl_resource* output_resource) |
| 1044 wl_resource* output_resource) | 1044 : output_resource_(output_resource) { |
| 1045 : display_id_(display.id()), output_resource_(output_resource) { | |
| 1046 display::Screen::GetScreen()->AddObserver(this); | 1045 display::Screen::GetScreen()->AddObserver(this); |
| 1047 SendDisplayMetrics(display); | 1046 SendDisplayMetrics(); |
| 1048 } | 1047 } |
| 1049 ~WaylandDisplayObserver() override { | 1048 ~WaylandPrimaryDisplayObserver() override { |
| 1050 display::Screen::GetScreen()->RemoveObserver(this); | 1049 display::Screen::GetScreen()->RemoveObserver(this); |
| 1051 } | 1050 } |
| 1052 | 1051 |
| 1053 // Overridden from display::DisplayObserver: | 1052 // Overridden from display::DisplayObserver: |
| 1054 void OnDisplayAdded(const display::Display& new_display) override {} | 1053 void OnDisplayAdded(const display::Display& new_display) override {} |
| 1055 void OnDisplayRemoved(const display::Display& new_display) override {} | 1054 void OnDisplayRemoved(const display::Display& new_display) override {} |
| 1056 void OnDisplayMetricsChanged(const display::Display& display, | 1055 void OnDisplayMetricsChanged(const display::Display& display, |
| 1057 uint32_t changed_metrics) override { | 1056 uint32_t changed_metrics) override { |
| 1058 if (display.id() != display_id_) | 1057 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) |
| 1059 return; | 1058 return; |
| 1060 | 1059 |
| 1060 // There is no need to check DISPLAY_METRIC_PRIMARY because when primary |
| 1061 // changes, bounds always changes. (new primary should have had non |
| 1062 // 0,0 origin). |
| 1063 // Only exception is when switching to newly connected primary with |
| 1064 // the same bounds. This happens whenyou're in docked mode, suspend, |
| 1065 // unplug the dislpay, then resume to the internal display which has |
| 1066 // the same resolution. Since metrics does not change, there is no need |
| 1067 // to notify clients. |
| 1061 if (changed_metrics & | 1068 if (changed_metrics & |
| 1062 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | | 1069 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | |
| 1063 DISPLAY_METRIC_ROTATION)) { | 1070 DISPLAY_METRIC_ROTATION)) { |
| 1064 SendDisplayMetrics(display); | 1071 SendDisplayMetrics(); |
| 1065 } | 1072 } |
| 1066 } | 1073 } |
| 1067 | 1074 |
| 1068 private: | 1075 private: |
| 1069 void SendDisplayMetrics(const display::Display& display) { | 1076 void SendDisplayMetrics() { |
| 1077 display::Display display = |
| 1078 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 1079 |
| 1070 const ash::DisplayInfo& info = | 1080 const ash::DisplayInfo& info = |
| 1071 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo( | 1081 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo( |
| 1072 display.id()); | 1082 display.id()); |
| 1073 | 1083 |
| 1074 const float kInchInMm = 25.4f; | 1084 const float kInchInMm = 25.4f; |
| 1075 const char* kUnknownMake = "unknown"; | 1085 const char* kUnknownMake = "unknown"; |
| 1076 const char* kUnknownModel = "unknown"; | 1086 const char* kUnknownModel = "unknown"; |
| 1077 | 1087 |
| 1078 gfx::Rect bounds = info.bounds_in_native(); | 1088 gfx::Rect bounds = info.bounds_in_native(); |
| 1079 wl_output_send_geometry( | 1089 wl_output_send_geometry( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1092 wl_output_send_mode( | 1102 wl_output_send_mode( |
| 1093 output_resource_, WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED, | 1103 output_resource_, WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED, |
| 1094 bounds.width(), bounds.height(), static_cast<int>(60000)); | 1104 bounds.width(), bounds.height(), static_cast<int>(60000)); |
| 1095 | 1105 |
| 1096 if (wl_resource_get_version(output_resource_) >= | 1106 if (wl_resource_get_version(output_resource_) >= |
| 1097 WL_OUTPUT_DONE_SINCE_VERSION) { | 1107 WL_OUTPUT_DONE_SINCE_VERSION) { |
| 1098 wl_output_send_done(output_resource_); | 1108 wl_output_send_done(output_resource_); |
| 1099 } | 1109 } |
| 1100 } | 1110 } |
| 1101 | 1111 |
| 1102 // The identifier associated with the observed display. | |
| 1103 const int64_t display_id_; | |
| 1104 | |
| 1105 // The output resource associated with the display. | 1112 // The output resource associated with the display. |
| 1106 wl_resource* const output_resource_; | 1113 wl_resource* const output_resource_; |
| 1107 | 1114 |
| 1108 DISALLOW_COPY_AND_ASSIGN(WaylandDisplayObserver); | 1115 DISALLOW_COPY_AND_ASSIGN(WaylandPrimaryDisplayObserver); |
| 1109 }; | 1116 }; |
| 1110 | 1117 |
| 1111 const uint32_t output_version = 2; | 1118 const uint32_t output_version = 2; |
| 1112 | 1119 |
| 1113 void bind_output(wl_client* client, void* data, uint32_t version, uint32_t id) { | 1120 void bind_output(wl_client* client, void* data, uint32_t version, uint32_t id) { |
| 1114 wl_resource* resource = wl_resource_create( | 1121 wl_resource* resource = wl_resource_create( |
| 1115 client, &wl_output_interface, std::min(version, output_version), id); | 1122 client, &wl_output_interface, std::min(version, output_version), id); |
| 1116 | 1123 |
| 1117 // TODO(reveman): Multi-display support. | |
| 1118 const display::Display& display = ash::Shell::GetInstance() | |
| 1119 ->display_manager() | |
| 1120 ->GetPrimaryDisplayCandidate(); | |
| 1121 | |
| 1122 SetImplementation( | 1124 SetImplementation( |
| 1123 resource, nullptr, | 1125 resource, nullptr, |
| 1124 base::WrapUnique(new WaylandDisplayObserver(display, resource))); | 1126 base::WrapUnique(new WaylandPrimaryDisplayObserver(resource))); |
| 1125 } | 1127 } |
| 1126 | 1128 |
| 1127 //////////////////////////////////////////////////////////////////////////////// | 1129 //////////////////////////////////////////////////////////////////////////////// |
| 1128 // xdg_surface_interface: | 1130 // xdg_surface_interface: |
| 1129 | 1131 |
| 1130 int XdgResizeComponent(uint32_t edges) { | 1132 int XdgResizeComponent(uint32_t edges) { |
| 1131 switch (edges) { | 1133 switch (edges) { |
| 1132 case XDG_SURFACE_RESIZE_EDGE_TOP: | 1134 case XDG_SURFACE_RESIZE_EDGE_TOP: |
| 1133 return HTTOP; | 1135 return HTTOP; |
| 1134 case XDG_SURFACE_RESIZE_EDGE_BOTTOM: | 1136 case XDG_SURFACE_RESIZE_EDGE_BOTTOM: |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1568 //////////////////////////////////////////////////////////////////////////////// | 1570 //////////////////////////////////////////////////////////////////////////////// |
| 1569 // remote_shell_interface: | 1571 // remote_shell_interface: |
| 1570 | 1572 |
| 1571 // Implements remote shell interface and monitors workspace state needed | 1573 // Implements remote shell interface and monitors workspace state needed |
| 1572 // for the remote shell interface. | 1574 // for the remote shell interface. |
| 1573 class WaylandRemoteShell : public ash::ShellObserver, | 1575 class WaylandRemoteShell : public ash::ShellObserver, |
| 1574 public aura::client::ActivationChangeObserver, | 1576 public aura::client::ActivationChangeObserver, |
| 1575 public display::DisplayObserver { | 1577 public display::DisplayObserver { |
| 1576 public: | 1578 public: |
| 1577 WaylandRemoteShell(Display* display, | 1579 WaylandRemoteShell(Display* display, |
| 1578 int64_t display_id, | |
| 1579 wl_resource* remote_shell_resource) | 1580 wl_resource* remote_shell_resource) |
| 1580 : display_(display), | 1581 : display_(display), |
| 1581 display_id_(display_id), | |
| 1582 remote_shell_resource_(remote_shell_resource), | 1582 remote_shell_resource_(remote_shell_resource), |
| 1583 weak_ptr_factory_(this) { | 1583 weak_ptr_factory_(this) { |
| 1584 ash::WmShell::Get()->AddShellObserver(this); | 1584 ash::WmShell::Get()->AddShellObserver(this); |
| 1585 ash::Shell* shell = ash::Shell::GetInstance(); | 1585 ash::Shell* shell = ash::Shell::GetInstance(); |
| 1586 shell->activation_client()->AddObserver(this); | 1586 shell->activation_client()->AddObserver(this); |
| 1587 display::Screen::GetScreen()->AddObserver(this); | 1587 display::Screen::GetScreen()->AddObserver(this); |
| 1588 SendPrimaryDisplayMetrics(); | 1588 SendPrimaryDisplayMetrics(); |
| 1589 SendActivated(shell->activation_client()->GetActiveWindow(), nullptr); | 1589 SendActivated(shell->activation_client()->GetActiveWindow(), nullptr); |
| 1590 } | 1590 } |
| 1591 ~WaylandRemoteShell() override { | 1591 ~WaylandRemoteShell() override { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1603 Surface* surface, | 1603 Surface* surface, |
| 1604 const std::string& notification_id) { | 1604 const std::string& notification_id) { |
| 1605 return display_->CreateNotificationSurface(surface, notification_id); | 1605 return display_->CreateNotificationSurface(surface, notification_id); |
| 1606 } | 1606 } |
| 1607 | 1607 |
| 1608 // Overridden from display::DisplayObserver: | 1608 // Overridden from display::DisplayObserver: |
| 1609 void OnDisplayAdded(const display::Display& new_display) override {} | 1609 void OnDisplayAdded(const display::Display& new_display) override {} |
| 1610 void OnDisplayRemoved(const display::Display& new_display) override {} | 1610 void OnDisplayRemoved(const display::Display& new_display) override {} |
| 1611 void OnDisplayMetricsChanged(const display::Display& display, | 1611 void OnDisplayMetricsChanged(const display::Display& display, |
| 1612 uint32_t changed_metrics) override { | 1612 uint32_t changed_metrics) override { |
| 1613 if (display.id() != display_id_) | 1613 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) |
| 1614 return; | 1614 return; |
| 1615 | 1615 |
| 1616 // No need to update when a primary dislpay has changed without bounds |
| 1617 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged |
| 1618 // for more details. |
| 1616 if (changed_metrics & | 1619 if (changed_metrics & |
| 1617 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | | 1620 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | |
| 1618 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { | 1621 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { |
| 1619 SendDisplayMetrics(display); | 1622 SendDisplayMetrics(display); |
| 1620 } | 1623 } |
| 1621 SendConfigure_DEPRECATED(display); | 1624 SendConfigure_DEPRECATED(display); |
| 1622 } | 1625 } |
| 1623 | 1626 |
| 1624 // Overridden from ash::ShellObserver: | 1627 // Overridden from ash::ShellObserver: |
| 1625 void OnMaximizeModeStarted() override { | 1628 void OnMaximizeModeStarted() override { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1645 // Overridden from aura::client::ActivationChangeObserver: | 1648 // Overridden from aura::client::ActivationChangeObserver: |
| 1646 void OnWindowActivated( | 1649 void OnWindowActivated( |
| 1647 aura::client::ActivationChangeObserver::ActivationReason reason, | 1650 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 1648 aura::Window* gained_active, | 1651 aura::Window* gained_active, |
| 1649 aura::Window* lost_active) override { | 1652 aura::Window* lost_active) override { |
| 1650 SendActivated(gained_active, lost_active); | 1653 SendActivated(gained_active, lost_active); |
| 1651 } | 1654 } |
| 1652 | 1655 |
| 1653 private: | 1656 private: |
| 1654 void SendPrimaryDisplayMetrics() { | 1657 void SendPrimaryDisplayMetrics() { |
| 1655 const display::Display& primary = | 1658 const display::Display primary = |
| 1656 ash::Shell::GetInstance()->display_manager()->GetDisplayForId( | 1659 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 1657 display_id_); | 1660 |
| 1658 SendConfigure_DEPRECATED(primary); | 1661 SendConfigure_DEPRECATED(primary); |
| 1659 SendDisplayMetrics(primary); | 1662 SendDisplayMetrics(primary); |
| 1660 } | 1663 } |
| 1661 | 1664 |
| 1662 void MaybeSendConfigure() { | 1665 void MaybeSendConfigure() { |
| 1663 if (send_configure_after_layout_change_) | 1666 if (send_configure_after_layout_change_) |
| 1664 SendPrimaryDisplayMetrics(); | 1667 SendPrimaryDisplayMetrics(); |
| 1665 } | 1668 } |
| 1666 | 1669 |
| 1667 void SendDisplayMetrics(const display::Display& display) { | 1670 void SendDisplayMetrics(const display::Display& display) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1681 | 1684 |
| 1682 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); | 1685 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); |
| 1683 } | 1686 } |
| 1684 | 1687 |
| 1685 void SendConfigure_DEPRECATED(const display::Display& display) { | 1688 void SendConfigure_DEPRECATED(const display::Display& display) { |
| 1686 send_configure_after_layout_change_ = false; | 1689 send_configure_after_layout_change_ = false; |
| 1687 | 1690 |
| 1688 if (wl_resource_get_version(remote_shell_resource_) >= 9) | 1691 if (wl_resource_get_version(remote_shell_resource_) >= 9) |
| 1689 return; | 1692 return; |
| 1690 | 1693 |
| 1691 gfx::Insets work_area_insets = display.GetWorkAreaInsets(); | 1694 const gfx::Insets& work_area_insets = display.GetWorkAreaInsets(); |
| 1692 zwp_remote_shell_v1_send_configure( | 1695 zwp_remote_shell_v1_send_configure( |
| 1693 remote_shell_resource_, display.size().width(), display.size().height(), | 1696 remote_shell_resource_, display.size().width(), display.size().height(), |
| 1694 work_area_insets.left(), work_area_insets.top(), | 1697 work_area_insets.left(), work_area_insets.top(), |
| 1695 work_area_insets.right(), work_area_insets.bottom()); | 1698 work_area_insets.right(), work_area_insets.bottom()); |
| 1696 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); | 1699 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); |
| 1697 } | 1700 } |
| 1698 | 1701 |
| 1699 void SendLayoutModeChange_DEPRECATED() { | 1702 void SendLayoutModeChange_DEPRECATED() { |
| 1700 if (wl_resource_get_version(remote_shell_resource_) < 8) | 1703 if (wl_resource_get_version(remote_shell_resource_) < 8) |
| 1701 return; | 1704 return; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1733 | 1736 |
| 1734 zwp_remote_shell_v1_send_activated(remote_shell_resource_, | 1737 zwp_remote_shell_v1_send_activated(remote_shell_resource_, |
| 1735 gained_active_surface_resource, | 1738 gained_active_surface_resource, |
| 1736 lost_active_surface_resource); | 1739 lost_active_surface_resource); |
| 1737 wl_client_flush(client); | 1740 wl_client_flush(client); |
| 1738 } | 1741 } |
| 1739 | 1742 |
| 1740 // The exo display instance. Not owned. | 1743 // The exo display instance. Not owned. |
| 1741 Display* const display_; | 1744 Display* const display_; |
| 1742 | 1745 |
| 1743 // The identifier associated with the observed display. | |
| 1744 const int64_t display_id_; | |
| 1745 | |
| 1746 // The remote shell resource associated with observer. | 1746 // The remote shell resource associated with observer. |
| 1747 wl_resource* const remote_shell_resource_; | 1747 wl_resource* const remote_shell_resource_; |
| 1748 | 1748 |
| 1749 bool send_configure_after_layout_change_ = false; | 1749 bool send_configure_after_layout_change_ = false; |
| 1750 | 1750 |
| 1751 int layout_mode_ = ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 1751 int layout_mode_ = ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 1752 | 1752 |
| 1753 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; | 1753 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; |
| 1754 | 1754 |
| 1755 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); | 1755 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1898 const uint32_t remote_shell_version = 10; | 1898 const uint32_t remote_shell_version = 10; |
| 1899 | 1899 |
| 1900 void bind_remote_shell(wl_client* client, | 1900 void bind_remote_shell(wl_client* client, |
| 1901 void* data, | 1901 void* data, |
| 1902 uint32_t version, | 1902 uint32_t version, |
| 1903 uint32_t id) { | 1903 uint32_t id) { |
| 1904 wl_resource* resource = | 1904 wl_resource* resource = |
| 1905 wl_resource_create(client, &zwp_remote_shell_v1_interface, | 1905 wl_resource_create(client, &zwp_remote_shell_v1_interface, |
| 1906 std::min(version, remote_shell_version), id); | 1906 std::min(version, remote_shell_version), id); |
| 1907 | 1907 |
| 1908 // TODO(reveman): Multi-display support. | |
| 1909 const display::Display& display = ash::Shell::GetInstance() | |
| 1910 ->display_manager() | |
| 1911 ->GetPrimaryDisplayCandidate(); | |
| 1912 | |
| 1913 SetImplementation(resource, &remote_shell_implementation, | 1908 SetImplementation(resource, &remote_shell_implementation, |
| 1914 base::WrapUnique(new WaylandRemoteShell( | 1909 base::WrapUnique(new WaylandRemoteShell( |
| 1915 static_cast<Display*>(data), display.id(), resource))); | 1910 static_cast<Display*>(data), resource))); |
| 1916 } | 1911 } |
| 1917 | 1912 |
| 1918 //////////////////////////////////////////////////////////////////////////////// | 1913 //////////////////////////////////////////////////////////////////////////////// |
| 1919 // zwp_vsync_timing_v1_interface: | 1914 // zwp_vsync_timing_v1_interface: |
| 1920 | 1915 |
| 1921 // Implements VSync timing interface by monitoring a compositor for updates | 1916 // Implements VSync timing interface by monitoring a compositor for updates |
| 1922 // to VSync parameters. | 1917 // to VSync parameters. |
| 1923 class VSyncTiming : public ui::CompositorVSyncManager::Observer { | 1918 class VSyncTiming : public ui::CompositorVSyncManager::Observer { |
| 1924 public: | 1919 public: |
| 1925 ~VSyncTiming() { vsync_manager_->RemoveObserver(this); } | 1920 ~VSyncTiming() { vsync_manager_->RemoveObserver(this); } |
| (...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3130 DCHECK(event_loop); | 3125 DCHECK(event_loop); |
| 3131 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3126 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3132 } | 3127 } |
| 3133 | 3128 |
| 3134 void Server::Flush() { | 3129 void Server::Flush() { |
| 3135 wl_display_flush_clients(wl_display_.get()); | 3130 wl_display_flush_clients(wl_display_.get()); |
| 3136 } | 3131 } |
| 3137 | 3132 |
| 3138 } // namespace wayland | 3133 } // namespace wayland |
| 3139 } // namespace exo | 3134 } // namespace exo |
| OLD | NEW |