Formatting the code.

This commit is contained in:
Louis-Bertrand Varin 2018-03-31 16:01:30 -04:00
parent 74efc57369
commit 8324d03f0a
294 changed files with 3796 additions and 3740 deletions

View file

@ -20,7 +20,7 @@
#include <QApplication>
#include <QPluginLoader>
#include <QRegularExpression>
#include <QRegularExpression>
#include "config-keepassx.h"
@ -304,8 +304,8 @@ void AutoType::performGlobalAutoType(const QList<Database*>& dbList)
auto* msgBox = new QMessageBox();
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setWindowTitle(tr("Auto-Type - KeePassXC"));
msgBox->setText(tr("Couldn't find an entry that matches the window title:").append("\n\n")
.append(windowTitle));
msgBox->setText(
tr("Couldn't find an entry that matches the window title:").append("\n\n").append(windowTitle));
msgBox->setIcon(QMessageBox::Information);
msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->show();
@ -323,8 +323,7 @@ void AutoType::performGlobalAutoType(const QList<Database*>& dbList)
auto* selectDialog = new AutoTypeSelectDialog();
// connect slots, both of which must unlock the m_inGlobalAutoTypeDialog mutex
connect(selectDialog, SIGNAL(matchActivated(AutoTypeMatch)),
SLOT(performAutoTypeFromGlobal(AutoTypeMatch)));
connect(selectDialog, SIGNAL(matchActivated(AutoTypeMatch)), SLOT(performAutoTypeFromGlobal(AutoTypeMatch)));
connect(selectDialog, SIGNAL(rejected()), SLOT(autoTypeRejectedFromGlobal()));
selectDialog->setMatchList(matchList);
@ -449,11 +448,11 @@ QList<AutoTypeAction*> AutoType::createActionFromTemplate(const QString& tmpl, c
list.append(new AutoTypeKey(Qt::Key_Left));
} else if (tmplName.compare("right", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Right));
} else if (tmplName.compare("insert", Qt::CaseInsensitive) == 0 ||
tmplName.compare("ins", Qt::CaseInsensitive) == 0) {
} else if (tmplName.compare("insert", Qt::CaseInsensitive) == 0
|| tmplName.compare("ins", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Insert));
} else if (tmplName.compare("delete", Qt::CaseInsensitive) == 0 ||
tmplName.compare("del", Qt::CaseInsensitive) == 0) {
} else if (tmplName.compare("delete", Qt::CaseInsensitive) == 0
|| tmplName.compare("del", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Delete));
} else if (tmplName.compare("home", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Home));
@ -463,8 +462,9 @@ QList<AutoTypeAction*> AutoType::createActionFromTemplate(const QString& tmpl, c
list.append(new AutoTypeKey(Qt::Key_PageUp));
} else if (tmplName.compare("pgdown", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_PageDown));
} else if (tmplName.compare("backspace", Qt::CaseInsensitive) == 0 ||
tmplName.compare("bs", Qt::CaseInsensitive) == 0 || tmplName.compare("bksp", Qt::CaseInsensitive) == 0) {
} else if (tmplName.compare("backspace", Qt::CaseInsensitive) == 0
|| tmplName.compare("bs", Qt::CaseInsensitive) == 0
|| tmplName.compare("bksp", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Backspace));
} else if (tmplName.compare("break", Qt::CaseInsensitive) == 0) {
list.append(new AutoTypeKey(Qt::Key_Pause));
@ -591,13 +591,13 @@ QList<QString> AutoType::autoTypeSequences(const Entry* entry, const QString& wi
}
}
if (config()->get("AutoTypeEntryTitleMatch").toBool() &&
windowMatchesTitle(windowTitle, entry->resolvePlaceholder(entry->title()))) {
if (config()->get("AutoTypeEntryTitleMatch").toBool()
&& windowMatchesTitle(windowTitle, entry->resolvePlaceholder(entry->title()))) {
sequenceList.append(entry->effectiveAutoTypeSequence());
}
if (config()->get("AutoTypeEntryURLMatch").toBool() &&
windowMatchesUrl(windowTitle, entry->resolvePlaceholder(entry->url()))) {
if (config()->get("AutoTypeEntryURLMatch").toBool()
&& windowMatchesUrl(windowTitle, entry->resolvePlaceholder(entry->url()))) {
sequenceList.append(entry->effectiveAutoTypeSequence());
}
@ -605,7 +605,7 @@ QList<QString> AutoType::autoTypeSequences(const Entry* entry, const QString& wi
return sequenceList;
}
} else {
sequenceList.append(entry->effectiveAutoTypeSequence());
sequenceList.append(entry->effectiveAutoTypeSequence());
}
return sequenceList;
@ -659,7 +659,7 @@ bool AutoType::checkSyntax(const QString& string)
QString allowRepetition = "(?:\\s\\d+)?";
// the ":" allows custom commands with syntax S:Field
// exclude BEEP otherwise will be checked as valid
QString normalCommands = "(?!BEEP\\s)[A-Z:]*" + allowRepetition;
QString normalCommands = "(?!BEEP\\s)[A-Z:]*" + allowRepetition;
QString specialLiterals = "[\\^\\%\\(\\)~\\{\\}\\[\\]\\+]" + allowRepetition;
QString functionKeys = "(?:F[1-9]" + allowRepetition + "|F1[0-2])" + allowRepetition;
QString numpad = "NUMPAD\\d" + allowRepetition;
@ -673,9 +673,21 @@ bool AutoType::checkSyntax(const QString& string)
// a normal string not in parentheses
QString fixedStrings = "[^\\^\\%~\\+@\\{\\}]*";
QRegularExpression autoTypeSyntax("^(?:" + shortcutKeys + "|" + fixedStrings + "|\\{(?:" + normalCommands + "|" + specialLiterals +
"|" + functionKeys + "|" + numpad + "|" + delay + "|" + beep + "|" + vkey + ")\\}|\\{" + customAttributes + "\\})*$",
QRegularExpression::CaseInsensitiveOption);
QRegularExpression autoTypeSyntax(
"^(?:" + shortcutKeys + "|" + fixedStrings + "|\\{(?:" + normalCommands + "|" + specialLiterals + "|"
+ functionKeys
+ "|"
+ numpad
+ "|"
+ delay
+ "|"
+ beep
+ "|"
+ vkey
+ ")\\}|\\{"
+ customAttributes
+ "\\})*$",
QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch match = autoTypeSyntax.match(string);
return match.hasMatch();
}
@ -686,7 +698,7 @@ bool AutoType::checkSyntax(const QString& string)
bool AutoType::checkHighDelay(const QString& string)
{
// 5 digit numbers(10 seconds) are too much
QRegularExpression highDelay("\\{DELAY\\s\\d{5,}\\}", QRegularExpression::CaseInsensitiveOption);
QRegularExpression highDelay("\\{DELAY\\s\\d{5,}\\}", QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch match = highDelay.match(string);
return match.hasMatch();
}
@ -697,7 +709,7 @@ bool AutoType::checkHighDelay(const QString& string)
bool AutoType::checkSlowKeypress(const QString& string)
{
// 3 digit numbers(100 milliseconds) are too much
QRegularExpression slowKeypress("\\{DELAY=\\d{3,}\\}", QRegularExpression::CaseInsensitiveOption);
QRegularExpression slowKeypress("\\{DELAY=\\d{3,}\\}", QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch match = slowKeypress.match(string);
return match.hasMatch();
}
@ -724,7 +736,9 @@ bool AutoType::verifyAutoTypeSyntax(const QString& sequence)
return false;
} else if (AutoType::checkHighDelay(sequence)) {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(nullptr, tr("Auto-Type"),
reply = QMessageBox::question(
nullptr,
tr("Auto-Type"),
tr("This Auto-Type command contains a very long delay. Do you really want to proceed?"));
if (reply == QMessageBox::No) {
@ -732,7 +746,9 @@ bool AutoType::verifyAutoTypeSyntax(const QString& sequence)
}
} else if (AutoType::checkSlowKeypress(sequence)) {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(nullptr, tr("Auto-Type"),
reply = QMessageBox::question(
nullptr,
tr("Auto-Type"),
tr("This Auto-Type command contains very slow key presses. Do you really want to proceed?"));
if (reply == QMessageBox::No) {
@ -740,8 +756,9 @@ bool AutoType::verifyAutoTypeSyntax(const QString& sequence)
}
} else if (AutoType::checkHighRepetition(sequence)) {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(nullptr, tr("Auto-Type"),
tr("This Auto-Type command contains arguments which are repeated very often. Do you really want to proceed?"));
reply =
QMessageBox::question(nullptr, tr("Auto-Type"), tr("This Auto-Type command contains arguments which are "
"repeated very often. Do you really want to proceed?"));
if (reply == QMessageBox::No) {
return false;

View file

@ -19,10 +19,10 @@
#ifndef KEEPASSX_AUTOTYPE_H
#define KEEPASSX_AUTOTYPE_H
#include <QMutex>
#include <QObject>
#include <QStringList>
#include <QWidget>
#include <QMutex>
#include "core/AutoTypeMatch.h"
@ -47,8 +47,7 @@ public:
static bool checkSlowKeypress(const QString& string);
static bool checkHighDelay(const QString& string);
static bool verifyAutoTypeSyntax(const QString& sequence);
void performAutoType(const Entry* entry,
QWidget* hideWindow = nullptr);
void performAutoType(const Entry* entry, QWidget* hideWindow = nullptr);
inline bool isAvailable()
{

View file

@ -34,7 +34,6 @@ void AutoTypeChar::accept(AutoTypeExecutor* executor)
executor->execChar(this);
}
AutoTypeKey::AutoTypeKey(Qt::Key key)
: key(key)
{
@ -50,7 +49,6 @@ void AutoTypeKey::accept(AutoTypeExecutor* executor)
executor->execKey(this);
}
AutoTypeDelay::AutoTypeDelay(int delayMs)
: delayMs(delayMs)
{
@ -66,7 +64,6 @@ void AutoTypeDelay::accept(AutoTypeExecutor* executor)
executor->execDelay(this);
}
AutoTypeClearField::AutoTypeClearField()
{
}
@ -81,7 +78,6 @@ void AutoTypeClearField::accept(AutoTypeExecutor* executor)
executor->execClearField(this);
}
void AutoTypeExecutor::execDelay(AutoTypeDelay* action)
{
Tools::wait(action->delayMs);

View file

@ -19,8 +19,8 @@
#define KEEPASSX_AUTOTYPEACTION_H
#include <QChar>
#include <Qt>
#include <QObject>
#include <Qt>
#include "core/Global.h"
@ -29,7 +29,9 @@ class AutoTypeExecutor;
class KEEPASSX_EXPORT AutoTypeAction
{
public:
virtual ~AutoTypeAction() {}
virtual ~AutoTypeAction()
{
}
virtual AutoTypeAction* clone() = 0;
virtual void accept(AutoTypeExecutor* executor) = 0;
};
@ -75,7 +77,9 @@ public:
class KEEPASSX_EXPORT AutoTypeExecutor
{
public:
virtual ~AutoTypeExecutor() {}
virtual ~AutoTypeExecutor()
{
}
virtual void execChar(AutoTypeChar* action) = 0;
virtual void execKey(AutoTypeKey* action) = 0;
virtual void execDelay(AutoTypeDelay* action);

View file

@ -25,7 +25,9 @@
class AutoTypePlatformInterface
{
public:
virtual ~AutoTypePlatformInterface() {}
virtual ~AutoTypePlatformInterface()
{
}
virtual bool isAvailable() = 0;
virtual QStringList windowTitles() = 0;
virtual WId activeWindow() = 0;
@ -35,7 +37,9 @@ public:
virtual int platformEventFilter(void* event) = 0;
virtual int initialTimeout() = 0;
virtual bool raiseWindow(WId window) = 0;
virtual void unload() {}
virtual void unload()
{
}
virtual AutoTypeExecutor* createExecutor() = 0;

View file

@ -61,7 +61,7 @@ AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent)
connect(m_view, SIGNAL(activated(QModelIndex)), SLOT(emitMatchActivated(QModelIndex)));
connect(m_view, SIGNAL(clicked(QModelIndex)), SLOT(emitMatchActivated(QModelIndex)));
connect(m_view->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(matchRemoved()));
connect(m_view->model(), SIGNAL(rowsRemoved(QModelIndex, int, int)), SLOT(matchRemoved()));
connect(m_view, SIGNAL(rejected()), SLOT(reject()));
layout->addWidget(m_view);
@ -109,7 +109,7 @@ void AutoTypeSelectDialog::matchRemoved()
if (m_rejected) {
return;
}
if (m_view->model()->rowCount() == 0) {
reject();
}

View file

@ -36,8 +36,7 @@ void AutoTypeSelectView::mouseMoveEvent(QMouseEvent* event)
if (index.isValid()) {
setCurrentIndex(index);
setCursor(Qt::PointingHandCursor);
}
else {
} else {
unsetCursor();
}

View file

@ -50,8 +50,7 @@ void ShortcutWidget::setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers)
if (autoType()->registerGlobalShortcut(m_key, m_modifiers)) {
setStyleSheet("");
}
else {
} else {
setStyleSheet("background-color: #FF9696;");
}
}
@ -112,14 +111,12 @@ void ShortcutWidget::keyEvent(QKeyEvent* event)
if (!release && !keyIsModifier) {
if (modifiers != 0) {
setShortcut(key, modifiers);
}
else {
} else {
resetShortcut();
setStyleSheet("");
displayShortcut(key, modifiers);
}
}
else {
} else {
if (m_locked) {
resetShortcut();
setStyleSheet("");

View file

@ -33,8 +33,7 @@ bool WildcardMatcher::match(const QString& pattern)
if (patternContainsWildcard()) {
return matchWithWildcards();
}
else {
} else {
return patternEqualsText();
}
}
@ -63,8 +62,7 @@ bool WildcardMatcher::matchWithWildcards()
bool WildcardMatcher::startOrEndDoesNotMatch(const QStringList& parts)
{
return !m_text.startsWith(parts.first(), Sensitivity) ||
!m_text.endsWith(parts.last(), Sensitivity);
return !m_text.startsWith(parts.first(), Sensitivity) || !m_text.endsWith(parts.last(), Sensitivity);
}
bool WildcardMatcher::partsMatch(const QStringList& parts)

View file

@ -20,13 +20,11 @@
#include <QtPlugin>
#include "autotype/AutoTypePlatformPlugin.h"
#include "autotype/AutoTypeAction.h"
#include "autotype/AutoTypePlatformPlugin.h"
#include "autotype/test/AutoTypeTestInterface.h"
class AutoTypePlatformTest : public QObject,
public AutoTypePlatformInterface,
public AutoTypeTestInterface
class AutoTypePlatformTest : public QObject, public AutoTypePlatformInterface, public AutoTypeTestInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.keepassx.AutoTypePlatformInterface")

View file

@ -23,7 +23,9 @@
class AutoTypeTestInterface
{
public:
virtual ~AutoTypeTestInterface() {}
virtual ~AutoTypeTestInterface()
{
}
virtual void setActiveWindowTitle(const QString& title) = 0;
virtual QString actionChars() = 0;

View file

@ -94,7 +94,7 @@ void AutoTypePlatformWin::unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModi
//
int AutoTypePlatformWin::platformEventFilter(void* event)
{
MSG *msg = static_cast<MSG *>(event);
MSG* msg = static_cast<MSG*>(event);
if (msg->message == WM_HOTKEY && msg->wParam == HOTKEY_ID) {
emit globalShortcutTriggered();
@ -480,17 +480,14 @@ BOOL AutoTypePlatformWin::isAltTabWindow(HWND hwnd)
//
// Window title enum proc
//
BOOL CALLBACK AutoTypePlatformWin::windowTitleEnumProc(
_In_ HWND hwnd,
_In_ LPARAM lParam
)
BOOL CALLBACK AutoTypePlatformWin::windowTitleEnumProc(_In_ HWND hwnd, _In_ LPARAM lParam)
{
if (!isAltTabWindow(hwnd)) {
// Skip window
return TRUE;
}
QStringList *list = reinterpret_cast<QStringList *>(lParam);
QStringList* list = reinterpret_cast<QStringList*>(lParam);
QString title = windowTitle(hwnd);
if (!title.isEmpty()) {
@ -508,7 +505,7 @@ QString AutoTypePlatformWin::windowTitle(HWND hwnd)
wchar_t title[MAX_WINDOW_TITLE_LENGTH];
int count = ::GetWindowTextW(hwnd, title, MAX_WINDOW_TITLE_LENGTH);
return QString::fromUtf16(reinterpret_cast<const ushort *>(title), count);
return QString::fromUtf16(reinterpret_cast<const ushort*>(title), count);
}
//

View file

@ -22,8 +22,8 @@
#include <QtPlugin>
#include <Windows.h>
#include "autotype/AutoTypePlatformPlugin.h"
#include "autotype/AutoTypeAction.h"
#include "autotype/AutoTypePlatformPlugin.h"
class AutoTypePlatformWin : public QObject, public AutoTypePlatformInterface
{
@ -72,4 +72,3 @@ private:
};
#endif // KEEPASSX_AUTOTYPEWINDOWS_H

View file

@ -40,11 +40,14 @@ AutoTypePlatformX11::AutoTypePlatformX11()
m_atomUtf8String = XInternAtom(m_dpy, "UTF8_STRING", True);
m_atomNetActiveWindow = XInternAtom(m_dpy, "_NET_ACTIVE_WINDOW", True);
m_classBlacklist << "desktop_window" << "gnome-panel"; // Gnome
m_classBlacklist << "kdesktop" << "kicker"; // KDE 3
m_classBlacklist << "desktop_window"
<< "gnome-panel"; // Gnome
m_classBlacklist << "kdesktop"
<< "kicker"; // KDE 3
m_classBlacklist << "Plasma"; // KDE 4
m_classBlacklist << "plasmashell"; // KDE 5
m_classBlacklist << "xfdesktop" << "xfce4-panel"; // Xfce 4
m_classBlacklist << "xfdesktop"
<< "xfce4-panel"; // Xfce 4
m_currentGlobalKey = static_cast<Qt::Key>(0);
m_currentGlobalModifiers = 0;
@ -146,12 +149,9 @@ bool AutoTypePlatformX11::registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifi
startCatchXErrors();
XGrabKey(m_dpy, keycode, nativeModifiers, m_rootWindow, True, GrabModeAsync, GrabModeAsync);
XGrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask, m_rootWindow, True, GrabModeAsync,
GrabModeAsync);
XGrabKey(m_dpy, keycode, nativeModifiers | LockMask, m_rootWindow, True, GrabModeAsync,
GrabModeAsync);
XGrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask | LockMask, m_rootWindow, True,
GrabModeAsync, GrabModeAsync);
XGrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask, m_rootWindow, True, GrabModeAsync, GrabModeAsync);
XGrabKey(m_dpy, keycode, nativeModifiers | LockMask, m_rootWindow, True, GrabModeAsync, GrabModeAsync);
XGrabKey(m_dpy, keycode, nativeModifiers | Mod2Mask | LockMask, m_rootWindow, True, GrabModeAsync, GrabModeAsync);
stopCatchXErrors();
if (!m_xErrorOccurred) {
@ -160,8 +160,7 @@ bool AutoTypePlatformX11::registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifi
m_currentGlobalKeycode = keycode;
m_currentGlobalNativeModifiers = nativeModifiers;
return true;
}
else {
} else {
unregisterGlobalShortcut(key, modifiers);
return false;
}
@ -211,29 +210,26 @@ int AutoTypePlatformX11::platformEventFilter(void* event)
if (type == XCB_KEY_PRESS || type == XCB_KEY_RELEASE) {
xcb_key_press_event_t* keyPressEvent = static_cast<xcb_key_press_event_t*>(event);
if (keyPressEvent->detail == m_currentGlobalKeycode
&& (keyPressEvent->state & m_modifierMask) == m_currentGlobalNativeModifiers
&& (!QApplication::activeWindow() || QApplication::activeWindow()->isMinimized())
&& m_loaded) {
&& (keyPressEvent->state & m_modifierMask) == m_currentGlobalNativeModifiers
&& (!QApplication::activeWindow() || QApplication::activeWindow()->isMinimized())
&& m_loaded) {
if (type == XCB_KEY_PRESS) {
emit globalShortcutTriggered();
}
return 1;
}
}
else if (type == XCB_MAPPING_NOTIFY) {
} else if (type == XCB_MAPPING_NOTIFY) {
xcb_mapping_notify_event_t* mappingNotifyEvent = static_cast<xcb_mapping_notify_event_t*>(event);
if (mappingNotifyEvent->request == XCB_MAPPING_KEYBOARD
|| mappingNotifyEvent->request == XCB_MAPPING_MODIFIER)
{
|| mappingNotifyEvent->request == XCB_MAPPING_MODIFIER) {
XMappingEvent xMappingEvent;
memset(&xMappingEvent, 0, sizeof(xMappingEvent));
xMappingEvent.type = MappingNotify;
xMappingEvent.display = m_dpy;
if (mappingNotifyEvent->request == XCB_MAPPING_KEYBOARD) {
xMappingEvent.request = MappingKeyboard;
}
else {
} else {
xMappingEvent.request = MappingModifier;
}
xMappingEvent.first_keycode = mappingNotifyEvent->first_keycode;
@ -263,13 +259,12 @@ QString AutoTypePlatformX11::windowTitle(Window window, bool useBlacklist)
// the window manager spec says we should read _NET_WM_NAME first, then fall back to WM_NAME
int retVal = XGetWindowProperty(m_dpy, window, m_atomNetWmName, 0, 1000, False, m_atomUtf8String,
&type, &format, &nitems, &after, &data);
int retVal = XGetWindowProperty(
m_dpy, window, m_atomNetWmName, 0, 1000, False, m_atomUtf8String, &type, &format, &nitems, &after, &data);
if ((retVal == 0) && data) {
title = QString::fromUtf8(reinterpret_cast<char*>(data));
}
else {
} else {
XTextProperty textProp;
retVal = XGetTextProperty(m_dpy, window, &textProp, m_atomWmName);
if ((retVal != 0) && textProp.value) {
@ -278,12 +273,10 @@ QString AutoTypePlatformX11::windowTitle(Window window, bool useBlacklist)
if (textProp.encoding == m_atomUtf8String) {
title = QString::fromUtf8(reinterpret_cast<char*>(textProp.value));
}
else if ((XmbTextPropertyToTextList(m_dpy, &textProp, &textList, &count) == 0)
&& textList && (count > 0)) {
} else if ((XmbTextPropertyToTextList(m_dpy, &textProp, &textList, &count) == 0) && textList
&& (count > 0)) {
title = QString::fromLocal8Bit(textList[0]);
}
else if (textProp.encoding == m_atomString) {
} else if (textProp.encoding == m_atomString) {
title = QString::fromLocal8Bit(reinterpret_cast<char*>(textProp.value));
}
@ -386,8 +379,8 @@ bool AutoTypePlatformX11::isTopLevelWindow(Window window)
unsigned long nitems;
unsigned long after;
unsigned char* data = Q_NULLPTR;
int retVal = XGetWindowProperty(m_dpy, window, m_atomWmState, 0, 2, False, m_atomWmState, &type, &format,
&nitems, &after, &data);
int retVal = XGetWindowProperty(
m_dpy, window, m_atomWmState, 0, 2, False, m_atomWmState, &type, &format, &nitems, &after, &data);
bool result = false;
@ -408,15 +401,12 @@ KeySym AutoTypePlatformX11::charToKeySym(const QChar& ch)
ushort unicode = ch.unicode();
/* first check for Latin-1 characters (1:1 mapping) */
if ((unicode >= 0x0020 && unicode <= 0x007e)
|| (unicode >= 0x00a0 && unicode <= 0x00ff)) {
if ((unicode >= 0x0020 && unicode <= 0x007e) || (unicode >= 0x00a0 && unicode <= 0x00ff)) {
return unicode;
}
/* mapping table generated from keysymdef.h */
const uint* match = Tools::binaryFind(m_unicodeToKeysymKeys,
m_unicodeToKeysymKeys + m_unicodeToKeysymLen,
unicode);
const uint* match = Tools::binaryFind(m_unicodeToKeysymKeys, m_unicodeToKeysymKeys + m_unicodeToKeysymLen, unicode);
int index = match - m_unicodeToKeysymKeys;
if (index != m_unicodeToKeysymLen) {
return m_unicodeToKeysymValues[index];
@ -483,8 +473,7 @@ KeySym AutoTypePlatformX11::keyToKeySym(Qt::Key key)
default:
if (key >= Qt::Key_F1 && key <= Qt::Key_F16) {
return XK_F1 + (key - Qt::Key_F1);
}
else {
} else {
return NoSymbol;
}
}
@ -493,13 +482,13 @@ KeySym AutoTypePlatformX11::keyToKeySym(Qt::Key key)
/*
* Update the keyboard and modifier mapping.
* We need the KeyboardMapping for AddKeysym.
* Modifier mapping is required for clearing the modifiers.
* Modifier mapping is required for clearing the modifiers.
*/
void AutoTypePlatformX11::updateKeymap()
{
int keycode, inx;
int mod_index, mod_key;
XModifierKeymap *modifiers;
XModifierKeymap* modifiers;
if (m_xkb) {
XkbFreeKeyboard(m_xkb, XkbAllComponentsMask, True);
@ -507,10 +496,9 @@ void AutoTypePlatformX11::updateKeymap()
m_xkb = getKeyboard();
XDisplayKeycodes(m_dpy, &m_minKeycode, &m_maxKeycode);
if (m_keysymTable != NULL) XFree(m_keysymTable);
m_keysymTable = XGetKeyboardMapping(m_dpy,
m_minKeycode, m_maxKeycode - m_minKeycode + 1,
&m_keysymPerKeycode);
if (m_keysymTable != NULL)
XFree(m_keysymTable);
m_keysymTable = XGetKeyboardMapping(m_dpy, m_minKeycode, m_maxKeycode - m_minKeycode + 1, &m_keysymPerKeycode);
/* determine the keycode to use for remapped keys */
inx = (m_remapKeycode - m_minKeycode) * m_keysymPerKeycode;
@ -518,16 +506,16 @@ void AutoTypePlatformX11::updateKeymap()
for (keycode = m_minKeycode; keycode <= m_maxKeycode; keycode++) {
inx = (keycode - m_minKeycode) * m_keysymPerKeycode;
if (m_keysymTable[inx] == NoSymbol) {
m_remapKeycode = keycode;
m_currentRemapKeysym = NoSymbol;
break;
m_remapKeycode = keycode;
m_currentRemapKeysym = NoSymbol;
break;
}
}
}
/* determine the keycode to use for modifiers */
modifiers = XGetModifierMapping(m_dpy);
for (mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index ++) {
for (mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index++) {
m_modifier_keycode[mod_index] = 0;
for (mod_key = 0; mod_key < modifiers->max_keypermod; mod_key++) {
keycode = modifiers->modifiermap[mod_index * modifiers->max_keypermod + mod_key];
@ -625,7 +613,7 @@ int AutoTypePlatformX11::AddKeysym(KeySym keysym)
return 0;
}
int inx = (m_remapKeycode- m_minKeycode) * m_keysymPerKeycode;
int inx = (m_remapKeycode - m_minKeycode) * m_keysymPerKeycode;
m_keysymTable[inx] = keysym;
m_currentRemapKeysym = keysym;
@ -644,7 +632,7 @@ int AutoTypePlatformX11::AddKeysym(KeySym keysym)
void AutoTypePlatformX11::SendKeyEvent(unsigned keycode, bool press)
{
XSync(m_dpy, False);
int (*oldHandler) (Display*, XErrorEvent*) = XSetErrorHandler(MyErrorHandler);
int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(MyErrorHandler);
XTestFakeKeyEvent(m_dpy, keycode, press, 0);
XFlush(m_dpy);
@ -659,7 +647,7 @@ void AutoTypePlatformX11::SendKeyEvent(unsigned keycode, bool press)
void AutoTypePlatformX11::SendModifiers(unsigned int mask, bool press)
{
int mod_index;
for (mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index ++) {
for (mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index++) {
if (mask & (1 << mod_index)) {
SendKeyEvent(m_modifier_keycode[mod_index], press);
}
@ -670,7 +658,7 @@ void AutoTypePlatformX11::SendModifiers(unsigned int mask, bool press)
* Determines the keycode and modifier mask for the given
* keysym.
*/
int AutoTypePlatformX11::GetKeycode(KeySym keysym, unsigned int *mask)
int AutoTypePlatformX11::GetKeycode(KeySym keysym, unsigned int* mask)
{
int keycode = XKeysymToKeycode(m_dpy, keysym);
@ -688,15 +676,15 @@ int AutoTypePlatformX11::GetKeycode(KeySym keysym, unsigned int *mask)
return 0;
}
bool AutoTypePlatformX11::keysymModifiers(KeySym keysym, int keycode, unsigned int *mask)
bool AutoTypePlatformX11::keysymModifiers(KeySym keysym, int keycode, unsigned int* mask)
{
int shift, mod;
unsigned int mods_rtrn;
/* determine whether there is a combination of the modifiers
(Mod1-Mod5) with or without shift which returns keysym */
for (shift = 0; shift < 2; shift ++) {
for (mod = ControlMapIndex; mod <= Mod5MapIndex; mod ++) {
for (shift = 0; shift < 2; shift++) {
for (mod = ControlMapIndex; mod <= Mod5MapIndex; mod++) {
KeySym keysym_rtrn;
*mask = (mod == ControlMapIndex) ? shift : shift | (1 << mod);
XkbTranslateKeyCode(m_xkb, keycode, *mask, &mods_rtrn, &keysym_rtrn);
@ -709,8 +697,6 @@ bool AutoTypePlatformX11::keysymModifiers(KeySym keysym, int keycode, unsigned i
return false;
}
/*
* Send sequence of KeyPressed/KeyReleased events to the focused
* window to simulate keyboard. If modifiers (shift, control, etc)
@ -753,7 +739,7 @@ void AutoTypePlatformX11::SendKey(KeySym keysym, unsigned int modifiers)
if (!modifiers) {
// check every release_check_mask individually if it affects the keysym we would generate
// if it doesn't we probably don't need to release it
for (int mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index ++) {
for (int mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index++) {
if (release_check_mask & (1 << mod_index)) {
unsigned int mods_rtrn;
KeySym keysym_rtrn;
@ -768,7 +754,8 @@ void AutoTypePlatformX11::SendKey(KeySym keysym, unsigned int modifiers)
// finally check if the combination of pressed modifiers that we chose to ignore affects the keysym
unsigned int mods_rtrn;
KeySym keysym_rtrn;
XkbTranslateKeyCode(m_xkb, keycode, wanted_mask | (release_check_mask & ~release_mask), &mods_rtrn, &keysym_rtrn);
XkbTranslateKeyCode(
m_xkb, keycode, wanted_mask | (release_check_mask & ~release_mask), &mods_rtrn, &keysym_rtrn);
if (keysym_rtrn != keysym) {
// oh well, release all the modifiers we don't want
release_mask = release_check_mask;
@ -810,7 +797,6 @@ int AutoTypePlatformX11::MyErrorHandler(Display* my_dpy, XErrorEvent* event)
return 0;
}
AutoTypeExecutorX11::AutoTypeExecutorX11(AutoTypePlatformX11* platform)
: m_platform(platform)
{
@ -844,7 +830,6 @@ void AutoTypeExecutorX11::execClearField(AutoTypeClearField* action = nullptr)
nanosleep(&ts, nullptr);
}
int AutoTypePlatformX11::initialTimeout()
{
return 500;
@ -870,15 +855,12 @@ bool AutoTypePlatformX11::raiseWindow(WId window)
QWidget* activeWindow = QApplication::activeWindow();
if (activeWindow) {
event.xclient.data.l[2] = activeWindow->internalWinId();
}
else {
} else {
event.xclient.data.l[2] = 0;
}
event.xclient.data.l[3] = 0;
event.xclient.data.l[4] = 0;
XSendEvent(m_dpy, m_rootWindow, False,
SubstructureRedirectMask | SubstructureNotifyMask,
&event);
XSendEvent(m_dpy, m_rootWindow, False, SubstructureRedirectMask | SubstructureNotifyMask, &event);
XFlush(m_dpy);
return true;

View file

@ -22,16 +22,16 @@
#include <QApplication>
#include <QSet>
#include <QtPlugin>
#include <QWidget>
#include <QX11Info>
#include <QtPlugin>
#include <X11/XKBlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/XTest.h>
#include <X11/XKBlib.h>
#include "autotype/AutoTypePlatformPlugin.h"
#include "autotype/AutoTypeAction.h"
#include "autotype/AutoTypePlatformPlugin.h"
#define N_MOD_INDICES (Mod5MapIndex + 1)
@ -81,8 +81,8 @@ private:
void AddModifier(KeySym keysym);
void SendKeyEvent(unsigned keycode, bool press);
void SendModifiers(unsigned int mask, bool press);
int GetKeycode(KeySym keysym, unsigned int *mask);
bool keysymModifiers(KeySym keysym, int keycode, unsigned int *mask);
int GetKeycode(KeySym keysym, unsigned int* mask);
bool keysymModifiers(KeySym keysym, int keycode, unsigned int* mask);
static int MyErrorHandler(Display* my_dpy, XErrorEvent* event);