ckb-next  beta-v0.2.8 at branch testing
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
keyaction.h
Go to the documentation of this file.
1 #ifndef KEYACTION_H
2 #define KEYACTION_H
3 
4 #include <QObject>
5 #include <QProcess>
6 #include "keymap.h"
7 
8 class KbBind;
9 class KbAnim;
10 
11 // Class for managing an action associated with a keypress
12 
13 class KeyAction : public QObject
14 {
15  Q_OBJECT
16 public:
17  // Action/string conversion
18  KeyAction(const QString& action, QObject *parent = 0);
19  inline QString value() const { return _value; }
20  inline operator QString () const { return _value; }
21  // Empty action
22  explicit KeyAction(QObject* parent = 0);
23 
24  // No action
25  static inline QString noAction() { return ""; }
26  // Default action (usually the same as the key name, but not always)
27  static QString defaultAction(const QString& key);
28 
29  // Friendly action name
30  QString friendlyName(const KeyMap& map) const;
31  // Name to send to driver (empty string for unbind)
32  QString driverName() const;
33 
43  inline QString macroFullLine() const {
44  return isMacro() ? _value.right(_value.length()-1) : "";
45  }
46 
55  inline bool isValidMacro() const {
56  if (isMacro()) {
57  QStringList ret;
58  ret =_value.split(":");
59  return ((ret.count() >= 4) && (ret.count() <= 5));
60  } else {
61  return false;
62  }
63  }
64 
73  inline QStringList macroLine() const {
74  if (isValidMacro()) {
75  QStringList ret =_value.split(":");
76  ret.removeFirst();
77  return ret;
78  } else return QStringList();
79  }
80 
86  inline QString macroContent() const {
87  // return isValidMacro() ? _value.split(":")[1].replace(QRegExp("=\\d+"), "") : ""; ///< Is used if we have ckb without delay handling
88  return isValidMacro() ? _value.split(":")[1] : "";
89  }
90 
98  inline QString macroTiming() const {
99  if (isValidMacro()) {
100  QStringList rval = _value.split(":");
101  return (rval.length() == 4)? rval[1] : rval[4];
102  }
103  return QString("");
104  }
105 
118  void macroDisplay();
119 
120  // Mode-switch action.
121  // 0 for first mode, 1 for second, etc. Constants below for movement options
122  const static int MODE_PREV = -2, MODE_NEXT = -1;
123  const static int MODE_PREV_WRAP = -4, MODE_NEXT_WRAP = -3;
124  static QString modeAction(int mode);
125  // DPI action. 0 for sniper, 1 for first DPI, etc
126  const static int DPI_UP = -2, DPI_DOWN = -1;
127  const static int DPI_SNIPER = 0, DPI_CUSTOM = 6;
128  static QString dpiAction(int level, int customX = 0, int customY = 0);
129  // Brightness control
130  const static int LIGHT_UP = 0, LIGHT_DOWN = 1;
131  const static int LIGHT_UP_WRAP = 2, LIGHT_DOWN_WRAP = 3;
132  static QString lightAction(int type = LIGHT_UP_WRAP);
133  // Win lock control
134  const static int LOCK_TOGGLE = 0, LOCK_ON = 1, LOCK_OFF = 2;
135  static QString lockAction(int type = LOCK_TOGGLE);
136  // Key to launch a program. stop should be (<press stop> | <release stop>)
137  static const int PROGRAM_PR_MULTI = 0x04, PROGRAM_PR_INDEF = 0x00, PROGRAM_PR_KRSTOP = 0x01, PROGRAM_PR_KPSTOP = 0x02;
138  static const int PROGRAM_RE_MULTI = 0x40, PROGRAM_RE_INDEF = 0x00, PROGRAM_RE_KPSTOP = 0x20;
139  static QString programAction(const QString& onPress, const QString& onRelease, int stop);
140  // Key to start an animation
141  static QString animAction(const QUuid& guid, bool onlyOnce, bool stopOnRelease);
142  static QString macroAction(QString macroDef);
143 
144  // Action type
145  enum Type {
149  };
150  Type type() const;
151  inline bool isUnbound() const { return type() == UNBOUND; }
152  inline bool isNormal() const { return type() == NORMAL; }
153  inline bool isSpecial() const { return type() == SPECIAL; }
154  // Media is a type of normal key
155  inline bool isMedia() const { return _value == "mute" || _value == "volup" || _value == "voldn" || _value == "stop" || _value == "prev" || _value == "play" || _value == "next"; }
156  // Macro, program and animation are types of special key
157  inline bool isProgram() const { return _value.startsWith("$program:"); }
158  inline bool isAnim() const { return _value.startsWith("$anim:"); }
159  inline bool isMacro() const { return _value.startsWith("$macro:"); }
160  // Mouse is some normal keys plus DPI
161  inline bool isDPI() const { return _value.startsWith("$dpi:"); }
162  inline bool isMouse() const { return (isNormal() && (_value.startsWith("mouse") || _value.startsWith("wheel"))) || isDPI(); }
163 
164  // Splits a special action into action and parameter.
165  QString specialInfo(int& parameter) const;
166  // Get program key info (onPress, onRelease = programs, return = stop)
167  int programInfo(QString& onPress, QString& onRelease) const;
168  // Get DPI info. custom is only set if return == DPI_CUSTOM.
169  int dpiInfo(QPoint& custom) const;
170  // Get animation info.
171  QUuid animInfo(bool& onlyOnce, bool& stopOnRelease) const;
172 
173  // Perform keydown action (if any)
174  void keyEvent(KbBind* bind, bool down);
175  // Perform keyup action (if any)
176  void keyRelease(KbBind* bind);
177  // Adjusts the DISPLAY variable to the mouse's screen. Needed to ensure that programs launch on the correct screen in multihead.
178  void adjustDisplay();
179 
180 
181  ~KeyAction();
182 private:
185  inline void operator=(const KeyAction& rhs) {}
186  inline KeyAction(const KeyAction& rhs) : QObject() {}
187 
188  QString _value;
189 
190  // Currently-running programs
191  QProcess* preProgram;
192  QProcess* relProgram;
193 
194  // Mouse sniper mode (0 = inactive)
195  quint64 sniperValue;
196 };
197 
198 #endif // KEYACTION_H
static QString noAction()
Definition: keyaction.h:25
bool isProgram() const
Definition: keyaction.h:157
QProcess * preProgram
Definition: keyaction.h:191
static const int DPI_UP
Definition: keyaction.h:126
bool isMacro() const
Definition: keyaction.h:159
QString macroFullLine() const
macroFullLine If a macro command and a macro definition exists for the given key, returns the complet...
Definition: keyaction.h:43
static QString animAction(const QUuid &guid, bool onlyOnce, bool stopOnRelease)
Definition: keyaction.cpp:175
bool isMouse() const
Definition: keyaction.h:162
static QString macroAction(QString macroDef)
well documented in cpp file
Definition: keyaction.cpp:504
static const int DPI_CUSTOM
Definition: keyaction.h:127
static const int PROGRAM_PR_MULTI
Definition: keyaction.h:137
static const int PROGRAM_RE_MULTI
Definition: keyaction.h:138
static QString dpiAction(int level, int customX=0, int customY=0)
Definition: keyaction.cpp:153
QString value() const
Definition: keyaction.h:19
QString specialInfo(int &parameter) const
Definition: keyaction.cpp:180
bool isValidMacro() const
isValidMacro checks whether a keyAction contains a valid macro. This is done easily: If the macro act...
Definition: keyaction.h:55
static const int MODE_PREV
Definition: keyaction.h:122
static QString programAction(const QString &onPress, const QString &onRelease, int stop)
Definition: keyaction.cpp:168
static const int PROGRAM_PR_KPSTOP
Definition: keyaction.h:137
bool isDPI() const
Definition: keyaction.h:161
QUuid animInfo(bool &onlyOnce, bool &stopOnRelease) const
Definition: keyaction.cpp:216
QStringList macroLine() const
macroLine returns all interresting content for a macro definition.
Definition: keyaction.h:73
static const int PROGRAM_RE_INDEF
Definition: keyaction.h:138
static const int PROGRAM_PR_INDEF
Definition: keyaction.h:137
KeyAction(const QString &action, QObject *parent=0)
Definition: keyaction.cpp:22
quint64 sniperValue
Definition: keyaction.h:195
static const int DPI_SNIPER
Definition: keyaction.h:127
bool isUnbound() const
Definition: keyaction.h:151
static const int PROGRAM_RE_KPSTOP
Definition: keyaction.h:138
static QString lockAction(int type=LOCK_TOGGLE)
Definition: keyaction.cpp:164
static const int MODE_PREV_WRAP
Definition: keyaction.h:123
void adjustDisplay()
Definition: keyaction.cpp:445
static const int LOCK_ON
Definition: keyaction.h:134
void keyRelease(KbBind *bind)
bool isMedia() const
Definition: keyaction.h:155
QString _value
Definition: keyaction.h:188
bool isNormal() const
Definition: keyaction.h:152
static const int LOCK_TOGGLE
Definition: keyaction.h:134
Definition: kbanim.h:11
static QString modeAction(int mode)
Definition: keyaction.cpp:149
Definition: kbbind.h:20
static const int LIGHT_DOWN
Definition: keyaction.h:130
static const int LOCK_OFF
Definition: keyaction.h:134
int dpiInfo(QPoint &custom) const
Definition: keyaction.cpp:202
static const int PROGRAM_PR_KRSTOP
Definition: keyaction.h:137
static QString lightAction(int type=LIGHT_UP_WRAP)
Definition: keyaction.cpp:160
QString driverName() const
Definition: keyaction.cpp:230
static const int MODE_NEXT_WRAP
Definition: keyaction.h:123
bool isAnim() const
Definition: keyaction.h:158
Definition: keymap.h:49
void macroDisplay()
Debug output for invalid macro Definitions.
Definition: keyaction.cpp:437
QString macroTiming() const
macroTiming returns the macro key definition with original timing infos (the fifth and up to now last...
Definition: keyaction.h:98
void operator=(const KeyAction &rhs)
ccMSC: Don't copy key actions (the old one needs to be deleted first) frickler24: statement left as d...
Definition: keyaction.h:185
int programInfo(QString &onPress, QString &onRelease) const
Definition: keyaction.cpp:190
static const int MODE_NEXT
Definition: keyaction.h:122
Type type() const
Definition: keyaction.cpp:14
QString friendlyName(const KeyMap &map) const
Definition: keyaction.cpp:79
static const int LIGHT_DOWN_WRAP
Definition: keyaction.h:131
static const int DPI_DOWN
Definition: keyaction.h:126
QProcess * relProgram
Definition: keyaction.h:192
QString macroContent() const
macroContent returns the macro key definition only (the second part of the macro action).
Definition: keyaction.h:86
static const int LIGHT_UP_WRAP
Definition: keyaction.h:131
KeyAction(const KeyAction &rhs)
Definition: keyaction.h:186
bool isSpecial() const
Definition: keyaction.h:153
void keyEvent(KbBind *bind, bool down)
Definition: keyaction.cpp:236
static const int LIGHT_UP
Definition: keyaction.h:130
static QString defaultAction(const QString &key)
Definition: keyaction.cpp:44