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
kbbind.h
Go to the documentation of this file.
1 #ifndef KBBIND_H
2 #define KBBIND_H
3 
4 #include <QFile>
5 #include <QHash>
6 #include <QObject>
7 #include <QProcess>
8 #include "ckbsettings.h"
9 #include "keymap.h"
10 #include "keyaction.h"
11 
12 class Kb;
13 class KbMode;
14 class KbPerf;
15 class KbLight;
16 
17 // Binding setup for a device mode
18 // See also KeyAction, a class for managing binding actions
19 
20 class KbBind : public QObject
21 {
22  Q_OBJECT
23 public:
24  // New binding setup
25  explicit KbBind(KbMode* modeParent, Kb* devParent, const KeyMap& keyMap);
33  KbBind(KbMode* modeParent, Kb* devParent, const KeyMap& keyMap, const KbBind& other);
34 
35  // Load and save from stored settings
36  void load(CkbSettings& settings);
37  void save(CkbSettings& settings);
38  inline bool needsSave() const { return _needsSave; }
39 
40  // Key map
41  inline const KeyMap& map() { return _map; }
42  void map(const KeyMap& map);
43  inline bool isISO() const { return _map.isISO(); }
44  inline bool isKeyboard() const { return _map.isKeyboard(); }
45  inline bool isMouse() const { return _map.isMouse(); }
46  // Related objects
47  KbPerf* perf();
48  KbLight* light();
49 
50  // Global key remap (changes modifiers per Settings widget)
51  // Use only when iterating the map manually; all KbBind functions already take this into account
52  static QString globalRemap(const QString& key);
53  static void setGlobalRemap(const QHash<QString, QString> keyToActual);
54  static void loadGlobalRemap();
55  static void saveGlobalRemap();
56 
57  // Action for a given key. Use KeyAction(action) to get info about it.
58  QString action(const QString& key);
59  // Default action for a key.
60  QString defaultAction(const QString& key);
61  static QString defaultAction(const QString& key, KeyMap::Model model);
62 
63  // Friendly name for a key, taking into account the global key remap
64  QString friendlyName(const QString& key);
65  // Friendly name for the action associated with a key
66  QString friendlyActionName(const QString& key);
67 
68  // Changes a key's action
69  void setAction(const QString& key, const QString& action);
70  inline void setAction(const QStringList& keys, const QString& action) { foreach(const QString& key, keys) setAction(key, action); }
71  // Resets a key to the default action.
72  void resetAction(const QString &key);
73  inline void resetAction(const QStringList& keys) { foreach(const QString& key, keys) resetAction(key); }
74  // Unbinds a key.
75  void noAction(const QString& key);
76  inline void noAction(const QStringList& keys) { foreach(const QString& key, keys) noAction(key); }
77 
78  // Current win lock state
79  inline bool winLock() { return _winLock; }
80  void winLock(bool newWinLock) { _winLock = newWinLock; _needsUpdate = true; }
81 
82  // Updates bindings to the driver. Write "mode %d" first.
83  // By default, nothing will be written unless bindings have changed. Use force = true or call setNeedsUpdate() to override.
84  void update(QFile& cmd, bool force = false);
85  inline void setNeedsUpdate() { _needsUpdate = true; }
86 
90  int getMacroNumber();
91 
95  QString getMacroPath();
96 
102  void handleNotificationChannel(bool start);
103 
104 public slots:
105  // Callback for a keypress event.
106  void keyEvent(const QString& key, bool down);
107 
108 signals:
109  void didLoad();
110  void layoutChanged();
111  void updated();
112 
113 private:
115  inline Kb* devParent() const { return _devParent; }
116  inline KbMode* modeParent() const { return (KbMode*)parent(); }
117 
118  KeyAction* bindAction(const QString& key);
119 
120  static QHash<QString, QString> _globalRemap;
121  static quint64 globalRemapTime;
123 
128  QFile* lastCmd;
129 
131  // Key -> action map (no entry = default action)
132  QHash<QString, KeyAction*> _bind;
133 
134  bool _winLock;
137  friend class KeyAction;
138 };
139 
140 #endif // KBBIND_H
void load(CkbSettings &settings)
Definition: kbbind.cpp:58
bool isMouse() const
Definition: kbbind.h:45
bool needsSave() const
Definition: kbbind.h:38
void setAction(const QStringList &keys, const QString &action)
Definition: kbbind.h:70
KbBind(KbMode *modeParent, Kb *devParent, const KeyMap &keyMap)
Definition: kbbind.cpp:12
bool _winLock
Definition: kbbind.h:134
static bool isMouse(Model model)
Definition: keymap.h:111
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
cmd
Definition: command.h:7
KbPerf * perf()
Definition: kbbind.cpp:50
Kb * devParent() const
Definition: kbbind.h:115
static void setGlobalRemap(const QHash< QString, QString > keyToActual)
Definition: kbbind.cpp:104
const KeyMap & map()
Definition: kbbind.h:41
void didLoad()
Definition: moc_kbbind.cpp:155
KeyMap _map
Definition: kbbind.h:130
bool _needsSave
Definition: kbbind.h:136
Definition: keymap.h:49
QString friendlyActionName(const QString &key)
Definition: kbbind.cpp:166
static bool isKeyboard(Model model)
Definition: keymap.h:109
QString friendlyName(const QString &key)
Definition: kbbind.cpp:159
void resetAction(const QString &key)
Definition: kbbind.cpp:171
KbLight * light()
Definition: kbbind.cpp:54
void resetAction(const QStringList &keys)
Definition: kbbind.h:73
void winLock(bool newWinLock)
Definition: kbbind.h:80
Definition: kbmode.h:36
QString action(const QString &key)
Definition: kbbind.cpp:145
void save(CkbSettings &settings)
Definition: kbbind.cpp:81
bool isKeyboard() const
Definition: kbbind.h:44
Definition: kbperf.h:15
static bool isISO(Layout layout)
Definition: keymap.h:94
Definition: kb.h:11
QString defaultAction(const QString &key)
Definition: kbbind.cpp:155
Definition: kbbind.h:20
bool winLock()
Definition: kbbind.h:79
void update(QFile &cmd, bool force=false)
Definition: kbbind.cpp:197
void keyEvent(const QString &key, bool down)
Definition: kbbind.cpp:296
Model
Definition: keymap.h:51
QString getMacroPath()
KbBind::getMacroPath.
Definition: kbbind.cpp:274
void setNeedsUpdate()
Definition: kbbind.h:85
void handleNotificationChannel(bool start)
handleNotificationChannel sends commands to ckb-daemon for (de-) activating the notify channel...
Definition: kbbind.cpp:284
static QHash< QString, QString > _globalRemap
Definition: kbbind.h:120
void noAction(const QString &key)
Definition: kbbind.cpp:181
Definition: keymap.h:49
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:132
static void saveGlobalRemap()
Definition: kbbind.cpp:124
void noAction(const QStringList &keys)
Definition: kbbind.h:76
bool isISO() const
Definition: kbbind.h:43
quint64 lastGlobalRemapTime
Definition: kbbind.h:122
QFile * lastCmd
lastCmd is a cache-hack. Because the QFile ist opened in Kb, and we need it in the macro processing f...
Definition: kbbind.h:128
void setAction(const QString &key, const QString &action)
Definition: kbbind.cpp:189
static quint64 globalRemapTime
Definition: kbbind.h:121
int getMacroNumber()
KbBind::getMacroNumber.
Definition: kbbind.cpp:266
void updated()
Definition: moc_kbbind.cpp:167
Kb * _devParent
Definition: kbbind.h:114
bool _needsUpdate
Definition: kbbind.h:135
void layoutChanged()
Definition: moc_kbbind.cpp:161
KbMode * modeParent() const
Definition: kbbind.h:116
KeyAction * bindAction(const QString &key)
Definition: kbbind.cpp:140
static void loadGlobalRemap()
Definition: kbbind.cpp:116