diff --git a/src/gui/DatabaseOpenWidget.ui b/src/gui/DatabaseOpenWidget.ui index 1e018f2904..57a9719853 100644 --- a/src/gui/DatabaseOpenWidget.ui +++ b/src/gui/DatabaseOpenWidget.ui @@ -2,14 +2,6 @@ DatabaseOpenWidget - - - 0 - 0 - 592 - 522 - - Unlock KePassXC Database diff --git a/src/gui/PasswordEdit.cpp b/src/gui/PasswordEdit.cpp index 590d62b9ce..56369d8717 100644 --- a/src/gui/PasswordEdit.cpp +++ b/src/gui/PasswordEdit.cpp @@ -22,15 +22,12 @@ #include "core/FilePath.h" #include "gui/Font.h" -#include -#include -#include - #if defined(Q_OS_WIN) #include #elif defined(Q_OS_MACOS) -// TODO +#include #elif defined(Q_OS_UNIX) +#include #include // namespace required to avoid name clashes with declarations in XKBlib.h namespace X11 @@ -45,7 +42,6 @@ const QColor PasswordEdit::ErrorColor = QColor(255, 125, 125); PasswordEdit::PasswordEdit(QWidget* parent) : QLineEdit(parent) , m_basePasswordEdit(nullptr) - , m_capslockPollTimer(new QTimer(this)) { const QIcon errorIcon = filePath()->icon("status", "dialog-error"); m_errorAction = addAction(errorIcon, QLineEdit::TrailingPosition); @@ -64,8 +60,6 @@ PasswordEdit::PasswordEdit(QWidget* parent) QFont passwordFont = Font::fixedFont(); passwordFont.setLetterSpacing(QFont::PercentageSpacing, 110); setFont(passwordFont); - - connect(m_capslockPollTimer, SIGNAL(timeout()), SLOT(checkCapslockState())); } void PasswordEdit::enableVerifyMode(PasswordEdit* basePasswordEdit) @@ -140,19 +134,13 @@ void PasswordEdit::autocompletePassword(const QString& password) } } -void PasswordEdit::hideEvent(QHideEvent* event) -{ - QWidget::hideEvent(event); - m_capslockPollTimer->stop(); -} - -void PasswordEdit::showEvent(QShowEvent* event) +bool PasswordEdit::event(QEvent* event) { - QWidget::showEvent(event); if (!m_basePasswordEdit) { - // poll caps lock state only for primary password edits - m_capslockPollTimer->start(50); + // check caps lock state only for primary password edits + checkCapslockState(); } + return QLineEdit::event(event); } void PasswordEdit::checkCapslockState() @@ -162,14 +150,14 @@ void PasswordEdit::checkCapslockState() #if defined(Q_OS_WIN) newCapslockState = (GetKeyState(VK_CAPITAL) == 1); #elif defined(Q_OS_MACOS) - // TODO + newCapslockState = ((CGEventSourceFlagsState(kCGEventSourceStateHIDSystemState) & kCGEventFlagMaskAlphaShift) != 0); #elif defined(Q_OS_UNIX) if (QX11Info::isPlatformX11() && QX11Info::display()) { unsigned state = 0; // reinterpret cast needed, since we namespaced the XKBlib.h include if (X11::XkbGetIndicatorState( reinterpret_cast(QX11Info::display()), XkbUseCoreKbd, &state) == Success) { - newCapslockState = ((state & 1u) == 1); + newCapslockState = ((state & 1u) != 0); } } #endif diff --git a/src/gui/PasswordEdit.h b/src/gui/PasswordEdit.h index 2368472208..c26507c9c7 100644 --- a/src/gui/PasswordEdit.h +++ b/src/gui/PasswordEdit.h @@ -23,8 +23,6 @@ #include #include -class QTimer; - class PasswordEdit : public QLineEdit { Q_OBJECT @@ -41,8 +39,7 @@ public slots: void setShowPassword(bool show); protected: - void showEvent(QShowEvent* event) override; - void hideEvent(QHideEvent* event) override; + bool event(QEvent* event) override; signals: void showPasswordChanged(bool show); @@ -60,7 +57,6 @@ private slots: QPointer m_errorAction; QPointer m_correctAction; QPointer m_basePasswordEdit; - QPointer m_capslockPollTimer; }; #endif // KEEPASSX_PASSWORDEDIT_H