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

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

Issue 2189073003: Add configuration_changed event and set_background_opacity request. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated interface comment Created 4 years, 4 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 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 NOTREACHED(); 1035 NOTREACHED();
1036 return WL_OUTPUT_TRANSFORM_NORMAL; 1036 return WL_OUTPUT_TRANSFORM_NORMAL;
1037 } 1037 }
1038 1038
1039 class WaylandDisplayObserver : public display::DisplayObserver { 1039 class WaylandDisplayObserver : public display::DisplayObserver {
1040 public: 1040 public:
1041 WaylandDisplayObserver(const display::Display& display, 1041 WaylandDisplayObserver(const display::Display& display,
1042 wl_resource* output_resource) 1042 wl_resource* output_resource)
1043 : display_id_(display.id()), output_resource_(output_resource) { 1043 : display_id_(display.id()), output_resource_(output_resource) {
1044 display::Screen::GetScreen()->AddObserver(this); 1044 display::Screen::GetScreen()->AddObserver(this);
1045 SendDisplayMetrics(display); 1045 SendDisplayMetricsObsolete(display);
1046 } 1046 }
1047 ~WaylandDisplayObserver() override { 1047 ~WaylandDisplayObserver() override {
1048 display::Screen::GetScreen()->RemoveObserver(this); 1048 display::Screen::GetScreen()->RemoveObserver(this);
1049 } 1049 }
1050 1050
1051 // Overridden from display::DisplayObserver: 1051 // Overridden from display::DisplayObserver:
1052 void OnDisplayAdded(const display::Display& new_display) override {} 1052 void OnDisplayAdded(const display::Display& new_display) override {}
1053 void OnDisplayRemoved(const display::Display& new_display) override {} 1053 void OnDisplayRemoved(const display::Display& new_display) override {}
1054 void OnDisplayMetricsChanged(const display::Display& display, 1054 void OnDisplayMetricsChanged(const display::Display& display,
1055 uint32_t changed_metrics) override { 1055 uint32_t changed_metrics) override {
1056 if (display.id() != display_id_) 1056 if (display.id() != display_id_)
1057 return; 1057 return;
1058 1058
1059 if (changed_metrics & 1059 if (changed_metrics &
1060 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | 1060 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR |
1061 DISPLAY_METRIC_ROTATION)) { 1061 DISPLAY_METRIC_ROTATION)) {
1062 SendDisplayMetrics(display); 1062 SendDisplayMetricsObsolete(display);
1063 } 1063 }
1064 } 1064 }
1065 1065
1066 private: 1066 private:
1067 void SendDisplayMetrics(const display::Display& display) { 1067 void SendDisplayMetricsObsolete(const display::Display& display) {
reveman 2016/07/28 19:52:01 There's nothing obsolete about this code. wl_outpu
oshima 2016/07/28 22:49:47 Done.
1068 const ash::DisplayInfo& info = 1068 const ash::DisplayInfo& info =
1069 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo( 1069 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo(
1070 display.id()); 1070 display.id());
1071 1071
1072 const float kInchInMm = 25.4f; 1072 const float kInchInMm = 25.4f;
1073 const char* kUnknownMake = "unknown"; 1073 const char* kUnknownMake = "unknown";
1074 const char* kUnknownModel = "unknown"; 1074 const char* kUnknownModel = "unknown";
1075 1075
1076 gfx::Rect bounds = info.bounds_in_native(); 1076 gfx::Rect bounds = info.bounds_in_native();
1077 wl_output_send_geometry( 1077 wl_output_send_geometry(
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 1512
1513 void remote_surface_set_system_modal(wl_client* client, wl_resource* resource) { 1513 void remote_surface_set_system_modal(wl_client* client, wl_resource* resource) {
1514 GetUserDataAs<ShellSurface>(resource)->SetSystemModal(true); 1514 GetUserDataAs<ShellSurface>(resource)->SetSystemModal(true);
1515 } 1515 }
1516 1516
1517 void remote_surface_unset_system_modal(wl_client* client, 1517 void remote_surface_unset_system_modal(wl_client* client,
1518 wl_resource* resource) { 1518 wl_resource* resource) {
1519 GetUserDataAs<ShellSurface>(resource)->SetSystemModal(false); 1519 GetUserDataAs<ShellSurface>(resource)->SetSystemModal(false);
1520 } 1520 }
1521 1521
1522 void remote_surface_set_background_opacity(wl_client* client,
1523 wl_resource* resource,
1524 wl_fixed_t opacity) {
1525 GetUserDataAs<ShellSurface>(resource)->SetBackgroundOpacity(
1526 wl_fixed_to_double(opacity));
1527 }
1528
1522 const struct zwp_remote_surface_v1_interface remote_surface_implementation = { 1529 const struct zwp_remote_surface_v1_interface remote_surface_implementation = {
1523 remote_surface_destroy, 1530 remote_surface_destroy,
1524 remote_surface_set_app_id, 1531 remote_surface_set_app_id,
1525 remote_surface_set_window_geometry, 1532 remote_surface_set_window_geometry,
1526 remote_surface_set_scale, 1533 remote_surface_set_scale,
1527 remote_surface_fullscreen, 1534 remote_surface_fullscreen,
1528 remote_surface_maximize, 1535 remote_surface_maximize,
1529 remote_surface_minimize, 1536 remote_surface_minimize,
1530 remote_surface_restore, 1537 remote_surface_restore,
1531 remote_surface_pin, 1538 remote_surface_pin,
1532 remote_surface_unpin, 1539 remote_surface_unpin,
1533 remote_surface_unfullscreen, 1540 remote_surface_unfullscreen,
1534 remote_surface_set_rectangular_shadow, 1541 remote_surface_set_rectangular_shadow,
1535 remote_surface_set_title, 1542 remote_surface_set_title,
1536 remote_surface_set_top_inset, 1543 remote_surface_set_top_inset,
1537 remote_surface_set_system_modal, 1544 remote_surface_set_system_modal,
1538 remote_surface_unset_system_modal}; 1545 remote_surface_unset_system_modal,
1546 remote_surface_set_background_opacity};
1539 1547
1540 //////////////////////////////////////////////////////////////////////////////// 1548 ////////////////////////////////////////////////////////////////////////////////
1541 // notification_surface_interface: 1549 // notification_surface_interface:
1542 1550
1543 void notification_surface_destroy(wl_client* client, wl_resource* resource) { 1551 void notification_surface_destroy(wl_client* client, wl_resource* resource) {
1544 wl_resource_destroy(resource); 1552 wl_resource_destroy(resource);
1545 } 1553 }
1546 1554
1547 const struct zwp_notification_surface_v1_interface 1555 const struct zwp_notification_surface_v1_interface
1548 notification_surface_implementation = {notification_surface_destroy}; 1556 notification_surface_implementation = {notification_surface_destroy};
(...skipping 11 matching lines...) Expand all
1560 int64_t display_id, 1568 int64_t display_id,
1561 wl_resource* remote_shell_resource) 1569 wl_resource* remote_shell_resource)
1562 : display_(display), 1570 : display_(display),
1563 display_id_(display_id), 1571 display_id_(display_id),
1564 remote_shell_resource_(remote_shell_resource), 1572 remote_shell_resource_(remote_shell_resource),
1565 weak_ptr_factory_(this) { 1573 weak_ptr_factory_(this) {
1566 ash::WmShell::Get()->AddShellObserver(this); 1574 ash::WmShell::Get()->AddShellObserver(this);
1567 ash::Shell* shell = ash::Shell::GetInstance(); 1575 ash::Shell* shell = ash::Shell::GetInstance();
1568 shell->activation_client()->AddObserver(this); 1576 shell->activation_client()->AddObserver(this);
1569 display::Screen::GetScreen()->AddObserver(this); 1577 display::Screen::GetScreen()->AddObserver(this);
1570 SendConfigure(); 1578 SendConfigureObsolete();
1579 SendPrimaryDisplayMetrics();
1580
1571 SendActivated(shell->activation_client()->GetActiveWindow(), nullptr); 1581 SendActivated(shell->activation_client()->GetActiveWindow(), nullptr);
1572 } 1582 }
1573 ~WaylandRemoteShell() override { 1583 ~WaylandRemoteShell() override {
1574 ash::WmShell::Get()->RemoveShellObserver(this); 1584 ash::WmShell::Get()->RemoveShellObserver(this);
1575 ash::Shell::GetInstance()->activation_client()->RemoveObserver(this); 1585 ash::Shell::GetInstance()->activation_client()->RemoveObserver(this);
1576 display::Screen::GetScreen()->RemoveObserver(this); 1586 display::Screen::GetScreen()->RemoveObserver(this);
1577 } 1587 }
1578 1588
1579 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, 1589 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface,
1580 int container) { 1590 int container) {
1581 return display_->CreateRemoteShellSurface(surface, container); 1591 return display_->CreateRemoteShellSurface(surface, container);
1582 } 1592 }
1583 1593
1584 std::unique_ptr<NotificationSurface> CreateNotificationSurface( 1594 std::unique_ptr<NotificationSurface> CreateNotificationSurface(
1585 Surface* surface, 1595 Surface* surface,
1586 const std::string& notification_id) { 1596 const std::string& notification_id) {
1587 return display_->CreateNotificationSurface(surface, notification_id); 1597 return display_->CreateNotificationSurface(surface, notification_id);
1588 } 1598 }
1589 1599
1590 // Overridden from display::DisplayObserver: 1600 // Overridden from display::DisplayObserver:
1591 void OnDisplayAdded(const display::Display& new_display) override {} 1601 void OnDisplayAdded(const display::Display& new_display) override {}
1592 void OnDisplayRemoved(const display::Display& new_display) override {} 1602 void OnDisplayRemoved(const display::Display& new_display) override {}
1593 void OnDisplayMetricsChanged(const display::Display& display, 1603 void OnDisplayMetricsChanged(const display::Display& display,
1594 uint32_t metrics) override { 1604 uint32_t changed_metrics) override {
1605 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() ==
1606 display.id() &&
1607 (changed_metrics &
1608 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR |
1609 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA))) {
1610 SendPrimaryDisplayMetrics();
1611 }
1612
1595 if (display.id() == display_id_) 1613 if (display.id() == display_id_)
1596 SendConfigure(); 1614 SendConfigureObsolete();
1597 } 1615 }
1598 1616
1599 // Overridden from ash::ShellObserver: 1617 // Overridden from ash::ShellObserver:
1600 void OnDisplayWorkAreaInsetsChanged() override { SendConfigure(); } 1618 void OnDisplayWorkAreaInsetsChanged() override { SendConfigureObsolete(); }
1601 void OnMaximizeModeStarted() override { 1619 void OnMaximizeModeStarted() override {
1602 SendLayoutModeChange(ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET); 1620 SendLayoutModeChange(ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET);
1621 layout_mode_ = ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET;
1622
1603 send_configure_after_layout_change_ = true; 1623 send_configure_after_layout_change_ = true;
1604 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1624 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1605 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure, 1625 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure,
1606 weak_ptr_factory_.GetWeakPtr()), 1626 weak_ptr_factory_.GetWeakPtr()),
1607 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs)); 1627 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs));
1608 } 1628 }
1609 void OnMaximizeModeEnded() override { 1629 void OnMaximizeModeEnded() override {
1610 SendLayoutModeChange(ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED); 1630 SendLayoutModeChange(ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED);
1631 layout_mode_ = ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED;
1611 send_configure_after_layout_change_ = true; 1632 send_configure_after_layout_change_ = true;
1612 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1633 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1613 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure, 1634 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure,
1614 weak_ptr_factory_.GetWeakPtr()), 1635 weak_ptr_factory_.GetWeakPtr()),
1615 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs)); 1636 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs));
1616 } 1637 }
1617 1638
1618 // Overridden from aura::client::ActivationChangeObserver: 1639 // Overridden from aura::client::ActivationChangeObserver:
1619 void OnWindowActivated( 1640 void OnWindowActivated(
1620 aura::client::ActivationChangeObserver::ActivationReason reason, 1641 aura::client::ActivationChangeObserver::ActivationReason reason,
1621 aura::Window* gained_active, 1642 aura::Window* gained_active,
1622 aura::Window* lost_active) override { 1643 aura::Window* lost_active) override {
1623 SendActivated(gained_active, lost_active); 1644 SendActivated(gained_active, lost_active);
1624 } 1645 }
1625 1646
1626 private: 1647 private:
1627 void MaybeSendConfigure() { 1648 void MaybeSendConfigure() {
1628 if (send_configure_after_layout_change_) 1649 if (send_configure_after_layout_change_) {
1629 SendConfigure(); 1650 SendPrimaryDisplayMetrics();
1651 SendConfigureObsolete();
1652 }
1630 } 1653 }
1631 1654
1632 void SendConfigure() { 1655 void SendPrimaryDisplayMetrics() {
1656 const float kInchInMm = 25.4f;
1657
1658 if (wl_resource_get_version(remote_shell_resource_) < 9)
1659 return;
1660
1633 send_configure_after_layout_change_ = false; 1661 send_configure_after_layout_change_ = false;
1634 const display::Display& display = 1662 const display::Display& display =
1663 display::Screen::GetScreen()->GetPrimaryDisplay();
1664 const ash::DisplayInfo& info =
1665 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo(
1666 display.id());
1667
1668 gfx::Insets work_area_insets = display.GetWorkAreaInsets();
1669 gfx::Rect native_bounds = info.bounds_in_native();
1670
1671 int refresh_rate = 60000;
1672 zwp_remote_shell_v1_send_display_changed(
1673 remote_shell_resource_, native_bounds.x(), native_bounds.y(),
1674 static_cast<int>(kInchInMm * native_bounds.width() / info.device_dpi()),
1675 static_cast<int>(kInchInMm * native_bounds.height() /
1676 info.device_dpi()),
1677 WL_OUTPUT_SUBPIXEL_UNKNOWN, OutputTransform(display.rotation()),
1678 native_bounds.width(), native_bounds.height(), refresh_rate,
1679 wl_fixed_from_double(display.device_scale_factor()),
1680 display.size().width(), display.size().height(),
1681 work_area_insets.left(), work_area_insets.top(),
1682 work_area_insets.right(), work_area_insets.bottom(), layout_mode_);
1683
1684 wl_client_flush(wl_resource_get_client(remote_shell_resource_));
1685 }
1686
1687 void SendConfigureObsolete() {
reveman 2016/07/28 19:52:01 Maybe SendConfigure_DEPRECATED to make it even mor
oshima 2016/07/28 22:49:47 Done.
1688 send_configure_after_layout_change_ = false;
1689
1690 if (wl_resource_get_version(remote_shell_resource_) >= 9)
1691 return;
1692
1693 const display::Display& display =
1635 ash::Shell::GetInstance()->display_manager()->GetDisplayForId( 1694 ash::Shell::GetInstance()->display_manager()->GetDisplayForId(
1636 display_id_); 1695 display_id_);
1637 gfx::Insets work_area_insets = display.GetWorkAreaInsets(); 1696 gfx::Insets work_area_insets = display.GetWorkAreaInsets();
1638 zwp_remote_shell_v1_send_configure( 1697 zwp_remote_shell_v1_send_configure(
1639 remote_shell_resource_, display.size().width(), display.size().height(), 1698 remote_shell_resource_, display.size().width(), display.size().height(),
1640 work_area_insets.left(), work_area_insets.top(), 1699 work_area_insets.left(), work_area_insets.top(),
1641 work_area_insets.right(), work_area_insets.bottom()); 1700 work_area_insets.right(), work_area_insets.bottom());
1642 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); 1701 wl_client_flush(wl_resource_get_client(remote_shell_resource_));
1643 } 1702 }
1644 1703
1645 void SendLayoutModeChange(uint32_t mode) { 1704 void SendLayoutModeChange(uint32_t mode) {
reveman 2016/07/28 19:52:01 is this not deprecated too?
oshima 2016/07/28 22:49:47 Done.
1646 if (wl_resource_get_version(remote_shell_resource_) < 8) 1705 if (wl_resource_get_version(remote_shell_resource_) < 8)
1647 return; 1706 return;
1648 zwp_remote_shell_v1_send_layout_mode_changed(remote_shell_resource_, mode); 1707 zwp_remote_shell_v1_send_layout_mode_changed(remote_shell_resource_, mode);
1649 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); 1708 wl_client_flush(wl_resource_get_client(remote_shell_resource_));
1650 } 1709 }
1651 1710
1652 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { 1711 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) {
1653 Surface* gained_active_surface = 1712 Surface* gained_active_surface =
1654 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; 1713 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr;
1655 Surface* lost_active_surface = 1714 Surface* lost_active_surface =
(...skipping 30 matching lines...) Expand all
1686 Display* const display_; 1745 Display* const display_;
1687 1746
1688 // The identifier associated with the observed display. 1747 // The identifier associated with the observed display.
1689 const int64_t display_id_; 1748 const int64_t display_id_;
1690 1749
1691 // The remote shell resource associated with observer. 1750 // The remote shell resource associated with observer.
1692 wl_resource* const remote_shell_resource_; 1751 wl_resource* const remote_shell_resource_;
1693 1752
1694 bool send_configure_after_layout_change_ = false; 1753 bool send_configure_after_layout_change_ = false;
1695 1754
1755 int layout_mode_ = ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED;
1756
1696 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; 1757 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_;
1697 1758
1698 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); 1759 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell);
1699 }; 1760 };
1700 1761
1701 void remote_shell_destroy(wl_client* client, wl_resource* resource) { 1762 void remote_shell_destroy(wl_client* client, wl_resource* resource) {
1702 // Nothing to do here. 1763 // Nothing to do here.
1703 } 1764 }
1704 1765
1705 int RemoteSurfaceContainer(uint32_t container) { 1766 int RemoteSurfaceContainer(uint32_t container) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1831 wl_resource_get_version(resource), id); 1892 wl_resource_get_version(resource), id);
1832 SetImplementation(notification_surface_resource, 1893 SetImplementation(notification_surface_resource,
1833 &notification_surface_implementation, 1894 &notification_surface_implementation,
1834 std::move(notification_surface)); 1895 std::move(notification_surface));
1835 } 1896 }
1836 1897
1837 const struct zwp_remote_shell_v1_interface remote_shell_implementation = { 1898 const struct zwp_remote_shell_v1_interface remote_shell_implementation = {
1838 remote_shell_destroy, remote_shell_get_remote_surface, 1899 remote_shell_destroy, remote_shell_get_remote_surface,
1839 remote_shell_get_notification_surface}; 1900 remote_shell_get_notification_surface};
1840 1901
1841 const uint32_t remote_shell_version = 8; 1902 const uint32_t remote_shell_version = 9;
1842 1903
1843 void bind_remote_shell(wl_client* client, 1904 void bind_remote_shell(wl_client* client,
1844 void* data, 1905 void* data,
1845 uint32_t version, 1906 uint32_t version,
1846 uint32_t id) { 1907 uint32_t id) {
1847 wl_resource* resource = 1908 wl_resource* resource =
1848 wl_resource_create(client, &zwp_remote_shell_v1_interface, 1909 wl_resource_create(client, &zwp_remote_shell_v1_interface,
1849 std::min(version, remote_shell_version), id); 1910 std::min(version, remote_shell_version), id);
1850 1911
1851 // TODO(reveman): Multi-display support. 1912 // TODO(reveman): Multi-display support.
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2996 DCHECK(event_loop); 3057 DCHECK(event_loop);
2997 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 3058 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
2998 } 3059 }
2999 3060
3000 void Server::Flush() { 3061 void Server::Flush() {
3001 wl_display_flush_clients(wl_display_.get()); 3062 wl_display_flush_clients(wl_display_.get());
3002 } 3063 }
3003 3064
3004 } // namespace wayland 3065 } // namespace wayland
3005 } // namespace exo 3066 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698