Initial commit
[keepassx] / src / lib / AutoTypeX11.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2008 by Tarek Saidi, Felix Geyer                   *
3  *   tarek.saidi@arcor.de                                                  *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; version 2 of the License.               *
8
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _AUTOTYPEX11_H_
22 #define _AUTOTYPEX11_H_
23
24 #include "AutoType.h"
25
26 #include <X11/Xutil.h>
27
28 enum AutoTypeActionType{
29         TypeKey, Delay
30 };
31
32 struct AutoTypeAction{
33         AutoTypeAction(AutoTypeActionType t, KeySym d);
34         AutoTypeActionType type;
35         KeySym data;
36 };
37
38 class AutoTypeX11 : public AutoType {
39         public:
40                 AutoTypeX11(KeepassMainWindow* mainWin);
41                 void perform(IEntryHandle* entry, bool hideWindow=true, int nr=0, bool wasLocked=false);
42                 virtual void updateKeymap();
43         
44         protected:
45                 void sleepTime(int msec);
46                 inline void sleepKeyStrokeDelay(){ sleepTime(config->autoTypeKeyStrokeDelay()); };
47                 void templateToKeysyms(const QString& Template, QList<AutoTypeAction>& KeySymList,IEntryHandle* entry);
48                 void stringToKeysyms(const QString& string,QList<AutoTypeAction>& KeySymList);
49                 
50                 int AddKeysym(KeySym keysym, bool top);
51                 void AddModifier(KeySym keysym);
52                 void ReadKeymap();
53                 void SendKeyPressedEvent(KeySym keysym, unsigned int shift);
54                 void SendEvent(XKeyEvent *event);
55                 static int MyErrorHandler(Display *my_dpy, XErrorEvent *event);
56                 Window getFocusWindow();
57                 
58                 KeepassMainWindow* mainWin;
59                 Display* dpy;
60                 
61                 KeySym *keysym_table;
62                 int min_keycode, max_keycode;
63                 int keysym_per_keycode;
64                 int alt_mask;
65                 int meta_mask;
66                 int altgr_mask;
67                 KeySym altgr_keysym;
68                 bool reReadKeymap;
69                 Window focusWindow;
70         
71         private:
72                 bool inAutoType;
73 };
74
75 #endif // _AUTOTYPEX11_H_