From 5f2e0b72990402d2b9f7df8c79187b03fbcd3007 Mon Sep 17 00:00:00 2001
From: David Edmundson <kde@davidedmundson.co.uk>
Date: Fri, 16 Nov 2018 11:59:33 +0000
Subject: [PATCH] [wayland] WlShell cache the pre-maximised geometry before
 going fullscreen

Summary:
In shell surface, maximise mode and fullscreen are exclusive
fullscreen->toplevel should restore the state we had before maximising

Test Plan: testMaximisedToFullscreen unit test

Reviewers: #kwin, graesslin

Reviewed By: #kwin, graesslin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D16921
---
 shell_client.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/shell_client.cpp b/shell_client.cpp
index f6b9530ccd..b7291791d5 100644
--- a/shell_client.cpp
+++ b/shell_client.cpp
@@ -944,10 +944,17 @@ void ShellClient::setFullScreen(bool set, bool user)
     set = rules()->checkFullScreen(set && !isSpecialWindow());
     setShade(ShadeNone);
     bool was_fs = isFullScreen();
-    if (was_fs)
+    if (was_fs) {
         workspace()->updateFocusMousePosition(Cursor::pos()); // may cause leave event
-    else
-        m_geomFsRestore = geometry();
+    } else {
+        // in shell surface, maximise mode and fullscreen are exclusive
+        // fullscreen->toplevel should restore the state we had before maximising
+        if (m_shellSurface && m_maximizeMode == MaximizeMode::MaximizeFull) {
+            m_geomFsRestore = m_geomMaximizeRestore;
+        } else {
+            m_geomFsRestore = geometry();
+        }
+    }
     m_fullScreen = set;
     if (was_fs == isFullScreen())
         return;