| 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 19 matching lines...) Expand all Loading... |
| 30 #include "ash/common/shell_window_ids.h" | 30 #include "ash/common/shell_window_ids.h" |
| 31 #include "ash/common/wm_shell.h" | 31 #include "ash/common/wm_shell.h" |
| 32 #include "ash/display/display_manager.h" | 32 #include "ash/display/display_manager.h" |
| 33 #include "ash/shell.h" | 33 #include "ash/shell.h" |
| 34 #include "base/bind.h" | 34 #include "base/bind.h" |
| 35 #include "base/cancelable_callback.h" | 35 #include "base/cancelable_callback.h" |
| 36 #include "base/files/file_path.h" | 36 #include "base/files/file_path.h" |
| 37 #include "base/macros.h" | 37 #include "base/macros.h" |
| 38 #include "base/memory/free_deleter.h" | 38 #include "base/memory/free_deleter.h" |
| 39 #include "base/memory/ptr_util.h" | 39 #include "base/memory/ptr_util.h" |
| 40 #include "base/memory/weak_ptr.h" |
| 40 #include "base/strings/stringprintf.h" | 41 #include "base/strings/stringprintf.h" |
| 41 #include "base/strings/utf_string_conversions.h" | 42 #include "base/strings/utf_string_conversions.h" |
| 43 #include "base/threading/thread_task_runner_handle.h" |
| 42 #include "components/exo/buffer.h" | 44 #include "components/exo/buffer.h" |
| 43 #include "components/exo/display.h" | 45 #include "components/exo/display.h" |
| 44 #include "components/exo/keyboard.h" | 46 #include "components/exo/keyboard.h" |
| 45 #include "components/exo/keyboard_delegate.h" | 47 #include "components/exo/keyboard_delegate.h" |
| 46 #include "components/exo/notification_surface.h" | 48 #include "components/exo/notification_surface.h" |
| 47 #include "components/exo/notification_surface_manager.h" | 49 #include "components/exo/notification_surface_manager.h" |
| 48 #include "components/exo/pointer.h" | 50 #include "components/exo/pointer.h" |
| 49 #include "components/exo/pointer_delegate.h" | 51 #include "components/exo/pointer_delegate.h" |
| 50 #include "components/exo/shared_memory.h" | 52 #include "components/exo/shared_memory.h" |
| 51 #include "components/exo/shell_surface.h" | 53 #include "components/exo/shell_surface.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 80 #include "ui/events/keycodes/scoped_xkb.h" // nogncheck | 82 #include "ui/events/keycodes/scoped_xkb.h" // nogncheck |
| 81 #endif | 83 #endif |
| 82 | 84 |
| 83 DECLARE_SURFACE_PROPERTY_TYPE(wl_resource*); | 85 DECLARE_SURFACE_PROPERTY_TYPE(wl_resource*); |
| 84 DECLARE_SURFACE_PROPERTY_TYPE(bool); | 86 DECLARE_SURFACE_PROPERTY_TYPE(bool); |
| 85 | 87 |
| 86 namespace exo { | 88 namespace exo { |
| 87 namespace wayland { | 89 namespace wayland { |
| 88 namespace { | 90 namespace { |
| 89 | 91 |
| 92 // We don't send configure immediately after tablet mode switch |
| 93 // because layout can change due to orientation lock state or accelerometer. |
| 94 const int kConfigureDelayAfterLayoutSwitchMs = 300; |
| 95 |
| 90 // Default wayland socket name. | 96 // Default wayland socket name. |
| 91 const base::FilePath::CharType kSocketName[] = FILE_PATH_LITERAL("wayland-0"); | 97 const base::FilePath::CharType kSocketName[] = FILE_PATH_LITERAL("wayland-0"); |
| 92 | 98 |
| 93 // Group used for wayland socket. | 99 // Group used for wayland socket. |
| 94 const char kWaylandSocketGroup[] = "wayland"; | 100 const char kWaylandSocketGroup[] = "wayland"; |
| 95 | 101 |
| 96 template <class T> | 102 template <class T> |
| 97 T* GetUserDataAs(wl_resource* resource) { | 103 T* GetUserDataAs(wl_resource* resource) { |
| 98 return static_cast<T*>(wl_resource_get_user_data(resource)); | 104 return static_cast<T*>(wl_resource_get_user_data(resource)); |
| 99 } | 105 } |
| (...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 // for the remote shell interface. | 1546 // for the remote shell interface. |
| 1541 class WaylandRemoteShell : public ash::ShellObserver, | 1547 class WaylandRemoteShell : public ash::ShellObserver, |
| 1542 public aura::client::ActivationChangeObserver, | 1548 public aura::client::ActivationChangeObserver, |
| 1543 public display::DisplayObserver { | 1549 public display::DisplayObserver { |
| 1544 public: | 1550 public: |
| 1545 WaylandRemoteShell(Display* display, | 1551 WaylandRemoteShell(Display* display, |
| 1546 int64_t display_id, | 1552 int64_t display_id, |
| 1547 wl_resource* remote_shell_resource) | 1553 wl_resource* remote_shell_resource) |
| 1548 : display_(display), | 1554 : display_(display), |
| 1549 display_id_(display_id), | 1555 display_id_(display_id), |
| 1550 remote_shell_resource_(remote_shell_resource) { | 1556 remote_shell_resource_(remote_shell_resource), |
| 1557 weak_ptr_factory_(this) { |
| 1551 ash::WmShell::Get()->AddShellObserver(this); | 1558 ash::WmShell::Get()->AddShellObserver(this); |
| 1552 ash::Shell* shell = ash::Shell::GetInstance(); | 1559 ash::Shell* shell = ash::Shell::GetInstance(); |
| 1553 shell->activation_client()->AddObserver(this); | 1560 shell->activation_client()->AddObserver(this); |
| 1554 display::Screen::GetScreen()->AddObserver(this); | 1561 display::Screen::GetScreen()->AddObserver(this); |
| 1555 SendConfigure(); | 1562 SendConfigure(); |
| 1556 SendActivated(shell->activation_client()->GetActiveWindow(), nullptr); | 1563 SendActivated(shell->activation_client()->GetActiveWindow(), nullptr); |
| 1557 } | 1564 } |
| 1558 ~WaylandRemoteShell() override { | 1565 ~WaylandRemoteShell() override { |
| 1559 ash::WmShell::Get()->RemoveShellObserver(this); | 1566 ash::WmShell::Get()->RemoveShellObserver(this); |
| 1560 ash::Shell::GetInstance()->activation_client()->RemoveObserver(this); | 1567 ash::Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1578 void OnDisplayMetricsChanged(const display::Display& display, | 1585 void OnDisplayMetricsChanged(const display::Display& display, |
| 1579 uint32_t metrics) override { | 1586 uint32_t metrics) override { |
| 1580 if (display.id() == display_id_) | 1587 if (display.id() == display_id_) |
| 1581 SendConfigure(); | 1588 SendConfigure(); |
| 1582 } | 1589 } |
| 1583 | 1590 |
| 1584 // Overridden from ash::ShellObserver: | 1591 // Overridden from ash::ShellObserver: |
| 1585 void OnDisplayWorkAreaInsetsChanged() override { SendConfigure(); } | 1592 void OnDisplayWorkAreaInsetsChanged() override { SendConfigure(); } |
| 1586 void OnMaximizeModeStarted() override { | 1593 void OnMaximizeModeStarted() override { |
| 1587 SendLayoutModeChange(ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET); | 1594 SendLayoutModeChange(ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET); |
| 1595 send_configure_after_layout_change_ = true; |
| 1596 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1597 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure, |
| 1598 weak_ptr_factory_.GetWeakPtr()), |
| 1599 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs)); |
| 1588 } | 1600 } |
| 1589 void OnMaximizeModeEnded() override { | 1601 void OnMaximizeModeEnded() override { |
| 1590 SendLayoutModeChange(ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED); | 1602 SendLayoutModeChange(ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED); |
| 1603 send_configure_after_layout_change_ = true; |
| 1604 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1605 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure, |
| 1606 weak_ptr_factory_.GetWeakPtr()), |
| 1607 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs)); |
| 1591 } | 1608 } |
| 1592 | 1609 |
| 1593 // Overridden from aura::client::ActivationChangeObserver: | 1610 // Overridden from aura::client::ActivationChangeObserver: |
| 1594 void OnWindowActivated( | 1611 void OnWindowActivated( |
| 1595 aura::client::ActivationChangeObserver::ActivationReason reason, | 1612 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 1596 aura::Window* gained_active, | 1613 aura::Window* gained_active, |
| 1597 aura::Window* lost_active) override { | 1614 aura::Window* lost_active) override { |
| 1598 SendActivated(gained_active, lost_active); | 1615 SendActivated(gained_active, lost_active); |
| 1599 } | 1616 } |
| 1600 | 1617 |
| 1601 private: | 1618 private: |
| 1619 void MaybeSendConfigure() { |
| 1620 if (send_configure_after_layout_change_) |
| 1621 SendConfigure(); |
| 1622 } |
| 1623 |
| 1602 void SendConfigure() { | 1624 void SendConfigure() { |
| 1625 send_configure_after_layout_change_ = false; |
| 1603 const display::Display& display = | 1626 const display::Display& display = |
| 1604 ash::Shell::GetInstance()->display_manager()->GetDisplayForId( | 1627 ash::Shell::GetInstance()->display_manager()->GetDisplayForId( |
| 1605 display_id_); | 1628 display_id_); |
| 1606 gfx::Insets work_area_insets = display.GetWorkAreaInsets(); | 1629 gfx::Insets work_area_insets = display.GetWorkAreaInsets(); |
| 1607 zwp_remote_shell_v1_send_configure( | 1630 zwp_remote_shell_v1_send_configure( |
| 1608 remote_shell_resource_, display.size().width(), display.size().height(), | 1631 remote_shell_resource_, display.size().width(), display.size().height(), |
| 1609 work_area_insets.left(), work_area_insets.top(), | 1632 work_area_insets.left(), work_area_insets.top(), |
| 1610 work_area_insets.right(), work_area_insets.bottom()); | 1633 work_area_insets.right(), work_area_insets.bottom()); |
| 1611 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); | 1634 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); |
| 1612 } | 1635 } |
| 1613 | 1636 |
| 1614 void SendLayoutModeChange(int mode) { | 1637 void SendLayoutModeChange(uint32_t mode) { |
| 1615 if (wl_resource_get_version(remote_shell_resource_) < 8) | 1638 if (wl_resource_get_version(remote_shell_resource_) < 8) |
| 1616 return; | 1639 return; |
| 1617 zwp_remote_shell_v1_send_layout_mode_changed(remote_shell_resource_, mode); | 1640 zwp_remote_shell_v1_send_layout_mode_changed(remote_shell_resource_, mode); |
| 1618 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); | 1641 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); |
| 1619 } | 1642 } |
| 1620 | 1643 |
| 1621 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { | 1644 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { |
| 1622 Surface* gained_active_surface = | 1645 Surface* gained_active_surface = |
| 1623 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; | 1646 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; |
| 1624 Surface* lost_active_surface = | 1647 Surface* lost_active_surface = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1653 | 1676 |
| 1654 // The exo display instance. Not owned. | 1677 // The exo display instance. Not owned. |
| 1655 Display* const display_; | 1678 Display* const display_; |
| 1656 | 1679 |
| 1657 // The identifier associated with the observed display. | 1680 // The identifier associated with the observed display. |
| 1658 const int64_t display_id_; | 1681 const int64_t display_id_; |
| 1659 | 1682 |
| 1660 // The remote shell resource associated with observer. | 1683 // The remote shell resource associated with observer. |
| 1661 wl_resource* const remote_shell_resource_; | 1684 wl_resource* const remote_shell_resource_; |
| 1662 | 1685 |
| 1686 bool send_configure_after_layout_change_ = false; |
| 1687 |
| 1688 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; |
| 1689 |
| 1663 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); | 1690 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); |
| 1664 }; | 1691 }; |
| 1665 | 1692 |
| 1666 void remote_shell_destroy(wl_client* client, wl_resource* resource) { | 1693 void remote_shell_destroy(wl_client* client, wl_resource* resource) { |
| 1667 // Nothing to do here. | 1694 // Nothing to do here. |
| 1668 } | 1695 } |
| 1669 | 1696 |
| 1670 int RemoteSurfaceContainer(uint32_t container) { | 1697 int RemoteSurfaceContainer(uint32_t container) { |
| 1671 switch (container) { | 1698 switch (container) { |
| 1672 case ZWP_REMOTE_SHELL_V1_CONTAINER_DEFAULT: | 1699 case ZWP_REMOTE_SHELL_V1_CONTAINER_DEFAULT: |
| (...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2869 DCHECK(event_loop); | 2896 DCHECK(event_loop); |
| 2870 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 2897 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 2871 } | 2898 } |
| 2872 | 2899 |
| 2873 void Server::Flush() { | 2900 void Server::Flush() { |
| 2874 wl_display_flush_clients(wl_display_.get()); | 2901 wl_display_flush_clients(wl_display_.get()); |
| 2875 } | 2902 } |
| 2876 | 2903 |
| 2877 } // namespace wayland | 2904 } // namespace wayland |
| 2878 } // namespace exo | 2905 } // namespace exo |
| OLD | NEW |