Skip to content

Commit

Permalink
FIX(client): Improve handling of the GlobalShortcutButtons dialog
Browse files Browse the repository at this point in the history
This commit makes the shortcut configuration dialog a modal window.
It also explicitly searches for a new effective parent, such that the window
can be centered over the Mumble application instead of randomly out of bounds
of the screen. (This is most likely only necessary because of a bug in Qt, but
Qt is a pain to debug)

Fixes mumble-voip#5024
  • Loading branch information
Hartmnt committed Jun 2, 2024
1 parent 1c6e452 commit ffb2cb3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/mumble/GlobalShortcutButtons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,42 @@

#include "GlobalShortcut.h"

#include "MainWindow.h"
#include "Global.h"

#include <QRect>
#include <QTimer>

GlobalShortcutButtons::GlobalShortcutButtons(QWidget *parent) : QDialog(parent), m_ui(new Ui::GlobalShortcutButtons) {
m_ui->setupUi(this);
setModal(true);

connect(m_ui->addButton, &QPushButton::toggled, this, &GlobalShortcutButtons::toggleCapture);
connect(m_ui->removeButton, &QPushButton::clicked, this, &GlobalShortcutButtons::removeItem);

// Due to what appears to be a Qt bug, this dialog will not take
// the parent geometry into account when spawning.
// Therefore, we search for a different parent or even fallback to the
// MainWindow and move this dialog to its center.
QWidget *searchWidget = parent;
while (searchWidget && !qobject_cast< QDialog * >(searchWidget)) {
searchWidget = searchWidget->parentWidget();
}
QWidget *effectiveParent = qobject_cast< QDialog * >(searchWidget);
if (!effectiveParent && Global::get().mw && Global::get().mw->isVisible()) {
effectiveParent = Global::get().mw;
}

int32_t posx = geometry().x();
int32_t posy = geometry().y();

if (effectiveParent) {
QRect geometry = effectiveParent->geometry();
posx = geometry.center().x() - (width() / 2);
posy = geometry.center().y() - (height() / 2);
}

QTimer::singleShot(0, [this, posx, posy]() { move(posx, posy); });
}

GlobalShortcutButtons::~GlobalShortcutButtons() {
Expand Down

0 comments on commit ffb2cb3

Please sign in to comment.