Skip to content

Commit

Permalink
Merge bitcoin-core/gui#831: GUIUtil::brintToFront workaround for Wayland
Browse files Browse the repository at this point in the history
15aa7d0 gui, qt: brintToFront workaround for Wayland (pablomartin4btc)

Pull request description:

  There are known issues around handling windows focus in `Wayland` ([this one specific](https://bugs.kde.org/show_bug.cgi?id=462574) in KDE but also in [gnome](https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/730)).

  The idea is that the workaround will be executed if `bitcoin-qt` is running using `Wayland` platform (e.g.: `QT_QPA_PLATFORM=wayland ./src/qt/bitcoin-qt -regtest`), since the workaround behaviour looks like re-opening the window again (which I tried to fix by moving the window to the original position and/ or re-setting the original geometry without success) while in `X11` (not sure in Mac) the current `GUIUtil::brintToFront` actually sets the focus to the desired window, keeping its original position as expected, and I didn't want to change that (`X11` behaviour).

  The solution was [initially discussed](bitcoin-core/gui#817 (comment)) with hebasto in bitcoin#817.

ACKs for top commit:
  hebasto:
    ACK 15aa7d0.

Tree-SHA512: 141d6cc4a618026e551627b9f4cc284285980db02a54a7b19c7de91e8c5adccf0c1d67380625146b5413e58c59f39c9e944ed5ba68cb8644f67647518918b6f7
  • Loading branch information
hebasto committed Aug 12, 2024
2 parents b21ba08 + 15aa7d0 commit 1873e41
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,19 +405,26 @@ bool isObscured(QWidget *w)

void bringToFront(QWidget* w)
{
#ifdef Q_OS_MACOS
ForceActivation();
#endif

if (w) {
// activateWindow() (sometimes) helps with keyboard focus on Windows
if (w->isMinimized()) {
w->showNormal();
} else {
if (QGuiApplication::platformName() == "wayland") {
auto flags = w->windowFlags();
w->setWindowFlags(flags|Qt::WindowStaysOnTopHint);
w->show();
w->setWindowFlags(flags);
w->show();
} else {
#ifdef Q_OS_MACOS
ForceActivation();
#endif
// activateWindow() (sometimes) helps with keyboard focus on Windows
if (w->isMinimized()) {
w->showNormal();
} else {
w->show();
}
w->activateWindow();
w->raise();
}
w->activateWindow();
w->raise();
}
}

Expand Down

0 comments on commit 1873e41

Please sign in to comment.