ckb-next  v0.2.8 at branch master
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, KeyMap::Model model);
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_CYCLE_UP = -4, DPI_CYCLE_DOWN = -3;
127  const static int DPI_UP = -2, DPI_DOWN = -1;
128  const static int DPI_SNIPER = 0, DPI_CUSTOM = 6;
129  static QString dpiAction(int level, int customX = 0, int customY = 0);
130  // Brightness control
131  const static int LIGHT_UP = 0, LIGHT_DOWN = 1;
132  const static int LIGHT_UP_WRAP = 2, LIGHT_DOWN_WRAP = 3;
133  static QString lightAction(int type = LIGHT_UP_WRAP);
134  // Win lock control
135  const static int LOCK_TOGGLE = 0, LOCK_ON = 1, LOCK_OFF = 2;
136  static QString lockAction(int type = LOCK_TOGGLE);
137  // Key to launch a program. stop should be (<press stop> | <release stop>)
138  static const int PROGRAM_PR_MULTI = 0x04, PROGRAM_PR_INDEF = 0x00, PROGRAM_PR_KRSTOP = 0x01, PROGRAM_PR_KPSTOP = 0x02;
139  static const int PROGRAM_RE_MULTI = 0x40, PROGRAM_RE_INDEF = 0x00, PROGRAM_RE_KPSTOP = 0x20;
140  static QString programAction(const QString& onPress, const QString& onRelease, int stop);
141  // Key to start an animation
142  static QString animAction(const QUuid& guid, bool onlyOnce, bool stopOnRelease);
143  static QString macroAction(QString macroDef);
144 
145  // Action type
146  enum Type {
150  };
151  Type type() const;
152  inline bool isUnbound() const { return type() == UNBOUND; }
153  inline bool isNormal() const { return type() == NORMAL; }
154  inline bool isSpecial() const { return type() == SPECIAL; }
155  // Media is a type of normal key
156  inline bool isMedia() const { return _value == "mute" || _value == "volup" || _value == "voldn" || _value == "stop" || _value == "prev" || _value == "play" || _value == "next"; }
157  // Macro, program and animation are types of special key
158  inline bool isProgram() const { return _value.startsWith("$program:"); }
159  inline bool isAnim() const { return _value.startsWith("$anim:"); }
160  inline bool isMacro() const { return _value.startsWith("$macro:"); }
161  // Mouse is some normal keys plus DPI
162  inline bool isDPI() const { return _value.startsWith("$dpi:"); }
163  inline bool isMouse() const { return (isNormal() && (_value.startsWith("mouse") || _value.startsWith("wheel"))) || isDPI(); }
164 
165  // Splits a special action into action and parameter.
166  QString specialInfo(int& parameter) const;
167  // Get program key info (onPress, onRelease = programs, return = stop)
168  int programInfo(QString& onPress, QString& onRelease) const;
169  // Get DPI info. custom is only set if return == DPI_CUSTOM.
170  int dpiInfo(QPoint& custom) const;
171  // Get animation info.
172  QUuid animInfo(bool& onlyOnce, bool& stopOnRelease) const;
173 
174  // Perform keydown action (if any)
175  void keyEvent(KbBind* bind, bool down);
176  // Perform keyup action (if any)
177  void keyRelease(KbBind* bind);
178  // Adjusts the DISPLAY variable to the mouse's screen. Needed to ensure that programs launch on the correct screen in multihead.
179  void adjustDisplay();
180 
181 
182  ~KeyAction();
183 private:
186  inline void operator=(const KeyAction& rhs) {}
187  inline KeyAction(const KeyAction& rhs) : QObject() {}
188 
189  QString _value;
190 
191  // Currently-running programs
192  QProcess* preProgram;
193  QProcess* relProgram;
194 
195  // Mouse sniper mode (0 = inactive)
196  quint64 sniperValue;
197 };
198 
199 #endif // KEYACTION_H
static QString noAction()
Definition: keyaction.h:25
bool isProgram() const
Definition: keyaction.h:158
QProcess * preProgram
Definition: keyaction.h:192
static const int DPI_CYCLE_DOWN
Definition: keyaction.h:126
static const int DPI_UP
Definition: keyaction.h:127
bool isMacro() const
Definition: keyaction.h:160
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:184
bool isMouse() const
Definition: keyaction.h:163
static QString macroAction(QString macroDef)
well documented in cpp file
Definition: keyaction.cpp:523
static const int DPI_CUSTOM
Definition: keyaction.h:128
static const int PROGRAM_PR_MULTI
Definition: keyaction.h:138
static const int PROGRAM_RE_MULTI
Definition: keyaction.h:139
static QString dpiAction(int level, int customX=0, int customY=0)
Definition: keyaction.cpp:162
QString value() const
Definition: keyaction.h:19
QString specialInfo(int &parameter) const
Definition: keyaction.cpp:189
bool isValidMacro() const
isValidMacro checks whether a keyAction contains a valid macro. This is done easily: If the macro act...
Definition: keyaction.h:55
struct parameter contains the values for a fresh started macro_play thread. parameter_t is the typede...
Definition: input.h:54
static const int MODE_PREV
Definition: keyaction.h:122
static QString programAction(const QString &onPress, const QString &onRelease, int stop)
Definition: keyaction.cpp:177
static const int PROGRAM_PR_KPSTOP
Definition: keyaction.h:138
bool isDPI() const
Definition: keyaction.h:162
QUuid animInfo(bool &onlyOnce, bool &stopOnRelease) const
Definition: keyaction.cpp:225
QStringList macroLine() const
macroLine returns all interresting content for a macro definition.
Definition: keyaction.h:73
Definition: keymap.h:49
static const int PROGRAM_RE_INDEF
Definition: keyaction.h:139
static const int PROGRAM_PR_INDEF
Definition: keyaction.h:138
KeyAction(const QString &action, QObject *parent=0)
Definition: keyaction.cpp:22
quint64 sniperValue
Definition: keyaction.h:196
static const int DPI_SNIPER
Definition: keyaction.h:128
bool isUnbound() const
Definition: keyaction.h:152
static const int PROGRAM_RE_KPSTOP
Definition: keyaction.h:139
static QString lockAction(int type=LOCK_TOGGLE)
Definition: keyaction.cpp:173
static const int MODE_PREV_WRAP
Definition: keyaction.h:123
void adjustDisplay()
Definition: keyaction.cpp:464
static const int LOCK_ON
Definition: keyaction.h:135
void keyRelease(KbBind *bind)
bool isMedia() const
Definition: keyaction.h:156
QString _value
Definition: keyaction.h:189
bool isNormal() const
Definition: keyaction.h:153
static const int LOCK_TOGGLE
Definition: keyaction.h:135
Definition: kbanim.h:11
static QString modeAction(int mode)
Definition: keyaction.cpp:158
Definition: kbbind.h:20
static const int LIGHT_DOWN
Definition: keyaction.h:131
static const int DPI_CYCLE_UP
Definition: keyaction.h:126
static const int LOCK_OFF
Definition: keyaction.h:135
int dpiInfo(QPoint &custom) const
Definition: keyaction.cpp:211
Model
Definition: keymap.h:51
static const int PROGRAM_PR_KRSTOP
Definition: keyaction.h:138
static QString lightAction(int type=LIGHT_UP_WRAP)
Definition: keyaction.cpp:169
QString driverName() const
Definition: keyaction.cpp:239
static const int MODE_NEXT_WRAP
Definition: keyaction.h:123
bool isAnim() const
Definition: keyaction.h:159
Definition: keymap.h:49
void macroDisplay()
Debug output for invalid macro Definitions.
Definition: keyaction.cpp:456
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:186
int programInfo(QString &onPress, QString &onRelease) const
Definition: keyaction.cpp:199
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:84
static const int LIGHT_DOWN_WRAP
Definition: keyaction.h:132
static const int DPI_DOWN
Definition: keyaction.h:127
QProcess * relProgram
Definition: keyaction.h:193
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:132
KeyAction(const KeyAction &rhs)
Definition: keyaction.h:187
static QString defaultAction(const QString &key, KeyMap::Model model)
Definition: keyaction.cpp:44
bool isSpecial() const
Definition: keyaction.h:154
void keyEvent(KbBind *bind, bool down)
Definition: keyaction.cpp:245
static const int LIGHT_UP
Definition: keyaction.h:131