Commit 2fdf002b authored by Andrey Bychkov's avatar Andrey Bychkov Committed by Nate Graham

Fix lock screen focus

Summary:
When the screen is locked, the focus always remains on the main screen. This patch fixes the problem: now the focus is on the screen where the cursor is located.

BUG: 395639
FIXED-IN: 5.16.0

Reviewers: davidedmundson

Reviewed By: davidedmundson

Subscribers: ngraham, graesslin, abetts, davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D17706
parent 059a97a1
......@@ -206,6 +206,27 @@ void UnlockApp::initialize()
installEventFilter(this);
}
QWindow *UnlockApp::getActiveScreen()
{
QWindow *activeScreen = nullptr;
if (m_views.isEmpty()) {
return activeScreen;
}
foreach (KQuickAddons::QuickViewSharedEngine *view, m_views) {
if (view->geometry().contains(QCursor::pos())) {
activeScreen = view;
break;
}
}
if (!activeScreen) {
activeScreen = m_views.first();
}
return activeScreen;
}
void UnlockApp::initializeWayland()
{
if (!platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
......@@ -383,15 +404,11 @@ void UnlockApp::desktopResized()
}
);
if (m_testing) {
// on Wayland we may not use fullscreen as that puts all windows on one screen
if (m_testing || plasmaSurface || QX11Info::isPlatformX11()) {
view->show();
} else {
// on Wayland we may not use fullscreen as that puts all windows on one screen
if (plasmaSurface) {
view->show();
} else {
view->showFullScreen();
}
view->showFullScreen();
}
view->raise();
......@@ -426,44 +443,24 @@ void UnlockApp::markViewsAsVisible(KQuickAddons::QuickViewSharedEngine *view)
void UnlockApp::getFocus()
{
if (m_views.isEmpty()) {
QWindow *activeScreen = getActiveScreen();
if (!activeScreen) {
return;
}
QWindow *w = nullptr;
// this loop is required to make the qml/graphicsscene properly handle the shared keyboard input
// ie. "type something into the box of every greeter"
foreach (KQuickAddons::QuickViewSharedEngine *view, m_views) {
if (!m_testing) {
view->setKeyboardGrabEnabled(true); // TODO - check whether this still works in master!
}
// w->setFocus(Qt::OtherFocusReason); // FIXME
}
// determine which window should actually be active and have the real input focus/grab
// FIXME - QWidget::underMouse()
// foreach (QQuickView *view, m_views) {
// if (view->underMouse()) {
// w = view;
// break;
// }
// }
if (!w) { // try harder
foreach (KQuickAddons::QuickViewSharedEngine *view, m_views) {
if (view->geometry().contains(QCursor::pos())) {
w = view;
break;
}
}
}
if (!w) { // fallback solution
w = m_views.first();
}
// activate window and grab input to be sure it really ends up there.
// focus setting is still required for proper internal QWidget state (and eg. visual reflection)
if (!m_testing) {
w->setKeyboardGrabEnabled(true); // TODO - check whether this still works in master!
activeScreen->setKeyboardGrabEnabled(true); // TODO - check whether this still works in master!
}
w->requestActivate();
// w->setFocus(Qt::OtherFocusReason); // FIXME
activeScreen->requestActivate();
}
void UnlockApp::setLockedPropertyOnViews()
......@@ -568,6 +565,13 @@ bool UnlockApp::eventFilter(QObject *obj, QEvent *event)
return false;
}
if (event->type() == QEvent::MouseButtonPress && QX11Info::isPlatformX11()) {
if (getActiveScreen()) {
getActiveScreen()->requestActivate();
}
return false;
}
if (event->type() == QEvent::KeyPress) { // react if saver is visible
shareEvent(event, qobject_cast<KQuickAddons::QuickViewSharedEngine*>(obj));
return false; // we don't care
......
......@@ -92,6 +92,7 @@ private:
void shareEvent(QEvent *e, KQuickAddons::QuickViewSharedEngine *from);
void loadWallpaperPlugin(KQuickAddons::QuickViewSharedEngine *view);
Authenticator *createAuthenticator();
QWindow *getActiveScreen();
QString m_packageName;
QUrl m_mainQmlPath;
......
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