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

CCBUG: 453166
CCBUG: 352476
wilder-5.26
Fushan Wen 4 years ago committed by Nate Graham
parent 6eac53b6d0
commit 53fdac77ec
  1. 21
      shell/panelview.cpp
  2. 10
      shell/panelview.h
  3. 9
      shell/shellcorona.cpp
  4. 4
      shell/shellcorona.h

@ -30,6 +30,7 @@
#include <Plasma/Package> #include <Plasma/Package>
#include <KWayland/Client/plasmashell.h> #include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/plasmawindowmanagement.h>
#include <KWayland/Client/surface.h> #include <KWayland/Client/surface.h>
#if HAVE_X11 #if HAVE_X11
@ -1400,11 +1401,31 @@ void PanelView::refreshStatus(Plasma::Types::ItemStatus status)
} }
} else if (status == Plasma::Types::AcceptingInputStatus) { } else if (status == Plasma::Types::AcceptingInputStatus) {
setFlags(flags() & ~Qt::WindowDoesNotAcceptFocus); setFlags(flags() & ~Qt::WindowDoesNotAcceptFocus);
#ifdef HAVE_X11
if (KWindowSystem::isPlatformX11()) {
m_previousWId = KWindowSystem::activeWindow();
}
KWindowSystem::forceActiveWindow(winId()); KWindowSystem::forceActiveWindow(winId());
#endif
if (m_shellSurface) { if (m_shellSurface) {
m_previousPlasmaWindow = m_corona->waylandPlasmaWindowManagementInterface()->activeWindow();
m_shellSurface->setPanelTakesFocus(true); m_shellSurface->setPanelTakesFocus(true);
} }
} else { } 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(); restoreAutoHide();
setFlags(flags() | Qt::WindowDoesNotAcceptFocus); setFlags(flags() | Qt::WindowDoesNotAcceptFocus);
if (m_shellSurface) { if (m_shellSurface) {

@ -9,6 +9,9 @@
#include <Plasma/Theme> #include <Plasma/Theme>
#include <QPointer> #include <QPointer>
#include <QTimer> #include <QTimer>
#ifdef HAVE_X11
#include <QWindow> // For WId
#endif
#include <PlasmaQuick/ConfigView> #include <PlasmaQuick/ConfigView>
#include <PlasmaQuick/ContainmentView> #include <PlasmaQuick/ContainmentView>
@ -20,6 +23,7 @@ namespace KWayland
namespace Client namespace Client
{ {
class PlasmaShellSurface; class PlasmaShellSurface;
class PlasmaWindow;
} }
} }
@ -279,5 +283,11 @@ private:
QPointer<QScreen> m_screenToFollow; QPointer<QScreen> m_screenToFollow;
QMetaObject::Connection m_transientWindowVisibleWatcher; 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; static const int STRUTSTIMERDELAY = 200;
}; };

@ -46,6 +46,7 @@
#include <KWayland/Client/connection_thread.h> #include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/plasmashell.h> #include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/plasmawindowmanagement.h>
#include <KWayland/Client/registry.h> #include <KWayland/Client/registry.h>
#include "config-ktexteditor.h" // HAVE_KTEXTEDITOR #include "config-ktexteditor.h" // HAVE_KTEXTEDITOR
@ -2174,6 +2175,9 @@ void ShellCorona::setupWaylandIntegration()
connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry](quint32 name, quint32 version) { connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry](quint32 name, quint32 version) {
m_waylandPlasmaShell = registry->createPlasmaShell(name, version, this); 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(); registry->setup();
connection->roundtrip(); connection->roundtrip();
qApp->installEventFilter(new DismissPopupEventFilter(this)); qApp->installEventFilter(new DismissPopupEventFilter(this));
@ -2184,6 +2188,11 @@ KWayland::Client::PlasmaShell *ShellCorona::waylandPlasmaShellInterface() const
return m_waylandPlasmaShell; return m_waylandPlasmaShell;
} }
KWayland::Client::PlasmaWindowManagement *ShellCorona::waylandPlasmaWindowManagementInterface() const
{
return m_waylandWindowManagement;
}
ScreenPool *ShellCorona::screenPool() const ScreenPool *ShellCorona::screenPool() const
{ {
return m_screenPool; return m_screenPool;

@ -52,6 +52,7 @@ namespace KWayland
namespace Client namespace Client
{ {
class PlasmaShell; class PlasmaShell;
class PlasmaWindowManagement;
} }
} }
@ -100,6 +101,7 @@ public:
Plasma::Containment *createContainmentForActivity(const QString &activity, int screenNum); Plasma::Containment *createContainmentForActivity(const QString &activity, int screenNum);
KWayland::Client::PlasmaShell *waylandPlasmaShellInterface() const; KWayland::Client::PlasmaShell *waylandPlasmaShellInterface() const;
KWayland::Client::PlasmaWindowManagement *waylandPlasmaWindowManagementInterface() const;
ScreenPool *screenPool() const; ScreenPool *screenPool() const;
@ -268,6 +270,8 @@ private:
QTimer m_invariantsTimer; QTimer m_invariantsTimer;
#endif #endif
KWayland::Client::PlasmaShell *m_waylandPlasmaShell; KWayland::Client::PlasmaShell *m_waylandPlasmaShell;
// For getting the active window on Wayland
KWayland::Client::PlasmaWindowManagement *m_waylandWindowManagement = nullptr;
bool m_closingDown : 1; bool m_closingDown : 1;
QString m_testModeLayout; QString m_testModeLayout;

Loading…
Cancel
Save