Index: configure.ac =================================================================== --- configure.ac +++ configure.ac @@ -649,6 +649,32 @@ fi fi +dnl +dnl Check for KF6WindowSystem library +dnl +have_kf6windowsystem=no +if test "$have_w32_system" != "yes" && test "$pinentry_qt6" = "yes"; then + PKG_CHECK_MODULES( + KF6WINDOWSYSTEM, + [KF6WindowSystem >= 5.240], + [have_kf6windowsystem=yes], + [ + AC_MSG_WARN([pkg-config could not find the module KF6WindowSystem]) + have_kf6windowsystem=no + ] + ) +fi + +if test "$have_kf6windowsystem" = "yes"; then + PINENTRY_QT6_CFLAGS="$KF6WINDOWSYSTEM_CFLAGS $PINENTRY_QT6_CFLAGS" + PINENTRY_QT6_LIBS="$KF6WINDOWSYSTEM_LIBS $PINENTRY_QT6_LIBS" + AC_DEFINE(PINENTRY_KWINDOWSYSTEM, 1, [pinentry-qt should use KF6WindowSystem.]) +else + if test "$have_w32_system" != "yes"; then + AC_MSG_WARN([pinentry-qt will be built without window parenting on wayland]) + fi +fi + dnl dnl Check for Qt4 pinentry program. dnl Index: qt/main.cpp =================================================================== --- qt/main.cpp +++ qt/main.cpp @@ -72,6 +72,10 @@ #include #endif +#ifdef PINENTRY_KWINDOWSYSTEM +#include +#endif + #include "pinentry_debug.h" static QString escape_accel(const QString &s) @@ -171,6 +175,16 @@ Qt::WindowMinimizeButtonHint); } +static void +setup_foreground_window(QWidget *widget, const QString &parentWid) +{ +#ifdef PINENTRY_KWINDOWSYSTEM + widget->winId(); // Important; ensures that a window handle is returned. + KWindowSystem::setMainWindow(widget->windowHandle(), parentWid); +#endif +} + + static int qt_cmd_handler(pinentry_t pe) { @@ -219,8 +233,13 @@ if (want_pass) { PinEntryDialog pinentry(pe, nullptr, 0, true, repeatString, visibilityTT, hideTT); - setup_foreground_window(&pinentry, pe->parent_wid); + if (qApp->platformName() == QStringLiteral("wayland")) { + setup_foreground_window(&pinentry, QString::fromLatin1(qgetenv("PINENTRY_GEOM_HINT"))); + } else { + setup_foreground_window(&pinentry, pe->parent_wid); + } pinentry.setPrompt(escape_accel(from_utf8(pe->prompt))); + pinentry.setDescription(from_utf8(pe->description)); pinentry.setRepeatErrorText(repeatError); pinentry.setGenpinLabel(generateLbl); @@ -294,7 +313,11 @@ box.setTextFormat(Qt::PlainText); box.setTextInteractionFlags(Qt::TextSelectableByMouse); box.setTimeout(std::chrono::seconds{pe->timeout}); - setup_foreground_window(&box, pe->parent_wid); + if (qApp->platformName() == QStringLiteral("wayland")) { + setup_foreground_window(&box, QString::fromLatin1(qgetenv("PINENTRY_GEOM_HINT"))); + } else { + setup_foreground_window(&box, pe->parent_wid); + } const struct { QMessageBox::StandardButton button;