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
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
#include <QDesktopWidget>
|
||||
#include "AutoTypeDlg.h"
|
||||
|
||||
bool AutoTypeDlg::dialogVisible = false;
|
||||
|
||||
AutoTypeDlg::AutoTypeDlg(QList<IEntryHandle*> entries, QList<int> 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){
|
||||
|
||||
@@ -25,10 +25,12 @@ class AutoTypeDlg : public QWidget, private Ui::AutoTypeDlg
|
||||
|
||||
public:
|
||||
AutoTypeDlg(QList<IEntryHandle*> entries, QList<int> 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<QTreeWidgetItem*,AutoTypeEntry> itemToEntry;
|
||||
QPixmap BannerPixmap;
|
||||
bool pWasLocked;
|
||||
static bool dialogVisible;
|
||||
};
|
||||
|
||||
@@ -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; i<num_children; i++)
|
||||
windowTitles(children[i], titleList);
|
||||
}
|
||||
else
|
||||
else {
|
||||
XFree(children);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList AutoTypeGlobalX11::getAllWindowTitles(){
|
||||
@@ -111,6 +124,13 @@ void AutoTypeGlobalX11::windowTitles(Window window, QStringList& titleList){
|
||||
}
|
||||
|
||||
void AutoTypeGlobalX11::performGlobal(){
|
||||
if (AutoTypeDlg::isDialogVisible()) {
|
||||
qWarning("Already performing auto-type, ignoring this one");
|
||||
return;
|
||||
}
|
||||
|
||||
focusWindow = getFocusWindow();
|
||||
|
||||
bool wasLocked = mainWin->isLocked();
|
||||
if (wasLocked)
|
||||
mainWin->OnUnLockWorkspace();
|
||||
|
||||
@@ -47,6 +47,7 @@ class AutoTypeGlobalX11 : public AutoTypeX11, public AutoTypeGlobal {
|
||||
Window focusedWindow;
|
||||
int oldCode;
|
||||
uint oldMod;
|
||||
bool inGlobalAutoType;
|
||||
};
|
||||
|
||||
#endif // _AUTOTYPEGLOBALX11_H_
|
||||
|
||||
@@ -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;i<Keys.size();i++){
|
||||
if (focusWindow != getFocusWindow()) {
|
||||
qWarning("Focus window changed, interrupting auto-type");
|
||||
break;
|
||||
}
|
||||
|
||||
if (Keys[i].type==TypeKey){
|
||||
SendKeyPressedEvent(Keys[i].data, 0);
|
||||
sleepKeyStrokeDelay();
|
||||
@@ -154,6 +174,9 @@ void AutoTypeX11::perform(IEntryHandle* entry, bool hideWindow, int nr, bool was
|
||||
if (hideWindow && !(config->showSysTrayIcon() && config->minimizeTray()) )
|
||||
mainWin->showMinimized();
|
||||
}
|
||||
|
||||
inAutoType = false;
|
||||
focusWindow = NULL;
|
||||
}
|
||||
|
||||
void AutoTypeX11::sleepTime(int msec){
|
||||
|
||||
@@ -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_
|
||||
|
||||
Reference in New Issue
Block a user