Commit c33f4c64 authored by Antonio Gomes's avatar Antonio Gomes Committed by Chromium LUCI CQ

[ozone/wayland] Relax condition to call PlatformWindowDelegate::OnWindowStateChanged()

The way the logic is currently implemented prevents the delegate from
being notified of state changes most of the time. This CL relaxes the
sanity checks in  WaylandToplevelWindow::HandleSurfaceConfigure(),
causing DesktopWTHPlatform::OnWindowStateChanged() to get called
more frequently, but holding now the correct state.

This will allow DesktopWTHPlatform to react on state changes more
reliably (eg lacros' immersive fullscreen behavior).

Last, this CL changes the logic that sets and unsets fullscreen.
Previously, UnSetFullscreen() was being called
for all operations different than "enter fullscreen".
This is needless and might mess compositors up.

TEST=ozone_unittests adapted accordingly.

BUG=1113900
R=msisov@igalia.com, nickdiego@igalia.com

Change-Id: Iddffaf5d4f0e20898db0016320935904b9816e45
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2601219
Auto-Submit: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarNick Yamane <nickdiego@igalia.com>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#840125}
parent 61177b33
...@@ -267,7 +267,6 @@ void WaylandToplevelWindow::HandleSurfaceConfigure(int32_t width, ...@@ -267,7 +267,6 @@ void WaylandToplevelWindow::HandleSurfaceConfigure(int32_t width,
bool is_activated) { bool is_activated) {
// Store the old state to propagte state changes if Wayland decides to change // Store the old state to propagte state changes if Wayland decides to change
// the state to something else. // the state to something else.
PlatformWindowState old_state = state_;
if (state_ == PlatformWindowState::kMinimized && !is_activated) { if (state_ == PlatformWindowState::kMinimized && !is_activated) {
state_ = PlatformWindowState::kMinimized; state_ = PlatformWindowState::kMinimized;
} else if (is_fullscreen) { } else if (is_fullscreen) {
...@@ -278,7 +277,6 @@ void WaylandToplevelWindow::HandleSurfaceConfigure(int32_t width, ...@@ -278,7 +277,6 @@ void WaylandToplevelWindow::HandleSurfaceConfigure(int32_t width,
state_ = PlatformWindowState::kNormal; state_ = PlatformWindowState::kNormal;
} }
const bool state_changed = old_state != state_;
const bool is_normal = state_ == PlatformWindowState::kNormal; const bool is_normal = state_ == PlatformWindowState::kNormal;
// Update state before notifying delegate. // Update state before notifying delegate.
...@@ -316,8 +314,8 @@ void WaylandToplevelWindow::HandleSurfaceConfigure(int32_t width, ...@@ -316,8 +314,8 @@ void WaylandToplevelWindow::HandleSurfaceConfigure(int32_t width,
SetOrResetRestoredBounds(); SetOrResetRestoredBounds();
ApplyPendingBounds(); ApplyPendingBounds();
if (state_changed) // Notify the delegate about the latest state set.
delegate()->OnWindowStateChanged(state_); delegate()->OnWindowStateChanged(state_);
if (did_active_change) if (did_active_change)
delegate()->OnActivationChanged(is_active_); delegate()->OnActivationChanged(is_active_);
...@@ -426,22 +424,21 @@ void WaylandToplevelWindow::TriggerStateChanges() { ...@@ -426,22 +424,21 @@ void WaylandToplevelWindow::TriggerStateChanges() {
if (!shell_surface_) if (!shell_surface_)
return; return;
if (state_ == PlatformWindowState::kFullScreen)
shell_surface_->SetFullscreen();
else
shell_surface_->UnSetFullscreen();
// Call UnSetMaximized only if current state is normal. Otherwise, if the // Call UnSetMaximized only if current state is normal. Otherwise, if the
// current state is fullscreen and the previous is maximized, calling // current state is fullscreen and the previous is maximized, calling
// UnSetMaximized may result in wrong restored window position that clients // UnSetMaximized may result in wrong restored window position that clients
// are not allowed to know about. // are not allowed to know about.
if (state_ == PlatformWindowState::kMaximized) if (state_ == PlatformWindowState::kMinimized) {
shell_surface_->SetMinimized();
} else if (state_ == PlatformWindowState::kFullScreen) {
shell_surface_->SetFullscreen();
} else if (previous_state_ == PlatformWindowState::kFullScreen) {
shell_surface_->UnSetFullscreen();
} else if (state_ == PlatformWindowState::kMaximized) {
shell_surface_->SetMaximized(); shell_surface_->SetMaximized();
else if (state_ == PlatformWindowState::kNormal) } else if (state_ == PlatformWindowState::kNormal) {
shell_surface_->UnSetMaximized(); shell_surface_->UnSetMaximized();
}
if (state_ == PlatformWindowState::kMinimized)
shell_surface_->SetMinimized();
connection()->ScheduleFlush(); connection()->ScheduleFlush();
} }
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
using ::testing::_; using ::testing::_;
using ::testing::Eq; using ::testing::Eq;
using ::testing::InvokeWithoutArgs;
using ::testing::Mock; using ::testing::Mock;
using ::testing::Return; using ::testing::Return;
using ::testing::SaveArg; using ::testing::SaveArg;
...@@ -296,7 +297,7 @@ TEST_P(WaylandWindowTest, MaximizeAndRestore) { ...@@ -296,7 +297,7 @@ TEST_P(WaylandWindowTest, MaximizeAndRestore) {
kMaximizedBounds.height())); kMaximizedBounds.height()));
EXPECT_CALL(delegate_, OnActivationChanged(Eq(true))); EXPECT_CALL(delegate_, OnActivationChanged(Eq(true)));
EXPECT_CALL(delegate_, OnBoundsChanged(kMaximizedBounds)); EXPECT_CALL(delegate_, OnBoundsChanged(kMaximizedBounds));
EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(0); EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(1);
window_->Maximize(); window_->Maximize();
SendConfigureEvent(xdg_surface_, kMaximizedBounds.width(), SendConfigureEvent(xdg_surface_, kMaximizedBounds.width(),
kMaximizedBounds.height(), ++serial, kMaximizedBounds.height(), ++serial,
...@@ -327,7 +328,7 @@ TEST_P(WaylandWindowTest, MaximizeAndRestore) { ...@@ -327,7 +328,7 @@ TEST_P(WaylandWindowTest, MaximizeAndRestore) {
EXPECT_CALL(*xdg_surface_, SetWindowGeometry(0, 0, kNormalBounds.width(), EXPECT_CALL(*xdg_surface_, SetWindowGeometry(0, 0, kNormalBounds.width(),
kNormalBounds.height())); kNormalBounds.height()));
EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(0); EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(1);
EXPECT_CALL(delegate_, OnActivationChanged(_)).Times(0); EXPECT_CALL(delegate_, OnActivationChanged(_)).Times(0);
EXPECT_CALL(delegate_, OnBoundsChanged(kNormalBounds)); EXPECT_CALL(delegate_, OnBoundsChanged(kNormalBounds));
EXPECT_CALL(*GetXdgToplevel(), UnsetMaximized()); EXPECT_CALL(*GetXdgToplevel(), UnsetMaximized());
...@@ -347,7 +348,7 @@ TEST_P(WaylandWindowTest, Minimize) { ...@@ -347,7 +348,7 @@ TEST_P(WaylandWindowTest, Minimize) {
Sync(); Sync();
EXPECT_CALL(*GetXdgToplevel(), SetMinimized()); EXPECT_CALL(*GetXdgToplevel(), SetMinimized());
EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(0); EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(1);
window_->Minimize(); window_->Minimize();
EXPECT_EQ(window_->GetPlatformWindowState(), PlatformWindowState::kMinimized); EXPECT_EQ(window_->GetPlatformWindowState(), PlatformWindowState::kMinimized);
...@@ -364,8 +365,14 @@ TEST_P(WaylandWindowTest, Minimize) { ...@@ -364,8 +365,14 @@ TEST_P(WaylandWindowTest, Minimize) {
// Send one additional empty configuration event (which means the surface is // Send one additional empty configuration event (which means the surface is
// not maximized, fullscreen or activated) to ensure, WaylandWindow stays in // not maximized, fullscreen or activated) to ensure, WaylandWindow stays in
// the same minimized state and doesn't notify its delegate. // the same minimized state, but the delegate is always notified.
EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(0); //
// TODO(tonikito): Improve filtering of delegate notification here.
ui::PlatformWindowState state;
EXPECT_CALL(delegate_, OnWindowStateChanged(_))
.WillRepeatedly(DoAll(SaveArg<0>(&state), InvokeWithoutArgs([&]() {
EXPECT_EQ(state, PlatformWindowState::kMinimized);
})));
SendConfigureEvent(xdg_surface_, 0, 0, 3, states.get()); SendConfigureEvent(xdg_surface_, 0, 0, 3, states.get());
Sync(); Sync();
...@@ -385,7 +392,7 @@ TEST_P(WaylandWindowTest, SetFullscreenAndRestore) { ...@@ -385,7 +392,7 @@ TEST_P(WaylandWindowTest, SetFullscreenAndRestore) {
AddStateToWlArray(XDG_TOPLEVEL_STATE_FULLSCREEN, states.get()); AddStateToWlArray(XDG_TOPLEVEL_STATE_FULLSCREEN, states.get());
EXPECT_CALL(*GetXdgToplevel(), SetFullscreen()); EXPECT_CALL(*GetXdgToplevel(), SetFullscreen());
EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(0); EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(1);
window_->ToggleFullscreen(); window_->ToggleFullscreen();
// Make sure than WaylandWindow manually handles fullscreen states. Check the // Make sure than WaylandWindow manually handles fullscreen states. Check the
// comment in the WaylandWindow::ToggleFullscreen. // comment in the WaylandWindow::ToggleFullscreen.
...@@ -395,7 +402,7 @@ TEST_P(WaylandWindowTest, SetFullscreenAndRestore) { ...@@ -395,7 +402,7 @@ TEST_P(WaylandWindowTest, SetFullscreenAndRestore) {
Sync(); Sync();
EXPECT_CALL(*GetXdgToplevel(), UnsetFullscreen()); EXPECT_CALL(*GetXdgToplevel(), UnsetFullscreen());
EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(0); EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(1);
window_->Restore(); window_->Restore();
EXPECT_EQ(window_->GetPlatformWindowState(), PlatformWindowState::kNormal); EXPECT_EQ(window_->GetPlatformWindowState(), PlatformWindowState::kNormal);
// Reinitialize wl_array, which removes previous old states. // Reinitialize wl_array, which removes previous old states.
...@@ -481,9 +488,8 @@ TEST_P(WaylandWindowTest, StartMaximized) { ...@@ -481,9 +488,8 @@ TEST_P(WaylandWindowTest, StartMaximized) {
Sync(); Sync();
// Once the surface will be activated, the window state mustn't be changed // Once the surface will be activated, the window state gets updated.
// and retain the same. EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(1);
EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(0);
EXPECT_EQ(window_->GetPlatformWindowState(), PlatformWindowState::kMaximized); EXPECT_EQ(window_->GetPlatformWindowState(), PlatformWindowState::kMaximized);
// Activate the surface. // Activate the surface.
...@@ -599,7 +605,7 @@ TEST_P(WaylandWindowTest, SetMaximizedFullscreenAndRestore) { ...@@ -599,7 +605,7 @@ TEST_P(WaylandWindowTest, SetMaximizedFullscreenAndRestore) {
kMaximizedBounds.height())); kMaximizedBounds.height()));
EXPECT_CALL(delegate_, OnActivationChanged(Eq(true))); EXPECT_CALL(delegate_, OnActivationChanged(Eq(true)));
EXPECT_CALL(delegate_, OnBoundsChanged(kMaximizedBounds)); EXPECT_CALL(delegate_, OnBoundsChanged(kMaximizedBounds));
EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(0); EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(1);
window_->Maximize(); window_->Maximize();
// State changes are synchronous. // State changes are synchronous.
EXPECT_EQ(PlatformWindowState::kMaximized, window_->GetPlatformWindowState()); EXPECT_EQ(PlatformWindowState::kMaximized, window_->GetPlatformWindowState());
...@@ -615,7 +621,7 @@ TEST_P(WaylandWindowTest, SetMaximizedFullscreenAndRestore) { ...@@ -615,7 +621,7 @@ TEST_P(WaylandWindowTest, SetMaximizedFullscreenAndRestore) {
EXPECT_CALL(*xdg_surface_, SetWindowGeometry(0, 0, kMaximizedBounds.width(), EXPECT_CALL(*xdg_surface_, SetWindowGeometry(0, 0, kMaximizedBounds.width(),
kMaximizedBounds.height())); kMaximizedBounds.height()));
EXPECT_CALL(delegate_, OnBoundsChanged(_)).Times(0); EXPECT_CALL(delegate_, OnBoundsChanged(_)).Times(0);
EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(0); EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(1);
window_->ToggleFullscreen(); window_->ToggleFullscreen();
// State changes are synchronous. // State changes are synchronous.
EXPECT_EQ(PlatformWindowState::kFullScreen, EXPECT_EQ(PlatformWindowState::kFullScreen,
...@@ -633,9 +639,8 @@ TEST_P(WaylandWindowTest, SetMaximizedFullscreenAndRestore) { ...@@ -633,9 +639,8 @@ TEST_P(WaylandWindowTest, SetMaximizedFullscreenAndRestore) {
EXPECT_CALL(*xdg_surface_, SetWindowGeometry(0, 0, kNormalBounds.width(), EXPECT_CALL(*xdg_surface_, SetWindowGeometry(0, 0, kNormalBounds.width(),
kNormalBounds.height())); kNormalBounds.height()));
EXPECT_CALL(*GetXdgToplevel(), UnsetFullscreen()); EXPECT_CALL(*GetXdgToplevel(), UnsetFullscreen());
EXPECT_CALL(*GetXdgToplevel(), UnsetMaximized());
EXPECT_CALL(delegate_, OnBoundsChanged(kNormalBounds)); EXPECT_CALL(delegate_, OnBoundsChanged(kNormalBounds));
EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(0); EXPECT_CALL(delegate_, OnWindowStateChanged(_)).Times(1);
window_->Restore(); window_->Restore();
EXPECT_EQ(PlatformWindowState::kNormal, window_->GetPlatformWindowState()); EXPECT_EQ(PlatformWindowState::kNormal, window_->GetPlatformWindowState());
// Reinitialize wl_array, which removes previous old states. // Reinitialize wl_array, which removes previous old states.
......
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