[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwin/Plasma/5.10] /: Restore active client after ending showing desktop
From:       Martin_Flöser <null () kde ! org>
Date:       2017-07-01 6:20:37
Message-ID: E1dRBll-00017H-Kd () code ! kde ! org
[Download RAW message or body]

Git commit 113be5fac81a4b546e2a1b272451f50e777bdcb5 by Martin Flöser.
Committed on 01/07/2017 at 06:20.
Pushed by graesslin into branch 'Plasma/5.10'.

Restore active client after ending showing desktop

Summary:
Showing desktop requests focus on the desktop window. This means the
active window is reset. When ending showing desktop the state was not
restored.

This change addresses this problem by requesting focus to the best
window.

BUG: 375993
FIXED-IN: 5.10.4

Test Plan: New autotest and manual testing

Reviewers: #kwin, #plasma

Subscribers: plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D6420

M  +1    -0    autotests/integration/CMakeLists.txt
A  +128  -0    autotests/integration/showing_desktop_test.cpp     [License: GPL (v2)]
M  +7    -1    workspace.cpp

https://commits.kde.org/kwin/113be5fac81a4b546e2a1b272451f50e777bdcb5

diff --git a/autotests/integration/CMakeLists.txt \
b/autotests/integration/CMakeLists.txt index 60000224e..6fb5be49d 100644
--- a/autotests/integration/CMakeLists.txt
+++ b/autotests/integration/CMakeLists.txt
@@ -44,6 +44,7 @@ integrationTest(NAME testWindowSelection SRCS \
window_selection_test.cpp)  integrationTest(NAME testPointerConstraints SRCS \
pointer_constraints_test.cpp)  integrationTest(NAME testKeyboardLayout SRCS \
keyboard_layout_test.cpp)  integrationTest(NAME testKeymapCreationFailure SRCS \
keymap_creation_failure_test.cpp) +integrationTest(NAME testShowingDesktop SRCS \
showing_desktop_test.cpp)  
 if (XCB_ICCCM_FOUND)
     integrationTest(NAME testMoveResize SRCS move_resize_window_test.cpp LIBS \
                XCB::ICCCM)
diff --git a/autotests/integration/showing_desktop_test.cpp \
b/autotests/integration/showing_desktop_test.cpp new file mode 100644
index 000000000..6053479b0
--- /dev/null
+++ b/autotests/integration/showing_desktop_test.cpp
@@ -0,0 +1,128 @@
+/********************************************************************
+KWin - the KDE window manager
+This file is part of the KDE project.
+
+Copyright (C) 2017 Martin Flöser <mgraesslin@kde.org>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+#include "kwin_wayland_test.h"
+#include "platform.h"
+#include "shell_client.h"
+#include "wayland_server.h"
+#include "workspace.h"
+
+#include <KWayland/Client/plasmashell.h>
+#include <KWayland/Client/surface.h>
+#include <KWayland/Client/shell.h>
+
+using namespace KWin;
+using namespace KWayland::Client;
+
+static const QString s_socketName = \
QStringLiteral("wayland_test_kwin_showing_desktop-0"); +
+class ShowingDesktopTest : public QObject
+{
+    Q_OBJECT
+private Q_SLOTS:
+    void initTestCase();
+    void init();
+    void cleanup();
+
+    void testRestoreFocus();
+    void testRestoreFocusWithDesktopWindow();
+};
+
+void ShowingDesktopTest::initTestCase()
+{
+    qRegisterMetaType<KWin::ShellClient*>();
+    qRegisterMetaType<KWin::AbstractClient*>();
+    QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated);
+    QVERIFY(workspaceCreatedSpy.isValid());
+    kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
+    QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit()));
+
+    kwinApp()->start();
+    QVERIFY(workspaceCreatedSpy.wait());
+    waylandServer()->initWorkspace();
+}
+
+void ShowingDesktopTest::init()
+{
+    QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::PlasmaShell));
 +}
+
+void ShowingDesktopTest::cleanup()
+{
+    Test::destroyWaylandConnection();
+}
+
+void ShowingDesktopTest::testRestoreFocus()
+{
+    QScopedPointer<Surface> surface1(Test::createSurface());
+    QScopedPointer<ShellSurface> \
shellSurface1(Test::createShellSurface(surface1.data())); +    auto client1 = \
Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::blue); +    \
QScopedPointer<Surface> surface2(Test::createSurface()); +    \
QScopedPointer<ShellSurface> \
shellSurface2(Test::createShellSurface(surface2.data())); +    auto client2 = \
Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue); +    \
QVERIFY(client1 != client2); +
+    QCOMPARE(workspace()->activeClient(), client2);
+    workspace()->slotToggleShowDesktop();
+    QVERIFY(workspace()->showingDesktop());
+    workspace()->slotToggleShowDesktop();
+    QVERIFY(!workspace()->showingDesktop());
+
+    QVERIFY(workspace()->activeClient());
+    QCOMPARE(workspace()->activeClient(), client2);
+}
+
+void ShowingDesktopTest::testRestoreFocusWithDesktopWindow()
+{
+    // first create a desktop window
+
+    QScopedPointer<Surface> desktopSurface(Test::createSurface());
+    QVERIFY(!desktopSurface.isNull());
+    QScopedPointer<ShellSurface> \
desktopShellSurface(Test::createShellSurface(desktopSurface.data())); +    \
QVERIFY(!desktopSurface.isNull()); +    QScopedPointer<PlasmaShellSurface> \
plasmaSurface(Test::waylandPlasmaShell()->createSurface(desktopSurface.data())); +    \
QVERIFY(!plasmaSurface.isNull()); +    \
plasmaSurface->setRole(PlasmaShellSurface::Role::Desktop); +
+    auto desktop = Test::renderAndWaitForShown(desktopSurface.data(), QSize(100, \
50), Qt::blue); +    QVERIFY(desktop);
+    QVERIFY(desktop->isDesktop());
+
+    // now create some windows
+    QScopedPointer<Surface> surface1(Test::createSurface());
+    QScopedPointer<ShellSurface> \
shellSurface1(Test::createShellSurface(surface1.data())); +    auto client1 = \
Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::blue); +    \
QScopedPointer<Surface> surface2(Test::createSurface()); +    \
QScopedPointer<ShellSurface> \
shellSurface2(Test::createShellSurface(surface2.data())); +    auto client2 = \
Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue); +    \
QVERIFY(client1 != client2); +
+    QCOMPARE(workspace()->activeClient(), client2);
+    workspace()->slotToggleShowDesktop();
+    QVERIFY(workspace()->showingDesktop());
+    QCOMPARE(workspace()->activeClient(), desktop);
+    workspace()->slotToggleShowDesktop();
+    QVERIFY(!workspace()->showingDesktop());
+
+    QVERIFY(workspace()->activeClient());
+    QCOMPARE(workspace()->activeClient(), client2);
+}
+
+WAYLANDTEST_MAIN(ShowingDesktopTest)
+#include "showing_desktop_test.moc"
diff --git a/workspace.cpp b/workspace.cpp
index 360f9db6e..a2fbb6ab3 100644
--- a/workspace.cpp
+++ b/workspace.cpp
@@ -1307,8 +1307,14 @@ void Workspace::setShowingDesktop(bool showing)
     }
     } // ~StackingUpdatesBlocker
 
-    if (showing_desktop && topDesk)
+    if (showing_desktop && topDesk) {
         requestFocus(topDesk);
+    } else if (!showing_desktop && changed) {
+        const auto client = \
FocusChain::self()->getForActivation(VirtualDesktopManager::self()->current()); +     \
if (client) { +            activateClient(client);
+        }
+    }
     if (changed)
         emit showingDesktopChanged(showing);
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic