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
KbBind Class Reference

#include <src/ckb/kbbind.h>

+ Inheritance diagram for KbBind:
+ Collaboration diagram for KbBind:

Public Slots

void keyEvent (const QString &key, bool down)
 

Signals

void didLoad ()
 
void layoutChanged ()
 
void updated ()
 

Public Member Functions

 KbBind (KbMode *modeParent, Kb *devParent, const KeyMap &keyMap)
 
 KbBind (KbMode *modeParent, Kb *devParent, const KeyMap &keyMap, const KbBind &other)
 KbBind. More...
 
void load (CkbSettings &settings)
 
void save (CkbSettings &settings)
 
bool needsSave () const
 
const KeyMapmap ()
 
void map (const KeyMap &map)
 
bool isISO () const
 
bool isKeyboard () const
 
bool isMouse () const
 
KbPerfperf ()
 
KbLightlight ()
 
QString action (const QString &key)
 
QString friendlyName (const QString &key)
 
QString friendlyActionName (const QString &key)
 
void setAction (const QString &key, const QString &action)
 
void setAction (const QStringList &keys, const QString &action)
 
void resetAction (const QString &key)
 
void resetAction (const QStringList &keys)
 
void noAction (const QString &key)
 
void noAction (const QStringList &keys)
 
bool winLock ()
 
void winLock (bool newWinLock)
 
void update (QFile &cmd, bool force=false)
 
void setNeedsUpdate ()
 
int getMacroNumber ()
 KbBind::getMacroNumber. More...
 
QString getMacroPath ()
 KbBind::getMacroPath. More...
 
void handleNotificationChannel (bool start)
 handleNotificationChannel sends commands to ckb-daemon for (de-) activating the notify channel. Send a notify cmd to the keyboard to set or clear notification for reading macro definition. The file handle for the cmd pipe is stored in lastCmd. More...
 

Static Public Member Functions

static QString globalRemap (const QString &key)
 
static void setGlobalRemap (const QHash< QString, QString > keyToActual)
 
static void loadGlobalRemap ()
 
static void saveGlobalRemap ()
 
static QString defaultAction (const QString &key)
 

Private Member Functions

KbdevParent () const
 
KbModemodeParent () const
 
KeyActionbindAction (const QString &key)
 

Private Attributes

Kb_devParent
 
quint64 lastGlobalRemapTime
 
QFile * lastCmd
 lastCmd is a cache-hack. Because the QFile ist opened in Kb, and we need it in the macro processing functions, we cache the value her in lastCmd. More...
 
KeyMap _map
 
QHash< QString, KeyAction * > _bind
 
bool _winLock
 
bool _needsUpdate
 
bool _needsSave
 

Static Private Attributes

static QHash< QString, QString > _globalRemap
 
static quint64 globalRemapTime = 0
 

Friends

class KeyAction
 

Detailed Description

Definition at line 20 of file kbbind.h.

Constructor & Destructor Documentation

KbBind::KbBind ( KbMode modeParent,
Kb devParent,
const KeyMap keyMap 
)
explicit

Definition at line 12 of file kbbind.cpp.

12  :
13  QObject(modeParent), _devParent(parentBoard), lastGlobalRemapTime(globalRemapTime), _map(keyMap),
14  _winLock(false), _needsUpdate(true), _needsSave(true) {
15 }
bool _winLock
Definition: kbbind.h:133
KeyMap _map
Definition: kbbind.h:129
bool _needsSave
Definition: kbbind.h:135
quint64 lastGlobalRemapTime
Definition: kbbind.h:121
static quint64 globalRemapTime
Definition: kbbind.h:120
Kb * _devParent
Definition: kbbind.h:113
bool _needsUpdate
Definition: kbbind.h:134
KbBind::KbBind ( KbMode modeParent,
Kb parentBoard,
const KeyMap keyMap,
const KbBind other 
)

KbBind::KbBind // copy all existing Key bindings.

Parameters
modeParent
devParent
keyMap
otherThis is the KbBind object to copy from Use this constructor to copy an existing Binding
modeParent
parentBoard
keyMap
other

Create a new Hash table and copy all entries

clear the destination list (there are the original KeyActions as references, so do not delete them)

and move the KeyActions we just created

Definition at line 24 of file kbbind.cpp.

References _bind, KeyAction, map(), and KeyAction::value().

24  :
25  QObject(modeParent), _devParent(parentBoard), lastGlobalRemapTime(globalRemapTime), _bind(other._bind),
26  _winLock(false), _needsUpdate(true), _needsSave(true) {
27  map(keyMap);
28 
30  QHash<QString, KeyAction*> newBind;
31  foreach(QString key, _bind.keys()) {
32  KeyAction* act = _bind.value(key);
33  if(act) {
34  newBind[key] = new KeyAction(act->value(), this);
35  }
36  }
37 
39  _bind.clear();
40  foreach(QString key, newBind.keys()) {
41  KeyAction* act = newBind.value(key);
42  if(act) {
44  _bind[key] = new KeyAction(act->value(), this);
45  }
46  }
47  newBind.clear(); // here we *must not* delete the KeyActions, because they are referenced by _bind now
48 }
bool _winLock
Definition: kbbind.h:133
QString value() const
Definition: keyaction.h:19
const KeyMap & map()
Definition: kbbind.h:41
bool _needsSave
Definition: kbbind.h:135
friend class KeyAction
Definition: kbbind.h:136
Definition: keymap.h:49
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:131
quint64 lastGlobalRemapTime
Definition: kbbind.h:121
static quint64 globalRemapTime
Definition: kbbind.h:120
Kb * _devParent
Definition: kbbind.h:113
bool _needsUpdate
Definition: kbbind.h:134

+ Here is the call graph for this function:

Member Function Documentation

QString KbBind::action ( const QString &  key)

Definition at line 140 of file kbbind.cpp.

References bindAction(), globalRemap(), and KeyAction::value().

Referenced by friendlyActionName(), KbBindWidget::on_copyButton_clicked(), resetAction(), RebindWidget::setSelection(), and KbBindWidget::updateBind().

140  {
141  QString rKey = globalRemap(key);
142  return bindAction(rKey)->value();
143 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
QString value() const
Definition: keyaction.h:19
Definition: keymap.h:49
KeyAction * bindAction(const QString &key)
Definition: kbbind.h:117

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

KeyAction* KbBind::bindAction ( const QString &  key)
inlineprivate

Definition at line 117 of file kbbind.h.

References _bind, KeyAction::defaultAction(), and KeyAction.

Referenced by action(), keyEvent(), and update().

117 { if(!_bind.contains(key)) return _bind[key] = new KeyAction(KeyAction::defaultAction(key), this); return _bind[key]; }
friend class KeyAction
Definition: kbbind.h:136
Definition: keymap.h:49
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:131
static QString defaultAction(const QString &key)
Definition: keyaction.cpp:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString KbBind::defaultAction ( const QString &  key)
static

Definition at line 145 of file kbbind.cpp.

References KeyAction::defaultAction(), and globalRemap().

Referenced by KeyWidget::paintEvent(), and RebindWidget::setBind().

145  {
146  QString rKey = globalRemap(key);
147  return KeyAction::defaultAction(rKey);
148 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
Definition: keymap.h:49
static QString defaultAction(const QString &key)
Definition: keyaction.cpp:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Kb* KbBind::devParent ( ) const
inlineprivate

Definition at line 114 of file kbbind.h.

References _devParent.

Referenced by getMacroNumber(), getMacroPath(), and KeyAction::keyEvent().

114 { return _devParent; }
Kb * _devParent
Definition: kbbind.h:113

+ Here is the caller graph for this function:

void KbBind::didLoad ( )
signal

Definition at line 155 of file moc_kbbind.cpp.

Referenced by load().

156 {
157  QMetaObject::activate(this, &staticMetaObject, 0, Q_NULLPTR);
158 }

+ Here is the caller graph for this function:

QString KbBind::friendlyActionName ( const QString &  key)

Definition at line 157 of file kbbind.cpp.

References _map, action(), and KeyAction.

Referenced by KbBindWidget::updateSelDisplay().

157  {
158  QString act = action(key);
159  return KeyAction(act).friendlyName(_map);
160 }
KeyMap _map
Definition: kbbind.h:129
friend class KeyAction
Definition: kbbind.h:136
Definition: keymap.h:49
QString action(const QString &key)
Definition: kbbind.cpp:140

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString KbBind::friendlyName ( const QString &  key)

Definition at line 150 of file kbbind.cpp.

References _map, Key::friendlyName(), and globalRemap().

150  {
151  const Key& pos = _map[globalRemap(key)];
152  if(!pos)
153  return "(Unknown)";
154  return pos.friendlyName();
155 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
QString friendlyName(bool os=true) const
Definition: keymap.h:23
KeyMap _map
Definition: kbbind.h:129
Definition: keymap.h:49
Definition: keymap.h:8

+ Here is the call graph for this function:

int KbBind::getMacroNumber ( )
Returns
number of notification channel. Use it in combination with notifyon/off-Statement

Definition at line 257 of file kbbind.cpp.

References devParent(), and Kb::getMacroNumber().

Referenced by handleNotificationChannel(), and RebindWidget::on_btnStartMacro_clicked().

257  {
258  return devParent()->getMacroNumber();
259 }
Kb * devParent() const
Definition: kbbind.h:114
int getMacroNumber()
For usage with macro definions, these two params must only be readable. So there are no setters...
Definition: kb.h:97

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString KbBind::getMacroPath ( )
Returns
Filepath of macro notification pipe. If not set, returns initial value ""

Definition at line 265 of file kbbind.cpp.

References devParent(), and Kb::getMacroPath().

Referenced by RebindWidget::on_btnStartMacro_clicked().

265  {
266  return devParent()->getMacroPath();
267 }
QString getMacroPath()
getMacroPath returns the macroPath (e.g. /dev/input/ckb1/notify), which we have saved in the construc...
Definition: kb.h:106
Kb * devParent() const
Definition: kbbind.h:114

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString KbBind::globalRemap ( const QString &  key)
static

Definition at line 98 of file kbbind.cpp.

References _globalRemap.

Referenced by action(), defaultAction(), friendlyName(), keyEvent(), noAction(), KeyWidget::paintEvent(), resetAction(), setAction(), and SettingsWidget::SettingsWidget().

98  {
99  if(!_globalRemap.contains(key))
100  return key;
101  return _globalRemap.value(key);
102 }
Definition: keymap.h:49
static QHash< QString, QString > _globalRemap
Definition: kbbind.h:119

+ Here is the caller graph for this function:

void KbBind::handleNotificationChannel ( bool  start)
Parameters
startis boolean. If true, notification channel is opened for all keys, otherwise channel ist closed.
startIf true, notification channel is opened for all keys, otherwise channel ist closed.

Definition at line 275 of file kbbind.cpp.

References getMacroNumber(), and lastCmd.

Referenced by RebindWidget::on_btnStartMacro_clicked(), and RebindWidget::on_btnStopMacro_clicked().

275  {
276  if (getMacroNumber() > 0 && lastCmd) {
277  if (start) {
278  lastCmd->write (QString("\nnotifyon %1\n@%1 notify all:on\n").arg(getMacroNumber()).toLatin1());
279  } else {
280  lastCmd->write (QString("\n@%1 notify all:off\nnotifyoff %1\n").arg(getMacroNumber()).toLatin1());
281  }
282  lastCmd->flush();
283  } else qDebug() << QString("No cmd or valid handle for notification found, macroNumber = %1, lastCmd = %2")
284  .arg(getMacroNumber()).arg(lastCmd? "set" : "unset");
285 }
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:127
int getMacroNumber()
KbBind::getMacroNumber.
Definition: kbbind.cpp:257

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool KbBind::isISO ( ) const
inline

Definition at line 43 of file kbbind.h.

References _map, and KeyMap::isISO().

43 { return _map.isISO(); }
KeyMap _map
Definition: kbbind.h:129
static bool isISO(Layout layout)
Definition: keymap.h:87

+ Here is the call graph for this function:

bool KbBind::isKeyboard ( ) const
inline

Definition at line 44 of file kbbind.h.

References _map, and KeyMap::isKeyboard().

44 { return _map.isKeyboard(); }
KeyMap _map
Definition: kbbind.h:129
static bool isKeyboard(Model model)
Definition: keymap.h:93

+ Here is the call graph for this function:

bool KbBind::isMouse ( ) const
inline

Definition at line 45 of file kbbind.h.

References _map, and KeyMap::isMouse().

Referenced by KbBindWidget::on_copyButton_clicked(), KbBindWidget::on_resetButton_clicked(), RebindWidget::setBind(), and KbBindWidget::updateSelDisplay().

45 { return _map.isMouse(); }
static bool isMouse(Model model)
Definition: keymap.h:95
KeyMap _map
Definition: kbbind.h:129

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::keyEvent ( const QString &  key,
bool  down 
)
slot

Definition at line 287 of file kbbind.cpp.

References bindAction(), globalRemap(), and KeyAction::keyEvent().

Referenced by Kb::readNotify().

287  {
288  QString rKey = globalRemap(key);
289  KeyAction* act = bindAction(rKey);
290  if(act)
291  act->keyEvent(this, down);
292 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
Definition: keymap.h:49
void keyEvent(KbBind *bind, bool down)
Definition: keyaction.cpp:236
KeyAction * bindAction(const QString &key)
Definition: kbbind.h:117

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::layoutChanged ( )
signal

Definition at line 161 of file moc_kbbind.cpp.

Referenced by map().

162 {
163  QMetaObject::activate(this, &staticMetaObject, 1, Q_NULLPTR);
164 }

+ Here is the caller graph for this function:

KbLight * KbBind::light ( )

Definition at line 54 of file kbbind.cpp.

References KbMode::light(), and modeParent().

Referenced by RebindWidget::applyChanges(), KeyAction::keyEvent(), and RebindWidget::setSelection().

54  {
55  return modeParent()->light();
56 }
KbLight * light()
Definition: kbmode.h:60
KbMode * modeParent() const
Definition: kbbind.h:115

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::load ( CkbSettings settings)

Definition at line 58 of file kbbind.cpp.

References _bind, _map, _needsSave, _winLock, CkbSettings::childKeys(), didLoad(), KeyMap::fromName(), KeyMap::fromStorage(), KeyAction, map(), and CkbSettings::value().

Referenced by KbMode::KbMode().

58  {
59  _needsSave = false;
60  SGroup group(settings, "Binding");
61  KeyMap currentMap = _map;
62  _map = KeyMap::fromName(settings.value("KeyMap").toString());
63  // Load key settings
64  bool useReal = settings.value("UseRealNames").toBool();
65  _bind.clear();
66  {
67  SGroup group(settings, "Keys");
68  foreach(QString key, settings.childKeys()){
69  QString name = key.toLower();
70  if(!useReal)
71  name = _map.fromStorage(name);
72  QString bind = settings.value(key).toString();
73  _bind[name] = new KeyAction(bind, this);
74  }
75  }
76  _winLock = settings.value("WinLock").toBool();
77  emit didLoad();
78  map(currentMap);
79 }
QStringList childKeys() const
bool _winLock
Definition: kbbind.h:133
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
const KeyMap & map()
Definition: kbbind.h:41
void didLoad()
Definition: moc_kbbind.cpp:155
KeyMap _map
Definition: kbbind.h:129
bool _needsSave
Definition: kbbind.h:135
friend class KeyAction
Definition: kbbind.h:136
QString fromStorage(const QString &storage)
Definition: keymap.h:135
Definition: keymap.h:49
Definition: keymap.h:49
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:131
static KeyMap fromName(const QString &name)
Definition: keymap.cpp:535

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::loadGlobalRemap ( )
static

Definition at line 116 of file kbbind.cpp.

References _globalRemap, CkbSettings::childKeys(), globalRemapTime, and CkbSettings::value().

Referenced by SettingsWidget::SettingsWidget().

116  {
117  _globalRemap.clear();
118  CkbSettings settings("Program/GlobalRemap");
119  foreach(const QString& key, settings.childKeys())
120  _globalRemap[key] = settings.value(key).toString();
121  globalRemapTime = QDateTime::currentMSecsSinceEpoch();
122 }
Definition: keymap.h:49
static QHash< QString, QString > _globalRemap
Definition: kbbind.h:119
static quint64 globalRemapTime
Definition: kbbind.h:120

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const KeyMap& KbBind::map ( )
inline
void KbBind::map ( const KeyMap map)

Definition at line 133 of file kbbind.cpp.

References _map, _needsSave, _needsUpdate, layoutChanged(), and map().

133  {
134  _map = map;
135  _needsUpdate = true;
136  _needsSave = true;
137  emit layoutChanged();
138 }
const KeyMap & map()
Definition: kbbind.h:41
KeyMap _map
Definition: kbbind.h:129
bool _needsSave
Definition: kbbind.h:135
bool _needsUpdate
Definition: kbbind.h:134
void layoutChanged()
Definition: moc_kbbind.cpp:161

+ Here is the call graph for this function:

KbMode* KbBind::modeParent ( ) const
inlineprivate

Definition at line 115 of file kbbind.h.

Referenced by light(), and perf().

115 { return (KbMode*)parent(); }
Definition: kbmode.h:36

+ Here is the caller graph for this function:

bool KbBind::needsSave ( ) const
inline

Definition at line 38 of file kbbind.h.

References _needsSave.

Referenced by KbMode::needsSave().

38 { return _needsSave; }
bool _needsSave
Definition: kbbind.h:135

+ Here is the caller graph for this function:

void KbBind::noAction ( const QString &  key)

Definition at line 172 of file kbbind.cpp.

References _bind, _map, globalRemap(), KeyMap::key(), KeyAction, and resetAction().

Referenced by RebindWidget::applyChanges(), and RebindWidget::on_unbindButton_clicked().

172  {
173  resetAction(key);
174  QString rKey = globalRemap(key);
175  if(!_map.key(rKey))
176  return;
177  _bind[rKey] = new KeyAction(this);
178 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
KeyMap _map
Definition: kbbind.h:129
Key key(const QString &name) const
Definition: keymap.h:125
friend class KeyAction
Definition: kbbind.h:136
Definition: keymap.h:49
void resetAction(const QString &key)
Definition: kbbind.cpp:162
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:131

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::noAction ( const QStringList &  keys)
inline

Definition at line 75 of file kbbind.h.

References noAction().

Referenced by noAction().

75 { foreach(const QString& key, keys) noAction(key); }
Definition: keymap.h:49
void noAction(const QString &key)
Definition: kbbind.cpp:172

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

KbPerf * KbBind::perf ( )

Definition at line 50 of file kbbind.cpp.

References modeParent(), and KbMode::perf().

Referenced by KeyAction::keyEvent(), and RebindWidget::setBind().

50  {
51  return modeParent()->perf();
52 }
KbMode * modeParent() const
Definition: kbbind.h:115
KbPerf * perf()
Definition: kbmode.h:62

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::resetAction ( const QString &  key)

Definition at line 162 of file kbbind.cpp.

References _bind, _needsSave, _needsUpdate, action(), and globalRemap().

Referenced by noAction(), KbBindWidget::on_resetButton_clicked(), RebindWidget::on_resetButton_clicked(), and setAction().

162  {
163  QString rKey = globalRemap(key);
164  // Clean up existing action (if any)
165  KeyAction* action = _bind.value(rKey);
166  delete action;
167  _bind.remove(rKey);
168  _needsUpdate = true;
169  _needsSave = true;
170 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
bool _needsSave
Definition: kbbind.h:135
Definition: keymap.h:49
QString action(const QString &key)
Definition: kbbind.cpp:140
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:131
bool _needsUpdate
Definition: kbbind.h:134

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::resetAction ( const QStringList &  keys)
inline

Definition at line 72 of file kbbind.h.

References resetAction().

Referenced by resetAction().

72 { foreach(const QString& key, keys) resetAction(key); }
Definition: keymap.h:49
void resetAction(const QString &key)
Definition: kbbind.cpp:162

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::save ( CkbSettings settings)

Definition at line 81 of file kbbind.cpp.

References _bind, _map, _needsSave, _winLock, KeyAction::defaultAction(), KeyMap::name(), CkbSettings::setValue(), and KeyAction::value().

Referenced by KbMode::save().

81  {
82  _needsSave = false;
83  SGroup group(settings, "Binding");
84  settings.setValue("KeyMap", _map.name());
85  // Save key settings
86  settings.setValue("UseRealNames", true);
87  {
88  SGroup group(settings, "Keys");
89  foreach(QString key, _bind.keys()){
90  KeyAction* act = _bind.value(key);
91  if(act && act->value() != KeyAction::defaultAction(key))
92  settings.setValue(key, act->value());
93  }
94  }
95  settings.setValue("WinLock", _winLock);
96 }
void setValue(const QString &key, const QVariant &value)
bool _winLock
Definition: kbbind.h:133
QString value() const
Definition: keyaction.h:19
KeyMap _map
Definition: kbbind.h:129
bool _needsSave
Definition: kbbind.h:135
Definition: keymap.h:49
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:131
QString name() const
Definition: keymap.h:115
static QString defaultAction(const QString &key)
Definition: keyaction.cpp:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::saveGlobalRemap ( )
static

Definition at line 124 of file kbbind.cpp.

References _globalRemap, and CkbSettings::setValue().

Referenced by SettingsWidget::updateModifiers().

124  {
125  CkbSettings settings("Program/GlobalRemap", true);
126  QHashIterator<QString, QString> i(_globalRemap);
127  while(i.hasNext()){
128  i.next();
129  settings.setValue(i.key(), i.value());
130  }
131 }
static QHash< QString, QString > _globalRemap
Definition: kbbind.h:119

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::setAction ( const QString &  key,
const QString &  action 
)

Definition at line 180 of file kbbind.cpp.

References _bind, _map, globalRemap(), KeyMap::key(), KeyAction, and resetAction().

Referenced by RebindWidget::applyChanges(), and KbBindWidget::on_copyButton_clicked().

180  {
181  resetAction(key);
182  QString rKey = globalRemap(key);
183  if(!_map.key(rKey))
184  return;
185  _bind[rKey] = new KeyAction(action, this);
186 }
static QString globalRemap(const QString &key)
Definition: kbbind.cpp:98
KeyMap _map
Definition: kbbind.h:129
Key key(const QString &name) const
Definition: keymap.h:125
friend class KeyAction
Definition: kbbind.h:136
Definition: keymap.h:49
void resetAction(const QString &key)
Definition: kbbind.cpp:162
QString action(const QString &key)
Definition: kbbind.cpp:140
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:131

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::setAction ( const QStringList &  keys,
const QString &  action 
)
inline

Definition at line 69 of file kbbind.h.

References setAction().

Referenced by setAction().

69 { foreach(const QString& key, keys) setAction(key, action); }
Definition: keymap.h:49
QString action(const QString &key)
Definition: kbbind.cpp:140
void setAction(const QString &key, const QString &action)
Definition: kbbind.cpp:180

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::setGlobalRemap ( const QHash< QString, QString >  keyToActual)
static

Definition at line 104 of file kbbind.cpp.

References _globalRemap, and globalRemapTime.

Referenced by SettingsWidget::updateModifiers().

104  {
105  _globalRemap.clear();
106  // Ignore any keys with the standard binding
107  QHashIterator<QString, QString> i(keyToActual);
108  while(i.hasNext()){
109  i.next();
110  if(i.key() != i.value())
111  _globalRemap[i.key()] = i.value();
112  }
113  globalRemapTime = QDateTime::currentMSecsSinceEpoch();
114 }
static QHash< QString, QString > _globalRemap
Definition: kbbind.h:119
static quint64 globalRemapTime
Definition: kbbind.h:120

+ Here is the caller graph for this function:

void KbBind::setNeedsUpdate ( )
inline

Definition at line 84 of file kbbind.h.

References _needsUpdate.

Referenced by KbMode::setNeedsUpdate().

84 { _needsUpdate = true; }
bool _needsUpdate
Definition: kbbind.h:134

+ Here is the caller graph for this function:

void KbBind::update ( QFile &  cmd,
bool  force = false 
)

Definition at line 188 of file kbbind.cpp.

References _bind, _globalRemap, _needsUpdate, _winLock, bindAction(), KeyAction::driverName(), globalRemapTime, KeyAction::isValidMacro(), lastCmd, lastGlobalRemapTime, KeyAction::macroContent(), updated(), and KeyAction::value().

Referenced by Kb::frameUpdate().

188  {
190  return;
192  emit updated();
193  _needsUpdate = false;
194  // Reset all keys and enable notifications for all
195  cmd.write("rebind all notify all");
196  // Make sure modifier keys are included as they may be remapped globally
197  QHash<QString, KeyAction*> bind(_bind);
198  if(!_bind.contains("caps")) bind["caps"] = 0;
199  if(!_bind.contains("lshift")) bind["lshift"] = 0;
200  if(!_bind.contains("rshift")) bind["rshift"] = 0;
201  if(!_bind.contains("lctrl")) bind["lctrl"] = 0;
202  if(!_bind.contains("rctrl")) bind["rctrl"] = 0;
203  if(!_bind.contains("lwin")) bind["lwin"] = 0;
204  if(!_bind.contains("rwin")) bind["rwin"] = 0;
205  if(!_bind.contains("lalt")) bind["lalt"] = 0;
206  if(!_bind.contains("ralt")) bind["ralt"] = 0;
207  if(!_bind.contains("fn")) bind["fn"] = 0;
208  QHashIterator<QString, KeyAction*> i(bind);
209 
210  // Initialize String buffer for macro Key definitions (G-keys)
211  // "macro clear" is neccessary, if an older definition is unbound.
212  QString macros = "\nmacro clear\n";
213 
214  // Write out rebound keys and collect infos for macro definitions
215  while(i.hasNext()){
216  i.next();
217  QString key = i.key();
218  KeyAction* act = i.value();
219  if(_globalRemap.contains(key))
220  act = bindAction(_globalRemap.value(key));
221  if(!act)
222  continue;
223  QString value = act->driverName();
224  if(value.isEmpty()){
225  // If the key is unbound or is a special action, unbind it
226  cmd.write(" unbind ");
227  cmd.write(key.toLatin1());
228  // if a macro definiton for the key is given,
229  // add the converted string to key-buffer "macro"
230  if (act->isValidMacro()) {
231  if (act->macroContent().length() > 0) {
232  macros.append("macro " + key.toLatin1() + ":" + act->macroContent().toLatin1() + "\n");
233  }
234  }
235  } else {
236  // Otherwise, write the binding
237  cmd.write(" bind ");
238  cmd.write(key.toLatin1());
239  cmd.write(":");
240  cmd.write(value.toLatin1());
241  }
242  }
243  // If win lock is enabled, unbind windows keys
244  if(_winLock)
245  cmd.write(" unbind lwin rwin");
246 
247  // At last, send Macro definitions if available.
248  // If no definitions are made, clear macro will be sent only to reset all macros,
249  cmd.write(macros.toLatin1());
250  lastCmd = &cmd;
251 }
bool _winLock
Definition: kbbind.h:133
cmd
Definition: command.h:7
QString value() const
Definition: keyaction.h:19
bool isValidMacro() const
isValidMacro checks whether a keyAction contains a valid macro. This is done easily: If the macro act...
Definition: keyaction.h:55
Definition: keymap.h:49
QString driverName() const
Definition: keyaction.cpp:230
static QHash< QString, QString > _globalRemap
Definition: kbbind.h:119
QHash< QString, KeyAction * > _bind
Definition: kbbind.h:131
quint64 lastGlobalRemapTime
Definition: kbbind.h:121
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:127
static quint64 globalRemapTime
Definition: kbbind.h:120
QString macroContent() const
macroContent returns the macro key definition only (the second part of the macro action).
Definition: keyaction.h:86
void updated()
Definition: moc_kbbind.cpp:167
bool _needsUpdate
Definition: kbbind.h:134
KeyAction * bindAction(const QString &key)
Definition: kbbind.h:117

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbBind::updated ( )
signal

Definition at line 167 of file moc_kbbind.cpp.

Referenced by update().

168 {
169  QMetaObject::activate(this, &staticMetaObject, 2, Q_NULLPTR);
170 }

+ Here is the caller graph for this function:

bool KbBind::winLock ( )
inline

Definition at line 78 of file kbbind.h.

References _winLock.

Referenced by KeyAction::keyEvent().

78 { return _winLock; }
bool _winLock
Definition: kbbind.h:133

+ Here is the caller graph for this function:

void KbBind::winLock ( bool  newWinLock)
inline

Definition at line 79 of file kbbind.h.

References _needsUpdate, and _winLock.

79 { _winLock = newWinLock; _needsUpdate = true; }
bool _winLock
Definition: kbbind.h:133
bool _needsUpdate
Definition: kbbind.h:134

Friends And Related Function Documentation

friend class KeyAction
friend

Definition at line 136 of file kbbind.h.

Referenced by bindAction(), friendlyActionName(), KbBind(), load(), noAction(), and setAction().

Field Documentation

QHash<QString, KeyAction*> KbBind::_bind
private

Definition at line 131 of file kbbind.h.

Referenced by bindAction(), KbBind(), load(), noAction(), resetAction(), save(), setAction(), and update().

Kb* KbBind::_devParent
private

Definition at line 113 of file kbbind.h.

Referenced by devParent().

QHash< QString, QString > KbBind::_globalRemap
staticprivate

Definition at line 119 of file kbbind.h.

Referenced by globalRemap(), loadGlobalRemap(), saveGlobalRemap(), setGlobalRemap(), and update().

KeyMap KbBind::_map
private
bool KbBind::_needsSave
private

Definition at line 135 of file kbbind.h.

Referenced by load(), map(), needsSave(), resetAction(), and save().

bool KbBind::_needsUpdate
private

Definition at line 134 of file kbbind.h.

Referenced by map(), resetAction(), setNeedsUpdate(), update(), and winLock().

bool KbBind::_winLock
private

Definition at line 133 of file kbbind.h.

Referenced by load(), save(), update(), and winLock().

quint64 KbBind::globalRemapTime = 0
staticprivate

Definition at line 120 of file kbbind.h.

Referenced by loadGlobalRemap(), setGlobalRemap(), and update().

QFile* KbBind::lastCmd
private

Definition at line 127 of file kbbind.h.

Referenced by handleNotificationChannel(), and update().

quint64 KbBind::lastGlobalRemapTime
private

Definition at line 121 of file kbbind.h.

Referenced by update().


The documentation for this class was generated from the following files: