Commit 53fdac77 authored by Fushan Wen's avatar Fushan Wen 💬 Committed by Nate Graham
Browse files

shell/panelview: restore old window focus when panel loses focus

CCBUG: 453166
CCBUG: 352476
parent 6eac53b6
Pipeline #183000 passed with stage
in 7 minutes and 5 seconds
......@@ -30,6 +30,7 @@
#include <Plasma/Package>
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/plasmawindowmanagement.h>
#include <KWayland/Client/surface.h>
#if HAVE_X11
......@@ -1400,11 +1401,31 @@ void PanelView::refreshStatus(Plasma::Types::ItemStatus status)
}
} else if (status == Plasma::Types::AcceptingInputStatus) {
setFlags(flags() & ~Qt::WindowDoesNotAcceptFocus);
#ifdef HAVE_X11
if (KWindowSystem::isPlatformX11()) {
m_previousWId = KWindowSystem::activeWindow();
}
KWindowSystem::forceActiveWindow(winId());
#endif
if (m_shellSurface) {
m_previousPlasmaWindow = m_corona->waylandPlasmaWindowManagementInterface()->activeWindow();
m_shellSurface->setPanelTakesFocus(true);
}
} else {
if (status == Plasma::Types::PassiveStatus) {
// Restores the previous focus
#ifdef HAVE_X11
if (KWindowSystem::isPlatformX11() && m_previousWId) {
KWindowSystem::forceActiveWindow(m_previousWId);
m_previousWId = 0;
}
#endif
if (m_previousPlasmaWindow) {
m_previousPlasmaWindow->requestActivate();
m_previousPlasmaWindow = nullptr;
}
}
restoreAutoHide();
setFlags(flags() | Qt::WindowDoesNotAcceptFocus);
if (m_shellSurface) {
......
......@@ -9,6 +9,9 @@
#include <Plasma/Theme>
#include <QPointer>
#include <QTimer>
#ifdef HAVE_X11
#include <QWindow> // For WId
#endif
#include <PlasmaQuick/ConfigView>
#include <PlasmaQuick/ContainmentView>
......@@ -20,6 +23,7 @@ namespace KWayland
namespace Client
{
class PlasmaShellSurface;
class PlasmaWindow;
}
}
......@@ -279,5 +283,11 @@ private:
QPointer<QScreen> m_screenToFollow;
QMetaObject::Connection m_transientWindowVisibleWatcher;
// Used to restore the previous activated window after the panel loses focus
#ifdef HAVE_X11
WId m_previousWId = 0;
#endif
KWayland::Client::PlasmaWindow *m_previousPlasmaWindow = nullptr;
static const int STRUTSTIMERDELAY = 200;
};
......@@ -46,6 +46,7 @@
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/plasmawindowmanagement.h>
#include <KWayland/Client/registry.h>
#include "config-ktexteditor.h" // HAVE_KTEXTEDITOR
......@@ -2174,6 +2175,9 @@ void ShellCorona::setupWaylandIntegration()
connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry](quint32 name, quint32 version) {
m_waylandPlasmaShell = registry->createPlasmaShell(name, version, this);
});
connect(registry, &KWayland::Client::Registry::plasmaWindowManagementAnnounced, this, [this, registry](quint32 name, quint32 version) {
m_waylandWindowManagement = registry->createPlasmaWindowManagement(name, version, this);
});
registry->setup();
connection->roundtrip();
qApp->installEventFilter(new DismissPopupEventFilter(this));
......@@ -2184,6 +2188,11 @@ KWayland::Client::PlasmaShell *ShellCorona::waylandPlasmaShellInterface() const
return m_waylandPlasmaShell;
}
KWayland::Client::PlasmaWindowManagement *ShellCorona::waylandPlasmaWindowManagementInterface() const
{
return m_waylandWindowManagement;
}
ScreenPool *ShellCorona::screenPool() const
{
return m_screenPool;
......
......@@ -52,6 +52,7 @@ namespace KWayland
namespace Client
{
class PlasmaShell;
class PlasmaWindowManagement;
}
}
......@@ -100,6 +101,7 @@ public:
Plasma::Containment *createContainmentForActivity(const QString &activity, int screenNum);
KWayland::Client::PlasmaShell *waylandPlasmaShellInterface() const;
KWayland::Client::PlasmaWindowManagement *waylandPlasmaWindowManagementInterface() const;
ScreenPool *screenPool() const;
......@@ -268,6 +270,8 @@ private:
QTimer m_invariantsTimer;
#endif
KWayland::Client::PlasmaShell *m_waylandPlasmaShell;
// For getting the active window on Wayland
KWayland::Client::PlasmaWindowManagement *m_waylandWindowManagement = nullptr;
bool m_closingDown : 1;
QString m_testModeLayout;
......
Supports Markdown
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