| 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 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 | 1528 |
| 1529 void remote_surface_set_system_modal(wl_client* client, wl_resource* resource) { | 1529 void remote_surface_set_system_modal(wl_client* client, wl_resource* resource) { |
| 1530 GetUserDataAs<ShellSurface>(resource)->SetSystemModal(true); | 1530 GetUserDataAs<ShellSurface>(resource)->SetSystemModal(true); |
| 1531 } | 1531 } |
| 1532 | 1532 |
| 1533 void remote_surface_unset_system_modal(wl_client* client, | 1533 void remote_surface_unset_system_modal(wl_client* client, |
| 1534 wl_resource* resource) { | 1534 wl_resource* resource) { |
| 1535 GetUserDataAs<ShellSurface>(resource)->SetSystemModal(false); | 1535 GetUserDataAs<ShellSurface>(resource)->SetSystemModal(false); |
| 1536 } | 1536 } |
| 1537 | 1537 |
| 1538 void remote_surface_set_moving(wl_client* client, wl_resource* resource) { |
| 1539 GetUserDataAs<ShellSurface>(resource)->SetMoving(); |
| 1540 } |
| 1541 |
| 1542 void remote_surface_unset_moving(wl_client* client, wl_resource* resource) { |
| 1543 GetUserDataAs<ShellSurface>(resource)->UnsetMoving(false /* revert */); |
| 1544 } |
| 1545 |
| 1538 const struct zcr_remote_surface_v1_interface remote_surface_implementation = { | 1546 const struct zcr_remote_surface_v1_interface remote_surface_implementation = { |
| 1539 remote_surface_destroy, | 1547 remote_surface_destroy, |
| 1540 remote_surface_set_app_id, | 1548 remote_surface_set_app_id, |
| 1541 remote_surface_set_window_geometry, | 1549 remote_surface_set_window_geometry, |
| 1542 remote_surface_set_scale, | 1550 remote_surface_set_scale, |
| 1543 remote_surface_set_rectangular_shadow, | 1551 remote_surface_set_rectangular_shadow, |
| 1544 remote_surface_set_rectangular_shadow_background_opacity, | 1552 remote_surface_set_rectangular_shadow_background_opacity, |
| 1545 remote_surface_set_title, | 1553 remote_surface_set_title, |
| 1546 remote_surface_set_top_inset, | 1554 remote_surface_set_top_inset, |
| 1547 remote_surface_activate, | 1555 remote_surface_activate, |
| 1548 remote_surface_maximize, | 1556 remote_surface_maximize, |
| 1549 remote_surface_minimize, | 1557 remote_surface_minimize, |
| 1550 remote_surface_restore, | 1558 remote_surface_restore, |
| 1551 remote_surface_fullscreen, | 1559 remote_surface_fullscreen, |
| 1552 remote_surface_unfullscreen, | 1560 remote_surface_unfullscreen, |
| 1553 remote_surface_pin, | 1561 remote_surface_pin, |
| 1554 remote_surface_unpin, | 1562 remote_surface_unpin, |
| 1555 remote_surface_set_system_modal, | 1563 remote_surface_set_system_modal, |
| 1556 remote_surface_unset_system_modal}; | 1564 remote_surface_unset_system_modal, |
| 1565 remote_surface_set_moving, |
| 1566 remote_surface_unset_moving}; |
| 1557 | 1567 |
| 1558 //////////////////////////////////////////////////////////////////////////////// | 1568 //////////////////////////////////////////////////////////////////////////////// |
| 1559 // notification_surface_interface: | 1569 // notification_surface_interface: |
| 1560 | 1570 |
| 1561 void notification_surface_destroy(wl_client* client, wl_resource* resource) { | 1571 void notification_surface_destroy(wl_client* client, wl_resource* resource) { |
| 1562 wl_resource_destroy(resource); | 1572 wl_resource_destroy(resource); |
| 1563 } | 1573 } |
| 1564 | 1574 |
| 1565 const struct zcr_notification_surface_v1_interface | 1575 const struct zcr_notification_surface_v1_interface |
| 1566 notification_surface_implementation = {notification_surface_destroy}; | 1576 notification_surface_implementation = {notification_surface_destroy}; |
| 1567 | 1577 |
| 1568 //////////////////////////////////////////////////////////////////////////////// | 1578 //////////////////////////////////////////////////////////////////////////////// |
| 1569 // remote_shell_interface: | 1579 // remote_shell_interface: |
| 1570 | 1580 |
| 1571 // Implements remote shell interface and monitors workspace state needed | 1581 // Implements remote shell interface and monitors workspace state needed |
| 1572 // for the remote shell interface. | 1582 // for the remote shell interface. |
| 1573 class WaylandRemoteShell : public WMHelper::MaximizeModeObserver, | 1583 class WaylandRemoteShell : public WMHelper::ShellObserver, |
| 1574 public WMHelper::ActivationObserver, | 1584 public WMHelper::ActivationObserver, |
| 1575 public display::DisplayObserver { | 1585 public display::DisplayObserver { |
| 1576 public: | 1586 public: |
| 1577 WaylandRemoteShell(Display* display, wl_resource* remote_shell_resource) | 1587 WaylandRemoteShell(Display* display, wl_resource* remote_shell_resource) |
| 1578 : display_(display), | 1588 : display_(display), |
| 1579 remote_shell_resource_(remote_shell_resource), | 1589 remote_shell_resource_(remote_shell_resource), |
| 1580 weak_ptr_factory_(this) { | 1590 weak_ptr_factory_(this) { |
| 1581 auto* helper = WMHelper::GetInstance(); | 1591 auto* helper = WMHelper::GetInstance(); |
| 1582 helper->AddMaximizeModeObserver(this); | 1592 helper->AddShellObserver(this); |
| 1583 helper->AddActivationObserver(this); | 1593 helper->AddActivationObserver(this); |
| 1584 display::Screen::GetScreen()->AddObserver(this); | 1594 display::Screen::GetScreen()->AddObserver(this); |
| 1585 | 1595 |
| 1586 layout_mode_ = helper->IsMaximizeModeWindowManagerEnabled() | 1596 layout_mode_ = helper->IsMaximizeModeWindowManagerEnabled() |
| 1587 ? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET | 1597 ? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET |
| 1588 : ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 1598 : ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 1589 | 1599 |
| 1590 SendPrimaryDisplayMetrics(); | 1600 SendDisplayMetrics(); |
| 1591 SendActivated(helper->GetActiveWindow(), nullptr); | 1601 SendActivated(helper->GetActiveWindow(), nullptr); |
| 1592 } | 1602 } |
| 1593 ~WaylandRemoteShell() override { | 1603 ~WaylandRemoteShell() override { |
| 1594 auto* helper = WMHelper::GetInstance(); | 1604 auto* helper = WMHelper::GetInstance(); |
| 1595 helper->RemoveMaximizeModeObserver(this); | 1605 helper->RemoveShellObserver(this); |
| 1596 helper->RemoveActivationObserver(this); | 1606 helper->RemoveActivationObserver(this); |
| 1597 display::Screen::GetScreen()->RemoveObserver(this); | 1607 display::Screen::GetScreen()->RemoveObserver(this); |
| 1598 } | 1608 } |
| 1599 | 1609 |
| 1600 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, | 1610 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, |
| 1601 int container) { | 1611 int container) { |
| 1602 return display_->CreateRemoteShellSurface(surface, container); | 1612 return display_->CreateRemoteShellSurface(surface, container); |
| 1603 } | 1613 } |
| 1604 | 1614 |
| 1605 std::unique_ptr<NotificationSurface> CreateNotificationSurface( | 1615 std::unique_ptr<NotificationSurface> CreateNotificationSurface( |
| 1606 Surface* surface, | 1616 Surface* surface, |
| 1607 const std::string& notification_id) { | 1617 const std::string& notification_id) { |
| 1608 return display_->CreateNotificationSurface(surface, notification_id); | 1618 return display_->CreateNotificationSurface(surface, notification_id); |
| 1609 } | 1619 } |
| 1610 | 1620 |
| 1611 // Overridden from display::DisplayObserver: | 1621 // Overridden from display::DisplayObserver: |
| 1612 void OnDisplayAdded(const display::Display& new_display) override {} | 1622 void OnDisplayAdded(const display::Display& new_display) override { |
| 1613 void OnDisplayRemoved(const display::Display& new_display) override {} | 1623 if (IsMultiDisplaySupported()) |
| 1624 ScheduleSendDisplayMetrics(); |
| 1625 } |
| 1626 |
| 1627 void OnDisplayRemoved(const display::Display& new_display) override { |
| 1628 if (IsMultiDisplaySupported()) |
| 1629 ScheduleSendDisplayMetrics(); |
| 1630 } |
| 1631 |
| 1614 void OnDisplayMetricsChanged(const display::Display& display, | 1632 void OnDisplayMetricsChanged(const display::Display& display, |
| 1615 uint32_t changed_metrics) override { | 1633 uint32_t changed_metrics) override { |
| 1616 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) | 1634 if (!IsMultiDisplaySupported() && |
| 1635 display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) |
| 1617 return; | 1636 return; |
| 1618 | 1637 |
| 1619 // No need to update when a primary dislpay has changed without bounds | 1638 // No need to update when a primary display has changed without bounds |
| 1620 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged | 1639 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged |
| 1621 // for more details. | 1640 // for more details. |
| 1622 if (changed_metrics & | 1641 if (changed_metrics & |
| 1623 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | | 1642 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | |
| 1624 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { | 1643 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { |
| 1625 SendDisplayMetrics(display); | 1644 ScheduleSendDisplayMetrics(); |
| 1626 } | 1645 } |
| 1627 } | 1646 } |
| 1628 | 1647 |
| 1629 // Overridden from WMHelper::MaximizeModeObserver: | 1648 // Overridden from WMHelper::ShellObserver: |
| 1630 void OnMaximizeModeStarted() override { | 1649 void OnMaximizeModeStarted() override { |
| 1631 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET; | 1650 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET; |
| 1632 | 1651 ScheduleSendDisplayMetrics(kConfigureDelayAfterLayoutSwitchMs); |
| 1633 send_configure_after_layout_change_ = true; | |
| 1634 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 1635 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure, | |
| 1636 weak_ptr_factory_.GetWeakPtr()), | |
| 1637 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs)); | |
| 1638 } | 1652 } |
| 1639 void OnMaximizeModeEnded() override { | 1653 void OnMaximizeModeEnded() override { |
| 1640 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 1654 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 1641 send_configure_after_layout_change_ = true; | 1655 ScheduleSendDisplayMetrics(kConfigureDelayAfterLayoutSwitchMs); |
| 1642 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 1643 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure, | |
| 1644 weak_ptr_factory_.GetWeakPtr()), | |
| 1645 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs)); | |
| 1646 } | 1656 } |
| 1647 | 1657 |
| 1648 // Overridden from WMHelper::ActivationObserver: | 1658 // Overridden from WMHelper::ActivationObserver: |
| 1649 void OnWindowActivated(aura::Window* gained_active, | 1659 void OnWindowActivated(aura::Window* gained_active, |
| 1650 aura::Window* lost_active) override { | 1660 aura::Window* lost_active) override { |
| 1651 SendActivated(gained_active, lost_active); | 1661 SendActivated(gained_active, lost_active); |
| 1652 } | 1662 } |
| 1653 | 1663 |
| 1654 private: | 1664 private: |
| 1655 void SendPrimaryDisplayMetrics() { | 1665 bool IsMultiDisplaySupported() const { |
| 1656 const display::Display primary = | 1666 return wl_resource_get_version(remote_shell_resource_) >= 2; |
| 1657 display::Screen::GetScreen()->GetPrimaryDisplay(); | |
| 1658 | |
| 1659 SendDisplayMetrics(primary); | |
| 1660 } | 1667 } |
| 1661 | 1668 |
| 1662 void MaybeSendConfigure() { | 1669 void ScheduleSendDisplayMetrics(int delay_ms = 0) { |
| 1663 if (send_configure_after_layout_change_) | 1670 needs_send_display_metrics_ = true; |
| 1664 SendPrimaryDisplayMetrics(); | 1671 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1672 FROM_HERE, base::Bind(&WaylandRemoteShell::SendDisplayMetrics, |
| 1673 weak_ptr_factory_.GetWeakPtr()), |
| 1674 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 1665 } | 1675 } |
| 1666 | 1676 |
| 1667 void SendDisplayMetrics(const display::Display& display) { | 1677 void SendDisplayMetrics() { |
| 1668 send_configure_after_layout_change_ = false; | 1678 if (!needs_send_display_metrics_) |
| 1679 return; |
| 1680 needs_send_display_metrics_ = false; |
| 1669 | 1681 |
| 1670 const gfx::Insets& work_area_insets = display.GetWorkAreaInsets(); | 1682 const display::Screen* screen = display::Screen::GetScreen(); |
| 1683 const display::Display primary = screen->GetPrimaryDisplay(); |
| 1684 |
| 1685 gfx::Size size = primary.size(); |
| 1686 |
| 1687 if (IsMultiDisplaySupported()) { |
| 1688 // Virtual screen is the bounding box of the displays in screen |
| 1689 // coordinates. |
| 1690 gfx::Rect bounds; |
| 1691 for (const auto& display : screen->GetAllDisplays()) |
| 1692 bounds.Union(display.bounds()); |
| 1693 |
| 1694 display_->set_virtual_origin(bounds.origin()); |
| 1695 size = bounds.size(); |
| 1696 } |
| 1697 |
| 1698 // TODO(domlaskowski): Send insets for each workspace. |
| 1699 const gfx::Insets& work_area_insets = primary.GetWorkAreaInsets(); |
| 1671 | 1700 |
| 1672 zcr_remote_shell_v1_send_configuration_changed( | 1701 zcr_remote_shell_v1_send_configuration_changed( |
| 1673 remote_shell_resource_, display.size().width(), display.size().height(), | 1702 remote_shell_resource_, size.width(), size.height(), |
| 1674 OutputTransform(display.rotation()), | 1703 OutputTransform(primary.rotation()), |
| 1675 wl_fixed_from_double(display.device_scale_factor()), | 1704 wl_fixed_from_double(primary.device_scale_factor()), |
| 1676 work_area_insets.left(), work_area_insets.top(), | 1705 work_area_insets.left(), work_area_insets.top(), |
| 1677 work_area_insets.right(), work_area_insets.bottom(), layout_mode_); | 1706 work_area_insets.right(), work_area_insets.bottom(), layout_mode_); |
| 1678 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); | 1707 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); |
| 1679 } | 1708 } |
| 1680 | 1709 |
| 1681 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { | 1710 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { |
| 1682 Surface* gained_active_surface = | 1711 Surface* gained_active_surface = |
| 1683 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; | 1712 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; |
| 1684 Surface* lost_active_surface = | 1713 Surface* lost_active_surface = |
| 1685 lost_active ? ShellSurface::GetMainSurface(lost_active) : nullptr; | 1714 lost_active ? ShellSurface::GetMainSurface(lost_active) : nullptr; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1710 lost_active_surface_resource); | 1739 lost_active_surface_resource); |
| 1711 wl_client_flush(client); | 1740 wl_client_flush(client); |
| 1712 } | 1741 } |
| 1713 | 1742 |
| 1714 // The exo display instance. Not owned. | 1743 // The exo display instance. Not owned. |
| 1715 Display* const display_; | 1744 Display* const display_; |
| 1716 | 1745 |
| 1717 // The remote shell resource associated with observer. | 1746 // The remote shell resource associated with observer. |
| 1718 wl_resource* const remote_shell_resource_; | 1747 wl_resource* const remote_shell_resource_; |
| 1719 | 1748 |
| 1720 bool send_configure_after_layout_change_ = false; | 1749 bool needs_send_display_metrics_ = true; |
| 1721 | 1750 |
| 1722 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 1751 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 1723 | 1752 |
| 1724 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; | 1753 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; |
| 1725 | 1754 |
| 1726 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); | 1755 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); |
| 1727 }; | 1756 }; |
| 1728 | 1757 |
| 1729 void remote_shell_destroy(wl_client* client, wl_resource* resource) { | 1758 void remote_shell_destroy(wl_client* client, wl_resource* resource) { |
| 1730 // Nothing to do here. | 1759 // Nothing to do here. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1833 wl_resource_get_version(resource), id); | 1862 wl_resource_get_version(resource), id); |
| 1834 SetImplementation(notification_surface_resource, | 1863 SetImplementation(notification_surface_resource, |
| 1835 ¬ification_surface_implementation, | 1864 ¬ification_surface_implementation, |
| 1836 std::move(notification_surface)); | 1865 std::move(notification_surface)); |
| 1837 } | 1866 } |
| 1838 | 1867 |
| 1839 const struct zcr_remote_shell_v1_interface remote_shell_implementation = { | 1868 const struct zcr_remote_shell_v1_interface remote_shell_implementation = { |
| 1840 remote_shell_destroy, remote_shell_get_remote_surface, | 1869 remote_shell_destroy, remote_shell_get_remote_surface, |
| 1841 remote_shell_get_notification_surface}; | 1870 remote_shell_get_notification_surface}; |
| 1842 | 1871 |
| 1843 const uint32_t remote_shell_version = 1; | 1872 const uint32_t remote_shell_version = 2; |
| 1844 | 1873 |
| 1845 void bind_remote_shell(wl_client* client, | 1874 void bind_remote_shell(wl_client* client, |
| 1846 void* data, | 1875 void* data, |
| 1847 uint32_t version, | 1876 uint32_t version, |
| 1848 uint32_t id) { | 1877 uint32_t id) { |
| 1849 wl_resource* resource = | 1878 wl_resource* resource = |
| 1850 wl_resource_create(client, &zcr_remote_shell_v1_interface, | 1879 wl_resource_create(client, &zcr_remote_shell_v1_interface, |
| 1851 std::min(version, remote_shell_version), id); | 1880 std::min(version, remote_shell_version), id); |
| 1852 | 1881 |
| 1853 SetImplementation(resource, &remote_shell_implementation, | 1882 SetImplementation(resource, &remote_shell_implementation, |
| (...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3072 DCHECK(event_loop); | 3101 DCHECK(event_loop); |
| 3073 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3102 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3074 } | 3103 } |
| 3075 | 3104 |
| 3076 void Server::Flush() { | 3105 void Server::Flush() { |
| 3077 wl_display_flush_clients(wl_display_.get()); | 3106 wl_display_flush_clients(wl_display_.get()); |
| 3078 } | 3107 } |
| 3079 | 3108 |
| 3080 } // namespace wayland | 3109 } // namespace wayland |
| 3081 } // namespace exo | 3110 } // namespace exo |
| OLD | NEW |