Release 0.4.3-3maemo with patches to disable menus/actions, add ScrollArea and fix...
[keepassx] / src / lib / HelperX11.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2006 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 #include "HelperX11.h"
22 #include <QX11Info>
23
24 #ifdef GLOBAL_AUTOTYPE
25 #include "AutoTypeGlobalX11.h"
26
27 uint HelperX11::getShortcutModifierMask(const Shortcut& s){
28         AutoTypeGlobalX11* autoTypeGlobal = static_cast<AutoTypeGlobalX11*>(autoType);
29         
30         uint mod = 0;
31         if (s.ctrl) mod |= ControlMask;
32         if (s.shift) mod |= ShiftMask;
33         if (s.alt) mod |= autoTypeGlobal->maskAlt();
34         if (s.altgr) mod |= autoTypeGlobal->maskAltGr();
35         if (s.win) mod |= autoTypeGlobal->maskMeta();
36         
37         return mod;
38 }
39 #endif
40
41 unsigned int HelperX11::keyboardModifiers(Display* d){
42         Window root, child;
43         int root_x, root_y, x, y;
44         unsigned int mask;
45         XQueryPointer(d, RootWindow(d, DefaultScreen(d)), &root, &child, &root_x, &root_y, &x, &y, &mask);
46         return mask;
47 }
48
49 void HelperX11:: startCatchErrors(){
50         Q_ASSERT(!catchErrors);
51         catchErrors = true;
52         pErrorOccurred = false;
53         oldHandler = XSetErrorHandler(x11ErrorHandler);
54 }
55
56 void HelperX11::stopCatchErrors(){
57         Q_ASSERT(catchErrors);
58         XSync(QX11Info::display(), false);
59         XSetErrorHandler(oldHandler);
60         catchErrors = false;
61 }
62
63 int HelperX11::x11ErrorHandler(Display* display, XErrorEvent* error){
64         Q_UNUSED(display)
65         Q_UNUSED(error)
66         if (catchErrors)
67                 pErrorOccurred = true;
68         return 1;
69 }
70
71 int (*HelperX11::oldHandler) (Display*, XErrorEvent*) = NULL;
72 bool HelperX11::catchErrors = false;
73 bool HelperX11::pErrorOccurred = false;
74
75 KeySym HelperX11::getKeysym(const QChar& c){
76         ushort unicode = c.unicode();
77         
78         /* first check for Latin-1 characters (1:1 mapping) */
79         if ((unicode >= 0x0020 && unicode <= 0x007e) ||
80                         (unicode >= 0x00a0 && unicode <= 0x00ff))
81                 return unicode;
82         else if (unicode >= 0x0100)
83                 return unicode|0x01000000;
84         else
85                 return NoSymbol;
86 }