From 7b8c699448c293cbb084f28e84ed48fa3d9b5de2 Mon Sep 17 00:00:00 2001 From: sniperbeamer Date: Thu, 25 Dec 2008 15:34:13 +0000 Subject: [PATCH] Dynamically calculate modifier value of alt, altgr and meta/win Added nostrip qmake option git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@246 b624d157-de02-0410-bad0-e51aec6abb33 --- src/Application_X11.cpp | 20 ++++++++++++++------ src/Application_X11.h | 3 +-- src/keepassx.h | 2 +- src/lib/AutoTypeGlobalX11.h | 3 +++ src/lib/AutoTypeX11.cpp | 2 +- src/lib/HelperX11.cpp | 17 +++++++++++------ src/lib/HelperX11.h | 6 +++--- src/lib/ShortcutWidget.cpp | 8 +++++++- src/src.pro | 4 ++++ 9 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/Application_X11.cpp b/src/Application_X11.cpp index 05c5b9c..8188b11 100644 --- a/src/Application_X11.cpp +++ b/src/Application_X11.cpp @@ -19,18 +19,26 @@ #include "Application_X11.h" -#include "lib/AutoType.h" +#include "lib/AutoTypeGlobalX11.h" #include "lib/HelperX11.h" -const unsigned int KeepassApplication::remove_invalid = ControlMask|ShiftMask|Mod1Mask|Mod5Mask|Mod4Mask; - -KeepassApplication::KeepassApplication(int& argc, char** argv) : QApplication(argc, argv){ +KeepassApplication::KeepassApplication(int& argc, char** argv) : QApplication(argc, argv), remove_invalid(0){ } bool KeepassApplication::x11EventFilter(XEvent* event){ + if (autoType == NULL) + return QApplication::x11EventFilter(event); + + if (remove_invalid == 0) { + AutoTypeGlobalX11* autoTypeGlobal = static_cast(autoType); + remove_invalid = ControlMask | ShiftMask | autoTypeGlobal->maskAlt() | + autoTypeGlobal->maskAltGr() | autoTypeGlobal->maskMeta(); + } + if (event->type==KeyPress && autoType->getShortcut().key!=0u && - event->xkey.keycode==XKeysymToKeycode(event->xkey.display,HelperX11::getKeysym(autoType->getShortcut().key)) && - (event->xkey.state&remove_invalid)==HelperX11::getShortcutModifierMask(autoType->getShortcut()) && focusWidget()==NULL ) + event->xkey.keycode == XKeysymToKeycode(event->xkey.display,HelperX11::getKeysym(autoType->getShortcut().key)) && + (event->xkey.state&remove_invalid) == HelperX11::getShortcutModifierMask(autoType->getShortcut()) && + focusWidget()==NULL) { EventOccurred = true; autoType->performGlobal(); diff --git a/src/Application_X11.h b/src/Application_X11.h index 206da50..3e37f4e 100644 --- a/src/Application_X11.h +++ b/src/Application_X11.h @@ -20,7 +20,6 @@ #ifndef APPLICATION_X11_H #define APPLICATION_X11_H - class KeepassApplication : public QApplication { Q_OBJECT @@ -30,7 +29,7 @@ class KeepassApplication : public QApplication bool x11EventFilter(XEvent* event); private: - static const unsigned int remove_invalid; + unsigned int remove_invalid; }; #endif // APPLICATION_X11_H diff --git a/src/keepassx.h b/src/keepassx.h index dee8608..1fd2c41 100644 --- a/src/keepassx.h +++ b/src/keepassx.h @@ -26,7 +26,7 @@ #define APP_CODE_NAME "keepassx" #define APP_SHORT_FUNC "Password Manager" #define APP_LONG_FUNC "Cross Platform Password Manager" -#define APP_VERSION "0.4.0b" +#define APP_VERSION "0.4.0beta1" #define BUILTIN_ICONS 69 diff --git a/src/lib/AutoTypeGlobalX11.h b/src/lib/AutoTypeGlobalX11.h index 409743f..2cccfc7 100644 --- a/src/lib/AutoTypeGlobalX11.h +++ b/src/lib/AutoTypeGlobalX11.h @@ -31,6 +31,9 @@ class AutoTypeGlobalX11 : public AutoTypeX11, public AutoTypeGlobal { bool registerGlobalShortcut(const Shortcut& s); void unregisterGlobalShortcut(); QStringList getAllWindowTitles(); + inline int maskAlt() { return alt_mask; }; + inline int maskAltGr() { return altgr_mask; }; + inline int maskMeta() { return meta_mask; }; private: void windowTitles(Window window, QStringList& titleList); diff --git a/src/lib/AutoTypeX11.cpp b/src/lib/AutoTypeX11.cpp index f5b7507..02b7d70 100644 --- a/src/lib/AutoTypeX11.cpp +++ b/src/lib/AutoTypeX11.cpp @@ -39,7 +39,7 @@ bool AutoTypeX11::error_detected = false; AutoTypeX11::AutoTypeX11(KeepassMainWindow* mainWin) { this->mainWin = mainWin; - dpy = mainWin->x11Info().display(); + dpy = QX11Info::display(); keysym_table = NULL; alt_mask = 0; diff --git a/src/lib/HelperX11.cpp b/src/lib/HelperX11.cpp index f9eff40..5413b05 100644 --- a/src/lib/HelperX11.cpp +++ b/src/lib/HelperX11.cpp @@ -22,13 +22,18 @@ #include #ifdef GLOBAL_AUTOTYPE +#include "AutoTypeGlobalX11.h" + int HelperX11::getShortcutModifierMask(const Shortcut& s){ - int mod=0; + AutoTypeGlobalX11* autoTypeGlobal = static_cast(autoType); + + int mod = 0; if (s.ctrl) mod |= ControlMask; if (s.shift) mod |= ShiftMask; - if (s.alt) mod |= Mod1Mask; - if (s.altgr) mod |= Mod5Mask; - if (s.win) mod |= Mod4Mask; + if (s.alt) mod |= autoTypeGlobal->maskAlt(); + if (s.altgr) mod |= autoTypeGlobal->maskAltGr(); + if (s.win) mod |= autoTypeGlobal->maskMeta(); + return mod; } #endif @@ -67,8 +72,8 @@ int (*HelperX11::oldHandler) (Display*, XErrorEvent*) = NULL; bool HelperX11::catchErrors = false; bool HelperX11::pErrorOccurred = false; -XID HelperX11::getKeysym(const QChar& c){ - KeySym unicode = c.unicode(); +KeySym HelperX11::getKeysym(const QChar& c){ + ushort unicode = c.unicode(); /* first check for Latin-1 characters (1:1 mapping) */ if ((unicode >= 0x0020 && unicode <= 0x007e) || diff --git a/src/lib/HelperX11.h b/src/lib/HelperX11.h index 6862543..489771c 100644 --- a/src/lib/HelperX11.h +++ b/src/lib/HelperX11.h @@ -20,13 +20,13 @@ #ifndef HELPERX11_H #define HELPERX11_H -#include "AutoType.h" -#include - #define XK_MISCELLANY #define XK_XKB_KEYS #define XK_3270 #define XK_CURRENCY + +#include "AutoType.h" +#include #include #include diff --git a/src/lib/ShortcutWidget.cpp b/src/lib/ShortcutWidget.cpp index 4939f8c..8a260c7 100644 --- a/src/lib/ShortcutWidget.cpp +++ b/src/lib/ShortcutWidget.cpp @@ -25,6 +25,7 @@ #include #include #include "HelperX11.h" +#include "AutoTypeGlobalX11.h" ShortcutWidget::ShortcutWidget(QWidget* parent) : QLineEdit(parent), lock(false), failed(false){ } @@ -55,8 +56,12 @@ void ShortcutWidget::keyEvent(QKeyEvent* event, bool release){ if (release && lock) return; + AutoTypeGlobalX11* autoTypeGlobal = static_cast(autoType); + unsigned int mods = HelperX11::keyboardModifiers(QX11Info::display()); - displayShortcut(event->nativeVirtualKey(), release, mods&ControlMask, mods&ShiftMask, mods&Mod1Mask, mods&Mod5Mask, mods&Mod4Mask); + displayShortcut(event->nativeVirtualKey(), release, mods & ControlMask, + mods & ShiftMask, mods & autoTypeGlobal->maskAlt(), + mods & autoTypeGlobal->maskAltGr(), mods & autoTypeGlobal->maskMeta()); } void ShortcutWidget::displayShortcut(quint32 key, bool release, bool ctrl, bool shift, bool alt, bool altgr, bool win){ @@ -74,6 +79,7 @@ void ShortcutWidget::displayShortcut(quint32 key, bool release, bool ctrl, bool text.append(tr("Win")).append(" + "); if ( !release && (keyXK_Hyper_R) && (keyXK_ISO_Last_Group_Lock) ){ + // converts key into orignal key on the keyboard KeySym keysym = XKeycodeToKeysym(QX11Info::display(), XKeysymToKeycode(QX11Info::display(),key), 0); if (keysym>=0xfd00 && keysym<=0xffff){ text.append(XKeysymToString(keysym)); diff --git a/src/src.pro b/src/src.pro index 620889e..7183955 100644 --- a/src/src.pro +++ b/src/src.pro @@ -17,6 +17,10 @@ else { CONFIG += release } +isEqual(NOSTRIP,1) { + CONFIG += nostrip +} + # lipo and freebsd cannot handle precompiled headers (yet) !isEqual(PRECOMPILED,1){ macx : isEqual(ARCH,UNIVERSAL) : PRECOMPILED = 0