Initial commit
[keepassx] / src / Application_X11.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2008 by Felix Geyer                                *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; version 2 of the License.               *
7
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19
20
21 #include "Application_X11.h"
22 #include "lib/AutoTypeGlobalX11.h"
23 #include "lib/HelperX11.h"
24
25 KeepassApplication::KeepassApplication(int& argc, char** argv) : QApplication(argc, argv), remove_invalid(0){
26 }
27
28 bool KeepassApplication::x11EventFilter(XEvent* event){
29         if (autoType == NULL)
30                 return QApplication::x11EventFilter(event);
31         
32 #ifdef GLOBAL_AUTOTYPE
33         if (remove_invalid == 0) {
34                 AutoTypeGlobalX11* autoTypeGlobal = static_cast<AutoTypeGlobalX11*>(autoType);
35                 remove_invalid = ControlMask | ShiftMask | autoTypeGlobal->maskAlt() |
36                                 autoTypeGlobal->maskAltGr() | autoTypeGlobal->maskMeta();
37         }
38         
39         if (event->type==KeyPress && autoType->getShortcut().key!=0 &&
40                         event->xkey.keycode == XKeysymToKeycode(event->xkey.display,HelperX11::getKeysym(autoType->getShortcut().key)) &&
41                         (event->xkey.state&remove_invalid) == HelperX11::getShortcutModifierMask(autoType->getShortcut()) &&
42                         focusWidget()==NULL)
43         {
44                 EventOccurred = true;
45                 autoType->performGlobal();
46                 return true;
47         }
48 #endif
49         
50         if (event->type == MappingNotify) {
51                 dynamic_cast<AutoTypeX11*>(autoType)->updateKeymap();
52                 remove_invalid = 0;
53         }
54         
55         return QApplication::x11EventFilter(event);
56 }