From 0a3cfebd9963494c9cc59dff9adaca504cff17e3 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Fri, 27 Dec 2024 17:09:01 -0500 Subject: [PATCH 1/2] Show Auto-Type select dialog even if window title is empty * Fixes #11597 --- src/autotype/AutoType.cpp | 45 +++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index e87357aa36..17373b142e 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -434,38 +434,33 @@ void AutoType::startGlobalAutoType(const QString& search) */ void AutoType::performGlobalAutoType(const QList>& dbList, const QString& search) { - if (!m_plugin) { - return; - } - - if (!m_inGlobalAutoTypeDialog.tryLock()) { - return; - } - - if (m_windowTitleForGlobal.isEmpty()) { - m_inGlobalAutoTypeDialog.unlock(); + if (!m_plugin || !m_inGlobalAutoTypeDialog.tryLock()) { return; } QList matchList; - bool hideExpired = config()->get(Config::AutoTypeHideExpiredEntry).toBool(); - - for (const auto& db : dbList) { - const QList dbEntries = db->rootGroup()->entriesRecursive(); - for (auto entry : dbEntries) { - auto group = entry->group(); - if (!group || !group->resolveAutoTypeEnabled() || !entry->autoTypeEnabled()) { - continue; - } + // Generate entry/sequence match list if there is a valid window title + if (!m_windowTitleForGlobal.isEmpty()) { + bool hideExpired = config()->get(Config::AutoTypeHideExpiredEntry).toBool(); + for (const auto& db : dbList) { + const QList dbEntries = db->rootGroup()->entriesRecursive(); + for (auto entry : dbEntries) { + auto group = entry->group(); + if (!group || !group->resolveAutoTypeEnabled() || !entry->autoTypeEnabled()) { + continue; + } - if (hideExpired && entry->isExpired()) { - continue; - } - const QSet sequences = Tools::asSet(entry->autoTypeSequences(m_windowTitleForGlobal)); - for (const auto& sequence : sequences) { - matchList << AutoTypeMatch(entry, sequence); + if (hideExpired && entry->isExpired()) { + continue; + } + const QSet sequences = Tools::asSet(entry->autoTypeSequences(m_windowTitleForGlobal)); + for (const auto& sequence : sequences) { + matchList << AutoTypeMatch(entry, sequence); + } } } + } else { + qWarning() << "Auto-Type: Window title was empty from the operating system"; } // Show the selection dialog if we always ask, have multiple matches, or no matches From c8c59fbc1917969d3397f4de2db619da42ff574b Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Fri, 27 Dec 2024 17:10:17 -0500 Subject: [PATCH 2/2] Always reset Auto-Type state on finished signal There were a couple code paths that did not reset the state appropriately and could cause undefined behavior in the auto-type processing. --- src/autotype/AutoType.cpp | 6 +----- src/autotype/AutoType.h | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index 17373b142e..738dc5ac68 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -153,6 +153,7 @@ AutoType::AutoType(QObject* parent, bool test) #endif } + connect(this, SIGNAL(autotypeFinished()), SLOT(resetAutoTypeState())); connect(qApp, SIGNAL(aboutToQuit()), SLOT(unloadPlugin())); } @@ -353,7 +354,6 @@ void AutoType::executeAutoTypeActions(const Entry* entry, } } - resetAutoTypeState(); m_inAutoType.unlock(); emit autotypeFinished(); } @@ -488,11 +488,9 @@ void AutoType::performGlobalAutoType(const QList>& dbLi m_windowForGlobal, virtualMode ? AutoTypeExecutor::Mode::VIRTUAL : AutoTypeExecutor::Mode::NORMAL); - resetAutoTypeState(); }); connect(selectDialog, &QDialog::rejected, this, [this] { restoreWindowState(); - resetAutoTypeState(); emit autotypeFinished(); }); @@ -506,10 +504,8 @@ void AutoType::performGlobalAutoType(const QList>& dbLi } else if (!matchList.isEmpty()) { // Only one match and not asking, do it! executeAutoTypeActions(matchList.first().first, matchList.first().second, m_windowForGlobal); - resetAutoTypeState(); } else { // We should never get here - resetAutoTypeState(); emit autotypeFinished(); } } diff --git a/src/autotype/AutoType.h b/src/autotype/AutoType.h index 17264dd68c..4708a70932 100644 --- a/src/autotype/AutoType.h +++ b/src/autotype/AutoType.h @@ -66,6 +66,7 @@ public slots: private slots: void startGlobalAutoType(const QString& search); void unloadPlugin(); + void resetAutoTypeState(); private: enum WindowState @@ -83,7 +84,6 @@ private slots: WId window = 0, AutoTypeExecutor::Mode mode = AutoTypeExecutor::Mode::NORMAL); void restoreWindowState(); - void resetAutoTypeState(); static QList> parseSequence(const QString& entrySequence, const Entry* entry, QString& error, bool syntaxOnly = false);