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

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

Issue 2112013002: Allow arc app to lock screen orientation in TouchView/Tablet mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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 <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
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
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 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 // for the remote shell interface. 1547 // for the remote shell interface.
1542 class WaylandRemoteShell : public ash::ShellObserver, 1548 class WaylandRemoteShell : public ash::ShellObserver,
1543 public aura::client::ActivationChangeObserver, 1549 public aura::client::ActivationChangeObserver,
1544 public display::DisplayObserver { 1550 public display::DisplayObserver {
1545 public: 1551 public:
1546 WaylandRemoteShell(Display* display, 1552 WaylandRemoteShell(Display* display,
1547 int64_t display_id, 1553 int64_t display_id,
1548 wl_resource* remote_shell_resource) 1554 wl_resource* remote_shell_resource)
1549 : display_(display), 1555 : display_(display),
1550 display_id_(display_id), 1556 display_id_(display_id),
1551 remote_shell_resource_(remote_shell_resource) { 1557 remote_shell_resource_(remote_shell_resource),
1558 weak_ptr_factory_(this) {
1552 ash::WmShell::Get()->AddShellObserver(this); 1559 ash::WmShell::Get()->AddShellObserver(this);
1553 ash::Shell* shell = ash::Shell::GetInstance(); 1560 ash::Shell* shell = ash::Shell::GetInstance();
1554 shell->activation_client()->AddObserver(this); 1561 shell->activation_client()->AddObserver(this);
1555 display::Screen::GetScreen()->AddObserver(this); 1562 display::Screen::GetScreen()->AddObserver(this);
1556 SendConfigure(); 1563 SendConfigure();
1557 SendActivated(shell->activation_client()->GetActiveWindow(), nullptr); 1564 SendActivated(shell->activation_client()->GetActiveWindow(), nullptr);
1558 } 1565 }
1559 ~WaylandRemoteShell() override { 1566 ~WaylandRemoteShell() override {
1560 ash::WmShell::Get()->RemoveShellObserver(this); 1567 ash::WmShell::Get()->RemoveShellObserver(this);
1561 ash::Shell::GetInstance()->activation_client()->RemoveObserver(this); 1568 ash::Shell::GetInstance()->activation_client()->RemoveObserver(this);
(...skipping 17 matching lines...) Expand all
1579 void OnDisplayMetricsChanged(const display::Display& display, 1586 void OnDisplayMetricsChanged(const display::Display& display,
1580 uint32_t metrics) override { 1587 uint32_t metrics) override {
1581 if (display.id() == display_id_) 1588 if (display.id() == display_id_)
1582 SendConfigure(); 1589 SendConfigure();
1583 } 1590 }
1584 1591
1585 // Overridden from ash::ShellObserver: 1592 // Overridden from ash::ShellObserver:
1586 void OnDisplayWorkAreaInsetsChanged() override { SendConfigure(); } 1593 void OnDisplayWorkAreaInsetsChanged() override { SendConfigure(); }
1587 void OnMaximizeModeStarted() override { 1594 void OnMaximizeModeStarted() override {
1588 SendLayoutModeChange(ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET); 1595 SendLayoutModeChange(ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET);
1596 send_configure_after_layout_change_ = true;
1597 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1598 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure,
1599 weak_ptr_factory_.GetWeakPtr()),
1600 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs));
1589 } 1601 }
1590 void OnMaximizeModeEnded() override { 1602 void OnMaximizeModeEnded() override {
1591 SendLayoutModeChange(ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED); 1603 SendLayoutModeChange(ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED);
1604 send_configure_after_layout_change_ = true;
1605 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1606 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure,
1607 weak_ptr_factory_.GetWeakPtr()),
1608 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs));
1592 } 1609 }
1593 1610
1594 // Overridden from aura::client::ActivationChangeObserver: 1611 // Overridden from aura::client::ActivationChangeObserver:
1595 void OnWindowActivated( 1612 void OnWindowActivated(
1596 aura::client::ActivationChangeObserver::ActivationReason reason, 1613 aura::client::ActivationChangeObserver::ActivationReason reason,
1597 aura::Window* gained_active, 1614 aura::Window* gained_active,
1598 aura::Window* lost_active) override { 1615 aura::Window* lost_active) override {
1599 SendActivated(gained_active, lost_active); 1616 SendActivated(gained_active, lost_active);
1600 } 1617 }
1601 1618
1602 private: 1619 private:
1620 void MaybeSendConfigure() {
1621 if (send_configure_after_layout_change_)
1622 SendConfigure();
1623 }
1624
1603 void SendConfigure() { 1625 void SendConfigure() {
1626 send_configure_after_layout_change_ = false;
1604 const display::Display& display = 1627 const display::Display& display =
1605 ash::Shell::GetInstance()->display_manager()->GetDisplayForId( 1628 ash::Shell::GetInstance()->display_manager()->GetDisplayForId(
1606 display_id_); 1629 display_id_);
1607 gfx::Insets work_area_insets = display.GetWorkAreaInsets(); 1630 gfx::Insets work_area_insets = display.GetWorkAreaInsets();
1608 zwp_remote_shell_v1_send_configure( 1631 zwp_remote_shell_v1_send_configure(
1609 remote_shell_resource_, display.size().width(), display.size().height(), 1632 remote_shell_resource_, display.size().width(), display.size().height(),
1610 work_area_insets.left(), work_area_insets.top(), 1633 work_area_insets.left(), work_area_insets.top(),
1611 work_area_insets.right(), work_area_insets.bottom()); 1634 work_area_insets.right(), work_area_insets.bottom());
1612 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); 1635 wl_client_flush(wl_resource_get_client(remote_shell_resource_));
1613 } 1636 }
1614 1637
1615 void SendLayoutModeChange(int mode) { 1638 void SendLayoutModeChange(uint32_t mode) {
1616 if (wl_resource_get_version(remote_shell_resource_) < 8) 1639 if (wl_resource_get_version(remote_shell_resource_) < 8)
1617 return; 1640 return;
1618 zwp_remote_shell_v1_send_layout_mode_changed(remote_shell_resource_, mode); 1641 zwp_remote_shell_v1_send_layout_mode_changed(remote_shell_resource_, mode);
1619 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); 1642 wl_client_flush(wl_resource_get_client(remote_shell_resource_));
1620 } 1643 }
1621 1644
1622 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { 1645 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) {
1623 Surface* gained_active_surface = 1646 Surface* gained_active_surface =
1624 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; 1647 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr;
1625 Surface* lost_active_surface = 1648 Surface* lost_active_surface =
(...skipping 28 matching lines...) Expand all
1654 1677
1655 // The exo display instance. Not owned. 1678 // The exo display instance. Not owned.
1656 Display* const display_; 1679 Display* const display_;
1657 1680
1658 // The identifier associated with the observed display. 1681 // The identifier associated with the observed display.
1659 const int64_t display_id_; 1682 const int64_t display_id_;
1660 1683
1661 // The remote shell resource associated with observer. 1684 // The remote shell resource associated with observer.
1662 wl_resource* const remote_shell_resource_; 1685 wl_resource* const remote_shell_resource_;
1663 1686
1687 bool send_configure_after_layout_change_ = false;
1688
1689 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_;
1690
1664 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); 1691 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell);
1665 }; 1692 };
1666 1693
1667 void remote_shell_destroy(wl_client* client, wl_resource* resource) { 1694 void remote_shell_destroy(wl_client* client, wl_resource* resource) {
1668 // Nothing to do here. 1695 // Nothing to do here.
1669 } 1696 }
1670 1697
1671 int RemoteSurfaceContainer(uint32_t container) { 1698 int RemoteSurfaceContainer(uint32_t container) {
1672 switch (container) { 1699 switch (container) {
1673 case ZWP_REMOTE_SHELL_V1_CONTAINER_DEFAULT: 1700 case ZWP_REMOTE_SHELL_V1_CONTAINER_DEFAULT:
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2870 DCHECK(event_loop); 2897 DCHECK(event_loop);
2871 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 2898 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
2872 } 2899 }
2873 2900
2874 void Server::Flush() { 2901 void Server::Flush() {
2875 wl_display_flush_clients(wl_display_.get()); 2902 wl_display_flush_clients(wl_display_.get());
2876 } 2903 }
2877 2904
2878 } // namespace wayland 2905 } // namespace wayland
2879 } // namespace exo 2906 } // namespace exo
OLDNEW
« components/arc/common/app.mojom ('K') | « components/arc/common/app.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698