Commit df43be02 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

[ozone/wayland] Hook zaura_shell 'layout_mode' event

This CL hooks ozone/wayland with the newly added 'layout_mode'
event, from zaura_shell EXO extension.

It also introduces a new path to set the global tablet state:
display::DisplayObserver.

Next, ash/wm/tablet_mode/tablet_more_controller.cc|h will switch
over to it, and rest chromeos::TabletState.

BUG=1113900

R=jamescook@chromium.org, rjkroege@chromium.org

Change-Id: Iae832c4247c04c47429255721ff69c3ba0762455
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2491517Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#823948}
parent 4f213c25
......@@ -5,6 +5,7 @@
#include "chromeos/ui/base/tablet_state.h"
#include "base/check_op.h"
#include "ui/display/screen.h"
namespace chromeos {
......@@ -19,11 +20,13 @@ TabletState* TabletState::Get() {
TabletState::TabletState() {
DCHECK_EQ(nullptr, g_instance);
g_instance = this;
display::Screen::GetScreen()->AddObserver(this);
}
TabletState::~TabletState() {
DCHECK_EQ(this, g_instance);
g_instance = nullptr;
display::Screen::GetScreen()->RemoveObserver(this);
}
void TabletState::AddObserver(Observer* observer) {
......@@ -46,4 +49,8 @@ void TabletState::SetState(display::TabletState state) {
observer.OnTabletStateChanged(state_);
}
void TabletState::OnDisplayTabletStateChanged(display::TabletState state) {
SetState(state);
}
} // namespace chromeos
......@@ -7,6 +7,7 @@
#include "base/component_export.h"
#include "base/observer_list.h"
#include "ui/display/display_observer.h"
#include "ui/display/tablet_state.h"
namespace ash {
......@@ -19,7 +20,8 @@ namespace chromeos {
//
// The idea is that only the creator of this class in Ash or Lacros/Ozone code
// is able to set the state.
class COMPONENT_EXPORT(CHROMEOS_UI_BASE) TabletState {
class COMPONENT_EXPORT(CHROMEOS_UI_BASE) TabletState
: public display::DisplayObserver {
public:
// Returns the singleton instance.
static TabletState* Get();
......@@ -35,7 +37,7 @@ class COMPONENT_EXPORT(CHROMEOS_UI_BASE) TabletState {
TabletState();
TabletState(const TabletState&) = delete;
TabletState& operator=(const TabletState&) = delete;
~TabletState();
~TabletState() override;
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
......@@ -45,6 +47,9 @@ class COMPONENT_EXPORT(CHROMEOS_UI_BASE) TabletState {
display::TabletState state() const { return state_; }
// display::DisplayObserver:
void OnDisplayTabletStateChanged(display::TabletState state) override;
private:
// The friend class declaration here is used to control classes that can set
// the tablet state.
......
......@@ -4,6 +4,8 @@
#include "ui/display/display_observer.h"
#include "ui/display/tablet_state.h"
namespace display {
DisplayObserver::~DisplayObserver() {}
......@@ -22,4 +24,6 @@ void DisplayObserver::OnDisplayMetricsChanged(const Display& display,
void DisplayObserver::OnCurrentWorkspaceChanged(
const std::string& new_workspace) {}
void DisplayObserver::OnDisplayTabletStateChanged(TabletState state) {}
} // namespace display
......@@ -12,6 +12,7 @@
namespace display {
class Display;
enum class TabletState;
// Observers for display configuration changes.
class DISPLAY_EXPORT DisplayObserver : public base::CheckedObserver {
......@@ -55,6 +56,9 @@ class DISPLAY_EXPORT DisplayObserver : public base::CheckedObserver {
// |new_workspace|.
virtual void OnCurrentWorkspaceChanged(const std::string& new_workspace);
// Called when display changes between conventional and tablet mode.
virtual void OnDisplayTabletStateChanged(TabletState state);
protected:
~DisplayObserver() override;
};
......
......@@ -65,7 +65,7 @@ constexpr uint32_t kMaxWpPresentationVersion = 1;
constexpr uint32_t kMaxWpViewporterVersion = 1;
constexpr uint32_t kMaxTextInputManagerVersion = 1;
constexpr uint32_t kMaxExplicitSyncVersion = 2;
constexpr uint32_t kMinAuraShellVersion = 10;
constexpr uint32_t kMinAuraShellVersion = 11;
constexpr uint32_t kMinWlDrmVersion = 2;
constexpr uint32_t kMinWlOutputVersion = 2;
constexpr uint32_t kMaxXdgDecorationVersion = 1;
......
......@@ -13,7 +13,6 @@
#include "ui/display/display.h"
#include "ui/display/display_finder.h"
#include "ui/display/display_list.h"
#include "ui/display/display_observer.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/display_color_spaces.h"
#include "ui/gfx/geometry/point.h"
......@@ -133,6 +132,13 @@ void WaylandScreen::AddOrUpdateDisplay(uint32_t output_id,
window->UpdateBufferScale(true);
}
void WaylandScreen::OnTabletStateChanged(display::TabletState tablet_state) {
auto* observer_list = display_list_.observers();
for (auto& observer : *observer_list) {
observer.OnDisplayTabletStateChanged(tablet_state);
}
}
base::WeakPtr<WaylandScreen> WaylandScreen::GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
......
......@@ -12,6 +12,8 @@
#include "base/observer_list.h"
#include "base/optional.h"
#include "ui/display/display_list.h"
#include "ui/display/display_observer.h"
#include "ui/display/tablet_state.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/point.h"
#include "ui/ozone/public/platform_screen.h"
......@@ -37,6 +39,8 @@ class WaylandScreen : public PlatformScreen {
int32_t output_scale);
void OnOutputRemoved(uint32_t output_id);
void OnTabletStateChanged(display::TabletState tablet_state);
base::WeakPtr<WaylandScreen> GetWeakPtr();
// PlatformScreen overrides:
......
......@@ -4,7 +4,12 @@
#include "ui/ozone/platform/wayland/host/wayland_zaura_shell.h"
#include <components/exo/wayland/protocol/aura-shell-client-protocol.h>
#include "base/check.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_output_manager.h"
#include "ui/ozone/platform/wayland/host/wayland_screen.h"
namespace ui {
......@@ -13,8 +18,33 @@ WaylandZAuraShell::WaylandZAuraShell(zaura_shell* aura_shell,
: obj_(aura_shell), connection_(connection) {
DCHECK(obj_);
DCHECK(connection_);
static const zaura_shell_listener zaura_shell_listener = {
&WaylandZAuraShell::OnLayoutMode,
};
zaura_shell_add_listener(obj_.get(), &zaura_shell_listener, this);
}
WaylandZAuraShell::~WaylandZAuraShell() = default;
// static
void WaylandZAuraShell::OnLayoutMode(void* data,
struct zaura_shell* zaura_shell,
uint32_t layout_mode) {
auto* self = static_cast<WaylandZAuraShell*>(data);
auto* screen = self->connection_->wayland_output_manager()->wayland_screen();
// |screen| is null in some unit test suites.
if (!screen)
return;
switch (layout_mode) {
case ZAURA_SHELL_LAYOUT_MODE_WINDOWED:
screen->OnTabletStateChanged(display::TabletState::kInClamshellMode);
return;
case ZAURA_SHELL_LAYOUT_MODE_TABLET:
screen->OnTabletStateChanged(display::TabletState::kInTabletMode);
return;
}
}
} // namespace ui
......@@ -22,6 +22,11 @@ class WaylandZAuraShell {
zaura_shell* wl_object() const { return obj_.get(); }
private:
// zaura_shell_listener
static void OnLayoutMode(void* data,
struct zaura_shell* zaura_shell,
uint32_t layout_mode);
wl::Object<zaura_shell> obj_;
WaylandConnection* const connection_;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment