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:
sniperbeamer
2009-08-28 14:59:52 +00:00
parent be548a6446
commit d97fce6394
8 changed files with 75 additions and 5 deletions

View File

@@ -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();

View File

@@ -47,6 +47,7 @@ class AutoTypeGlobalX11 : public AutoTypeX11, public AutoTypeGlobal {
Window focusedWindow;
int oldCode;
uint oldMod;
bool inGlobalAutoType;
};
#endif // _AUTOTYPEGLOBALX11_H_

View File

@@ -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){

View File

@@ -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_