23 :
QObject(parent), _value(action), preProgram(0), relProgram(0), sniperValue(0)
28 :
QObject(parent), _value(
""), preProgram(0), relProgram(0), sniperValue(0)
46 if(key.length() >= 2 && key[0] ==
'g'
47 && ((key.length() == 2 && key[1] >=
'0' && key[1] <=
'9')
48 || (key.length() == 3 && key[1] ==
'1' && key[2] >=
'0' && key[2] <=
'8')))
51 if(key.startsWith(
"thumb"))
82 QStringList parts =
_value.split(
":");
83 QString prefix = parts[0];
84 if(parts.length() < 2){
91 int suffix = parts[1].toInt();
92 if(prefix ==
"$mode"){
96 return "Switch to previous mode";
99 return "Switch to next mode";
101 return tr(
"Switch to mode %1").arg(suffix + 1);
103 }
else if(prefix ==
"$dpi"){
105 int level = parts[1].split(
"+")[0].toInt();
116 return tr(
"DPI: %1, %2").arg(xy.x()).arg(xy.y());
119 return tr(
"DPI stage %1").arg(level);
121 }
else if(prefix ==
"$light"){
125 return "Brightness up";
128 return "Brightness down";
130 }
else if(prefix ==
"$lock"){
133 return "Toggle Windows lock";
135 return "Windows lock on";
137 return "Windows lock off";
139 }
else if(prefix ==
"$anim"){
140 return "Start animation";
141 }
else if(prefix ==
"$program"){
142 return "Launch program";
143 }
else if(prefix ==
"$macro"){
144 return "Send G-key macro";
150 return QString(
"$mode:%1").arg(mode);
154 QString action = tr(
"$dpi:%1").arg(level);
156 action += tr(
"+%1+%2").arg(customX).arg(customY);
161 return QString(
"$light:%1").arg(type);
165 return QString(
"$lock:%1").arg(type);
170 return "$program:" + QString::fromUtf8(QUrl::toPercentEncoding(onPress.trimmed())) +
"+" + QString::fromUtf8(QUrl::toPercentEncoding(onRelease.trimmed())) + QString(
"+%1").arg(stop);
177 return "$anim:" + guid.toString() + QString(
"+%1").arg(flags);
181 QStringList list =
_value.split(
":");
182 if(list.length() < 2){
186 parameter = list[1].toInt();
187 return list[0].replace(
"$",
"");
193 QString param =
_value.mid(9);
194 QStringList programs = param.split(
"+");
195 if(programs.length() != 3)
197 onPress = QUrl::fromPercentEncoding(programs[0].toUtf8());
198 onRelease = QUrl::fromPercentEncoding(programs[1].toUtf8());
199 return programs[2].toInt();
205 QString param =
_value.mid(5);
206 QStringList lxy = param.split(
"+");
207 int level = lxy[0].toInt();
209 if(lxy.length() != 3)
211 custom = QPoint(lxy[1].toInt(), lxy[2].toInt());
219 QString param =
_value.mid(6);
220 QStringList split = param.split(
"+");
221 if(split.length() < 2)
224 int flags = split[1].toInt();
240 QStringList parts =
_value.split(
":");
241 if(parts.length() < 2)
243 QString prefix = parts[0];
244 int suffix = parts[1].toInt();
245 if(prefix ==
"$mode"){
252 int modeCount = currentProfile->
modeCount();
257 mode = modeCount - 1;
261 if(mode >= modeCount)
275 if(mode < 0 || mode >= modeCount)
278 }
else if(prefix ==
"$dpi"){
280 int level = parts[1].split(
"+")[0].toInt();
303 if(xy.x() <= 0 || xy.y() <= 0)
320 }
else if(prefix ==
"$light"){
347 }
else if(prefix ==
"$lock"){
362 }
else if(prefix ==
"$anim"){
364 bool onlyOnce =
false, stopOnRelease =
false;
365 QUuid
id =
animInfo(onlyOnce, stopOnRelease);
372 anim->
trigger(QDateTime::currentMSecsSinceEpoch(),
true);
373 }
else if(stopOnRelease){
377 }
else if(prefix ==
"$program"){
379 QString onPress, onRelease;
382 QProcess* process = 0;
399 QString& program = down ? onPress : onRelease;
400 if(program.isEmpty())
405 if(process->state() == QProcess::NotRunning)
418 QProcess::startDetached(
"sh", QStringList() <<
"-c" << program);
420 process =
new QProcess(
this);
421 process->start(
"sh", QStringList() <<
"-c" << program);
427 }
else if (prefix ==
"$macro") {
438 qDebug() <<
"isMacro returns" << (
isMacro() ?
"true" :
"false");
439 qDebug() <<
"isValidMacro returns" << (
isValidMacro() ?
"true" :
"false");
440 QStringList ret =
_value.split(
":");
441 qDebug() <<
"Macro definition conains" << ret.count() <<
"elements";
442 qDebug() <<
"Macro definition is" <<
_value;
448 char* display_name = XDisplayName(NULL);
451 Display* display = XOpenDisplay(display_name);
454 char* display_string = DisplayString(display);
455 if(!display_string || strlen(display_string) == 0){
456 XCloseDisplay(display);
459 size_t envstr_size = strlen(display_string) + 4;
460 char* envstr =
new char[envstr_size];
461 strncpy(envstr, display_string, envstr_size);
462 envstr[envstr_size - 1] = 0;
464 Window root_window = XRootWindow(display, DefaultScreen(display));
465 Window root_window_ret, child_window_ret, window;
466 XWindowAttributes attr;
467 int root_x, root_y, win_x, win_y;
468 unsigned int mask_ret;
471 XQueryPointer(display, root_window, &root_window_ret, &child_window_ret, &root_x, &root_y, &win_x, &win_y, &mask_ret);
472 if(child_window_ret == (Window)NULL)
473 window = root_window_ret;
475 window = child_window_ret;
476 XGetWindowAttributes(display, window, &attr);
478 char* ptr = strchr(envstr,
':');
480 ptr = strchr(ptr,
'.');
484 snprintf(buf,
sizeof(buf),
".%i", XScreenNumberOfScreen(attr.screen));
485 strncat(envstr, buf, envstr_size - 1 - strlen(envstr));
488 setenv(
"DISPLAY", envstr, 1);
492 XCloseDisplay(display);
505 return QString (
"$macro:%1").arg(macroDef);
KbMode * currentMode() const
const ModeList & modes() const
void setCurrentMode(KbProfile *profile, KbMode *mode, bool spontaneous=true)
static QString animAction(const QUuid &guid, bool onlyOnce, bool stopOnRelease)
static QString macroAction(QString macroDef)
well documented in cpp file
static QString friendlyName(const QString &key, Layout layout=US)
static const int DPI_CUSTOM
static const int PROGRAM_PR_MULTI
static const int ANIM_ONCE
static const int PROGRAM_RE_MULTI
static QString dpiAction(int level, int customX=0, int customY=0)
QString specialInfo(int ¶meter) const
bool isValidMacro() const
isValidMacro checks whether a keyAction contains a valid macro. This is done easily: If the macro act...
void trigger(quint64 timestamp, bool ignoreParameter=false)
KbProfile * currentProfile()
static const int ANIM_KRSTOP
static const int MODE_PREV
static QString programAction(const QString &onPress, const QString &onRelease, int stop)
static const int PROGRAM_PR_KPSTOP
QUuid animInfo(bool &onlyOnce, bool &stopOnRelease) const
KeyAction(const QString &action, QObject *parent=0)
void popDpi(quint64 pushIdx)
static const int DPI_SNIPER
quint64 pushDpi(const QPoint &newDpi)
static const int PROGRAM_RE_KPSTOP
static QString lockAction(int type=LOCK_TOGGLE)
static const int MODE_PREV_WRAP
QPoint dpi(int index) const
static const int LOCK_TOGGLE
static const int DPI_COUNT
static QString modeAction(int mode)
static const int LIGHT_DOWN
static const int LOCK_OFF
int dpiInfo(QPoint &custom) const
static const int PROGRAM_PR_KRSTOP
static QString lightAction(int type=LIGHT_UP_WRAP)
QString driverName() const
static const int MODE_NEXT_WRAP
void macroDisplay()
Debug output for invalid macro Definitions.
int programInfo(QString &onPress, QString &onRelease) const
static const int MODE_NEXT
QString friendlyName(const KeyMap &map) const
static const int LIGHT_DOWN_WRAP
static const int DPI_DOWN
int indexOf(KbMode *mode) const
static const int LIGHT_UP_WRAP
KbAnim * findAnim(const QUuid &guid) const
void keyEvent(KbBind *bind, bool down)
static const int LIGHT_UP
static QString defaultAction(const QString &key)