From d97fce639488a23bd2d54d1cf0998b1ea860f9f0 Mon Sep 17 00:00:00 2001 From: sniperbeamer Date: Fri, 28 Aug 2009 14:59:52 +0000 Subject: [PATCH] Interrupt auto-type if the focused window changed meanwhile Update changelog git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@332 b624d157-de02-0410-bad0-e51aec6abb33 --- changelog | 10 ++++++++-- src/Kdb3Database.cpp | 2 ++ src/dialogs/AutoTypeDlg.cpp | 12 +++++++++++- src/dialogs/AutoTypeDlg.h | 3 +++ src/lib/AutoTypeGlobalX11.cpp | 24 ++++++++++++++++++++++-- src/lib/AutoTypeGlobalX11.h | 1 + src/lib/AutoTypeX11.cpp | 23 +++++++++++++++++++++++ src/lib/AutoTypeX11.h | 5 +++++ 8 files changed, 75 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index 644ea88..7ea46a6 100644 --- a/changelog +++ b/changelog @@ -1,15 +1,21 @@ ---------------------------- - 0.4.1 (2009-06-XX) + 0.4.1 (2009-08-XX) ---------------------------- - Added initial documentation - Added and improved many translations +- Seperate columns settings between normal and search results view +- Interrupt auto-type if the focused window changed meanwhile +- Reduced height of password generator dialog (Bug #2831504) +- Fixed: "Key Stroke Delay" interpreted as seconds instead of ms (Bug #2716877) +- Escape HTML chars in detail view (Bug #2836096) - Fixed: Mispelling of initialize in interface (Bug #2806402) - Fixed: Race condition on lock file (Bug #2801583) - Fixed: Modified entry does not refresh Entry Details Pane (Bug #2782262) - Fixed: Logoff doesn't close database correctly (Bug #2726197) - Fixed: Incorrect auto-type keymapping when KeePassX is in autostart - Fixed: Workspace is being locked after auto-type -- Fixed: Wrong "Key Stroke Delay" (Bug #2716877) +- Fixed: compiler warning/error "format not a string literal and no format arguments" (Bug #2815290) +- Fixed: Makefile uninstall target removes system directories (Bug #2830345) - Fixed key rounds benchmark to return incorrect results - Set default auto-type key stroke delay to 5ms - Removed "Close to Tray" option diff --git a/src/Kdb3Database.cpp b/src/Kdb3Database.cpp index d751085..2c7ca28 100644 --- a/src/Kdb3Database.cpp +++ b/src/Kdb3Database.cpp @@ -1456,7 +1456,9 @@ bool Kdb3Database::save(){ int size = EncryptedPartSize+DB_HEADER_SIZE; if (!File->resize(size)){ + // only recreate file if the new database is smaller if (File->size() > size) { + qDebug("Unable to resize, trying to recreate file"); if (!File->remove() || !File->open(QIODevice::ReadWrite)) { delete [] buffer; error=decodeFileError(File->error()); diff --git a/src/dialogs/AutoTypeDlg.cpp b/src/dialogs/AutoTypeDlg.cpp index e60791c..5405920 100644 --- a/src/dialogs/AutoTypeDlg.cpp +++ b/src/dialogs/AutoTypeDlg.cpp @@ -19,7 +19,11 @@ #include #include "AutoTypeDlg.h" +bool AutoTypeDlg::dialogVisible = false; + AutoTypeDlg::AutoTypeDlg(QList entries, QList numbers, bool wasLocked) : pWasLocked(wasLocked){ + Q_ASSERT(!dialogVisible); + dialogVisible = true; setupUi(this); setAttribute(Qt::WA_DeleteOnClose); @@ -86,8 +90,14 @@ void AutoTypeDlg::paintEvent(QPaintEvent* event){ } void AutoTypeDlg::resizeEvent(QResizeEvent* event){ - Q_UNUSED(event); createBanner(&BannerPixmap,getPixmap("keepassx_large"),tr("Auto-Type"),width()); + QWidget::resizeEvent(event); +} + +void AutoTypeDlg::closeEvent(QCloseEvent* event) { + Q_ASSERT(dialogVisible); + dialogVisible = false; + QWidget::closeEvent(event); } bool AutoTypeDlg::event(QEvent* event){ diff --git a/src/dialogs/AutoTypeDlg.h b/src/dialogs/AutoTypeDlg.h index abb5f5a..dc293c3 100644 --- a/src/dialogs/AutoTypeDlg.h +++ b/src/dialogs/AutoTypeDlg.h @@ -25,10 +25,12 @@ class AutoTypeDlg : public QWidget, private Ui::AutoTypeDlg public: AutoTypeDlg(QList entries, QList numbers, bool wasLocked); + inline static bool isDialogVisible() { return dialogVisible; }; protected: void paintEvent(QPaintEvent* event); void resizeEvent(QResizeEvent* event); + void closeEvent(QCloseEvent* event); bool event(QEvent* event); private slots: @@ -43,4 +45,5 @@ class AutoTypeDlg : public QWidget, private Ui::AutoTypeDlg QHash itemToEntry; QPixmap BannerPixmap; bool pWasLocked; + static bool dialogVisible; }; diff --git a/src/lib/AutoTypeGlobalX11.cpp b/src/lib/AutoTypeGlobalX11.cpp index 761ce44..6d96a7e 100644 --- a/src/lib/AutoTypeGlobalX11.cpp +++ b/src/lib/AutoTypeGlobalX11.cpp @@ -38,6 +38,8 @@ AutoTypeGlobalX11::AutoTypeGlobalX11(KeepassMainWindow* mainWin) : AutoTypeX11(m focusedWindow = 0; oldCode = 0; oldMod = 0; + inGlobalAutoType = false; + //windowBlacklist << "kicker" << "KDE Desktop"; classBlacklist << "desktop_window" << "gnome-panel"; // Gnome classBlacklist << "kdesktop" << "kicker"; // KDE 3 @@ -51,11 +53,21 @@ void AutoTypeGlobalX11::updateKeymap() { } void AutoTypeGlobalX11::perform(IEntryHandle* entry, bool hideWindow, int nr, bool wasLocked){ + if (inGlobalAutoType) + return; + inGlobalAutoType = true; + if (focusedWindow && (!hideWindow || wasLocked)) { // detect if global auto-type XSetInputFocus(dpy, focusedWindow, RevertToPointerRoot, CurrentTime); focusedWindow = 0; } + else { + focusWindow = NULL; + } + AutoTypeX11::perform(entry, hideWindow, nr, wasLocked); + + inGlobalAutoType = false; } void AutoTypeGlobalX11::windowTitles(Window window, QStringList& titleList){ @@ -95,12 +107,13 @@ void AutoTypeGlobalX11::windowTitles(Window window, QStringList& titleList){ Window* children = NULL; unsigned int num_children; int tree = XQueryTree(dpy, window, &root, &parent, &children, &num_children); - if (tree && children){ + if (tree && children) { for (uint i=0; iisLocked(); if (wasLocked) mainWin->OnUnLockWorkspace(); diff --git a/src/lib/AutoTypeGlobalX11.h b/src/lib/AutoTypeGlobalX11.h index fc18b68..e1a2a3b 100644 --- a/src/lib/AutoTypeGlobalX11.h +++ b/src/lib/AutoTypeGlobalX11.h @@ -47,6 +47,7 @@ class AutoTypeGlobalX11 : public AutoTypeX11, public AutoTypeGlobal { Window focusedWindow; int oldCode; uint oldMod; + bool inGlobalAutoType; }; #endif // _AUTOTYPEGLOBALX11_H_ diff --git a/src/lib/AutoTypeX11.cpp b/src/lib/AutoTypeX11.cpp index b768a35..e31970e 100644 --- a/src/lib/AutoTypeX11.cpp +++ b/src/lib/AutoTypeX11.cpp @@ -38,6 +38,7 @@ AutoTypeAction::AutoTypeAction(AutoTypeActionType t, KeySym d) : type(t), data(d AutoTypeX11::AutoTypeX11(KeepassMainWindow* mainWin) { this->mainWin = mainWin; dpy = QX11Info::display(); + inAutoType = false; keysym_table = NULL; alt_mask = 0; @@ -57,7 +58,18 @@ void AutoTypeX11::updateKeymap() { meta_mask = Mod4Mask; } +Window AutoTypeX11::getFocusWindow() { + Window w; + int revert_to_return; + XGetInputFocus(dpy, &w, &revert_to_return); + return w; +} + void AutoTypeX11::perform(IEntryHandle* entry, bool hideWindow, int nr, bool wasLocked){ + if (inAutoType) + return; + inAutoType = true; + QString indexStr; if (nr==0) indexStr = "Auto-Type:"; @@ -130,8 +142,16 @@ void AutoTypeX11::perform(IEntryHandle* entry, bool hideWindow, int nr, bool was QApplication::processEvents(); sleepTime(config->autoTypePreGap()); + if (!focusWindow) + focusWindow = getFocusWindow(); + QString type; for(int i=0;ishowSysTrayIcon() && config->minimizeTray()) ) mainWin->showMinimized(); } + + inAutoType = false; + focusWindow = NULL; } void AutoTypeX11::sleepTime(int msec){ diff --git a/src/lib/AutoTypeX11.h b/src/lib/AutoTypeX11.h index 98f3063..f2f731c 100644 --- a/src/lib/AutoTypeX11.h +++ b/src/lib/AutoTypeX11.h @@ -53,6 +53,7 @@ class AutoTypeX11 : public AutoType { void SendKeyPressedEvent(KeySym keysym, unsigned int shift); void SendEvent(XKeyEvent *event); static int MyErrorHandler(Display *my_dpy, XErrorEvent *event); + Window getFocusWindow(); KeepassMainWindow* mainWin; Display* dpy; @@ -65,6 +66,10 @@ class AutoTypeX11 : public AutoType { int altgr_mask; KeySym altgr_keysym; bool reReadKeymap; + Window focusWindow; + + private: + bool inAutoType; }; #endif // _AUTOTYPEX11_H_