summaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorSebastien Braun2010-10-10 01:39:14 +0200
committerSebastien Braun2010-10-10 14:05:35 +0200
commitd45ad40dd76250d3f342d70159b3737be8562139 (patch)
tree3329c6b6632fbf760abd9a63ab358e11bd55cfa9 /src/input
parentCode cleanup for X11FakeKeyboardHandler.cpp (diff)
downloadpvs-d45ad40dd76250d3f342d70159b3737be8562139.tar.gz
pvs-d45ad40dd76250d3f342d70159b3737be8562139.tar.xz
pvs-d45ad40dd76250d3f342d70159b3737be8562139.zip
Code cleanup for inputEvent.h
- Use Qt's fixed-width integral types instead of stdint.h, which I forgot to include anyway - CamelCase identifiers - fix underscore position on instance variables
Diffstat (limited to 'src/input')
-rw-r--r--src/input/inputEvent.cpp4
-rw-r--r--src/input/inputEvent.h118
-rw-r--r--src/input/inputEventHandler.h10
-rw-r--r--src/input/x11FakeKeyboardHandler.cpp10
4 files changed, 74 insertions, 68 deletions
diff --git a/src/input/inputEvent.cpp b/src/input/inputEvent.cpp
index fa623e1..b623281 100644
--- a/src/input/inputEvent.cpp
+++ b/src/input/inputEvent.cpp
@@ -18,13 +18,13 @@
// We implement operators to serialize and load an event:
QDataStream& operator <<(QDataStream& ostrm, InputEvent const& evt)
{
- ostrm << evt.type_ << evt.code_ << evt.value_;
+ ostrm << evt._type << evt._code << evt._value;
return ostrm;
}
QDataStream& operator >>(QDataStream& istrm, InputEvent& evt)
{
- istrm >> evt.type_ >> evt.code_ >> evt.value_;
+ istrm >> evt._type >> evt._code >> evt._value;
return istrm;
}
diff --git a/src/input/inputEvent.h b/src/input/inputEvent.h
index 82b059c..73b7129 100644
--- a/src/input/inputEvent.h
+++ b/src/input/inputEvent.h
@@ -39,19 +39,19 @@ private:
friend void eventToString(InputEvent const& evt, QString& str);
friend bool eventFromString(QString const& str, InputEvent& evt);
- uint16_t type_;
- uint16_t code_;
- uint32_t value_;
+ quint16 _type;
+ quint16 _code;
+ quint32 _value;
// InputEvents are immutable. Prohibit assignment:
InputEvent& operator=(InputEvent const&); // There intentionally is no implementation.
public:
- InputEvent(uint16_t type, uint16_t code, uint32_t value = 0) : type_(type), code_(code), value_(value)
+ InputEvent(quint16 type, quint16 code, quint32 value = 0) : _type(type), _code(code), _value(value)
{
}
- InputEvent(InputEvent const& other) : type_(other.type_), code_(other.code_), value_(other.value_)
+ InputEvent(InputEvent const& other) : _type(other._type), _code(other._code), _value(other._value)
{
}
@@ -59,110 +59,110 @@ public:
{
}
- static InputEvent mouseMotion(uint16_t x, uint16_t y)
+ static InputEvent mouseMotion(quint16 x, quint16 y)
{
- return InputEvent(ET_POINTER, 0, ((uint32_t)x << 16) | y);
+ return InputEvent(ET_POINTER, 0, ((quint32)x << 16) | y);
}
- static uint16_t mouseButtonsFromQt(int b);
+ static quint16 mouseButtonsFromQt(int b);
static InputEvent mousePressRelease(int button, int buttons);
static InputEvent keyboardPress(int key, int mods);
static InputEvent keyboardRelease(int key, int mods);
- static const uint16_t ET_KEY = 0;
- static const uint16_t ET_BUTTON = 1;
- static const uint16_t ET_POINTER = 2;
- static const uint16_t ET_SPECIAL = 3;
+ static const quint16 ET_KEY = 0;
+ static const quint16 ET_BUTTON = 1;
+ static const quint16 ET_POINTER = 2;
+ static const quint16 ET_SPECIAL = 3;
- static const uint16_t EC_PRESS = 0;
- static const uint16_t EC_RELEASE = 1;
- static const uint16_t EC_REBOOT = 2;
- static const uint16_t EC_SYSRQ = 3;
- static const uint16_t EC_KILL_X = 4;
- static const uint16_t EC_SAY_HELLO = 5; //< for debugging purposes
+ static const quint16 EC_PRESS = 0;
+ static const quint16 EC_RELEASE = 1;
+ static const quint16 EC_REBOOT = 2;
+ static const quint16 EC_SYSRQ = 3;
+ static const quint16 EC_KILL_X = 4;
+ static const quint16 EC_SAY_HELLO = 5; //< for debugging purposes
- typedef uint32_t event_key;
+ typedef quint32 event_key;
- typedef uint32_t event_key_modifiers;
+ typedef quint32 event_key_modifiers;
- static const uint16_t EB_LEFT = 1;
- static const uint16_t EB_MIDDLE = 2;
- static const uint16_t EB_RIGHT = 4;
+ static const quint16 EB_LEFT = 1;
+ static const quint16 EB_MIDDLE = 2;
+ static const quint16 EB_RIGHT = 4;
- static const uint32_t MODIFIER_MASK =
+ static const quint32 MODIFIER_MASK =
0x7e000000;
- uint16_t type() const
+ quint16 type() const
{
- return type_;
+ return _type;
}
- uint16_t code() const
+ quint16 code() const
{
- return code_;
+ return _code;
}
- uint32_t value() const
+ quint32 value() const
{
- return value_;
+ return _value;
}
bool isKeyboard() const
{
- return type_ == ET_KEY;
+ return _type == ET_KEY;
}
bool isButton() const
{
- return type_ == ET_BUTTON;
+ return _type == ET_BUTTON;
}
bool isPointer() const
{
- return type_ == ET_POINTER;
+ return _type == ET_POINTER;
}
bool isSpecial() const
{
- return type_ == ET_SPECIAL;
+ return _type == ET_SPECIAL;
}
bool isPress() const
{
- return code_ == EC_PRESS;
+ return _code == EC_PRESS;
}
bool isRelease() const
{
- return code_ == EC_RELEASE;
+ return _code == EC_RELEASE;
}
- uint16_t pressedButton() const
+ quint16 pressedButton() const
{
- assert(type_ == ET_BUTTON);
- return (value_ >> 16);
+ assert(_type == ET_BUTTON);
+ return (_value >> 16);
}
- uint16_t heldButtons() const
+ quint16 heldButtons() const
{
- assert(type_ == ET_BUTTON);
- return (value_ & 0xffff);
+ assert(_type == ET_BUTTON);
+ return (_value & 0xffff);
}
- uint16_t xCoord() const
+ quint16 xCoord() const
{
- assert(type_ == ET_POINTER);
- return (value_ >> 16);
+ assert(_type == ET_POINTER);
+ return (_value >> 16);
}
- uint16_t yCoord() const
+ quint16 yCoord() const
{
- assert(type_ == ET_POINTER);
- return (value_ & 0xffff);
+ assert(_type == ET_POINTER);
+ return (_value & 0xffff);
}
- static QString typeToString(uint16_t type)
+ static QString typeToString(quint16 type)
{
switch(type)
{
@@ -179,7 +179,7 @@ public:
}
}
- static QString codeToString(uint16_t code)
+ static QString codeToString(quint16 code)
{
switch(code)
{
@@ -200,17 +200,17 @@ public:
QString toString() const
{
- return QString("%1:%2:%3").arg(typeToString(type_)).arg(codeToString(code_)).arg(value_, 16);
+ return QString("%1:%2:%3").arg(typeToString(_type)).arg(codeToString(_code)).arg(_value, 16);
}
- uint32_t qt_keysym() const
+ quint32 qtKeysym() const
{
- return value_ & ~MODIFIER_MASK;
+ return _value & ~MODIFIER_MASK;
}
- uint32_t qt_modifiers() const
+ quint32 qtModifiers() const
{
- return value_ & MODIFIER_MASK;
+ return _value & MODIFIER_MASK;
}
// We want to enable InputEvent as a translation context, so we fake the tr method:
@@ -222,14 +222,14 @@ public:
struct SpecialInputEventDescription
{
- SpecialInputEventDescription(uint16_t type, uint16_t code, uint32_t value, QString const& description_)
+ SpecialInputEventDescription(quint16 type, quint16 code, quint32 value, QString const& description_)
: type(type), code(code), value(value), description(description_)
{
}
- uint16_t type;
- uint16_t code;
- uint32_t value;
+ quint16 type;
+ quint16 code;
+ quint32 value;
QString description;
InputEvent toEvent() const
diff --git a/src/input/inputEventHandler.h b/src/input/inputEventHandler.h
index 5b03a90..71a530b 100644
--- a/src/input/inputEventHandler.h
+++ b/src/input/inputEventHandler.h
@@ -176,7 +176,7 @@ struct InputEventHandlerPolicyBase
// The actual handler class need to provide doHandle and can override
// allow and isApplicable.
/////////////////////////////////////////////////////////////////////////
-/* interface */ class InputEventHandlerBase
+class InputEventHandlerBase
{
public:
enum HandlerStatus
@@ -246,9 +246,15 @@ private:
// Unfortunately, we cannot specialize member functions of a template.
// So, we need to make this a class with a static non-template member.
/////////////////////////////////////////////////////////////////////////
- template<bool Applicable, typename HandlerType>
+ template<bool Compatible, typename HandlerType>
struct ConditionallyAppend
{
+ /////////////////////////////////////////////////////////////////////////
+ // This method will never be instantiated for handlers that are
+ // not Compatible, thus generating no reference to HandlerType
+ // and permitting compilation to proceed without
+ // tedious nested preprocessor conditionals.
+ /////////////////////////////////////////////////////////////////////////
static void doIt(InputEventHandlerChain* chain)
{
chain->handlers.append(new HandlerType);
diff --git a/src/input/x11FakeKeyboardHandler.cpp b/src/input/x11FakeKeyboardHandler.cpp
index a136e45..4e3449a 100644
--- a/src/input/x11FakeKeyboardHandler.cpp
+++ b/src/input/x11FakeKeyboardHandler.cpp
@@ -772,16 +772,16 @@ void X11FakeKeyboardHandler::doHandle(InputEvent const& evt, InputEventContext c
Display* dpy = X11InputUtils::display();
// find out which keysym caused this event:
- KeycodeLookupTable::const_iterator i = keysyms.find(evt.qt_keysym());
+ KeycodeLookupTable::const_iterator i = keysyms.find(evt.qtKeysym());
if(i == keysyms.end()) {
// Special cases. We don't know how to directly translate those, so we will try to emulate them.
- switch(evt.qt_keysym())
+ switch(evt.qtKeysym())
{
case Qt::Key_Backtab:
- doHandle(InputEvent(evt.type(), evt.code(), evt.qt_modifiers() | Qt::ShiftModifier | Qt::Key_Tab));
+ doHandle(InputEvent(evt.type(), evt.code(), evt.qtModifiers() | Qt::ShiftModifier | Qt::Key_Tab));
break;
default:
- ConsoleLog writeLine(QString("Unknown keysym received: %1").arg(evt.qt_keysym(), 8, 16));
+ ConsoleLog writeLine(QString("Unknown keysym received: %1").arg(evt.qtKeysym(), 8, 16));
}
} else {
KeySym ks = (*i).second;
@@ -805,7 +805,7 @@ void X11FakeKeyboardHandler::doHandle(InputEvent const& evt, InputEventContext c
else
{
// what modifier keys do we need to press?
- XModifiers mods = translateModifiers(evt.qt_modifiers());
+ XModifiers mods = translateModifiers(evt.qtModifiers());
// we may need to press additional modifiers to generate this keysym:
if(QChar(ks, 0).isLetter())