diff options
author | Jonathan White <support@dmapps.us> | 2021-05-16 16:15:31 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2021-05-16 20:29:21 +0300 |
commit | 8f0e0b6f94f46dc085f7daa13568569cb12a4206 (patch) | |
tree | dc0539f34fc35882a2a1a5adb12f790700ec1b76 | |
parent | bec7dafa91aca0d27149a83afc3f31fc8d2613d1 (diff) |
Backport: Prevent crash and resolve placeholders in Auto-Type dialog
* Modified backport of specific improvements introduced on develop branch.
- Prevent crash when multiple screens are at play and QApplication::screenAt returns nullptr.
- Resolve username/password when copying to clipboard from Auto-Type selection dialog.
-rw-r--r-- | src/autotype/AutoTypeSelectDialog.cpp | 12 | ||||
-rw-r--r-- | src/gui/entry/AutoTypeMatchView.cpp | 14 |
2 files changed, 19 insertions, 7 deletions
diff --git a/src/autotype/AutoTypeSelectDialog.cpp b/src/autotype/AutoTypeSelectDialog.cpp index 3b264b7bc..af11fb8f8 100644 --- a/src/autotype/AutoTypeSelectDialog.cpp +++ b/src/autotype/AutoTypeSelectDialog.cpp @@ -52,18 +52,24 @@ AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent) setWindowIcon(resources()->applicationIcon()); #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) - QRect screenGeometry = QApplication::screenAt(QCursor::pos())->availableGeometry(); + auto screen = QApplication::screenAt(QCursor::pos()); + if (!screen) { + // screenAt can return a nullptr, default to the primary screen + screen = QApplication::primaryScreen(); + } + QRect screenGeometry = screen->availableGeometry(); #else QRect screenGeometry = QApplication::desktop()->availableGeometry(QCursor::pos()); #endif + + // Resize to last used size QSize size = config()->get(Config::GUI_AutoTypeSelectDialogSize).toSize(); size.setWidth(qMin(size.width(), screenGeometry.width())); size.setHeight(qMin(size.height(), screenGeometry.height())); resize(size); // move dialog to the center of the screen - QPoint screenCenter = screenGeometry.center(); - move(screenCenter.x() - (size.width() / 2), screenCenter.y() - (size.height() / 2)); + move(screenGeometry.center().x() - (size.width() / 2), screenGeometry.center().y() - (size.height() / 2)); QVBoxLayout* layout = new QVBoxLayout(this); diff --git a/src/gui/entry/AutoTypeMatchView.cpp b/src/gui/entry/AutoTypeMatchView.cpp index 72ee32fde..cdf1f9425 100644 --- a/src/gui/entry/AutoTypeMatchView.cpp +++ b/src/gui/entry/AutoTypeMatchView.cpp @@ -64,14 +64,20 @@ AutoTypeMatchView::AutoTypeMatchView(QWidget* parent) void AutoTypeMatchView::userNameCopied() { - clipboard()->setText(currentMatch().entry->username()); - emit matchTextCopied(); + auto entry = currentMatch().entry; + if (entry) { + clipboard()->setText(entry->resolvePlaceholder(entry->username())); + emit matchTextCopied(); + } } void AutoTypeMatchView::passwordCopied() { - clipboard()->setText(currentMatch().entry->password()); - emit matchTextCopied(); + auto entry = currentMatch().entry; + if (entry) { + clipboard()->setText(entry->resolvePlaceholder(entry->password())); + emit matchTextCopied(); + } } void AutoTypeMatchView::keyPressEvent(QKeyEvent* event) |